Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arithemic operators added for ImVec2 #5966

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,38 @@ struct ImVec2
constexpr ImVec2(float _x, float _y) : x(_x), y(_y) { }
float operator[] (size_t idx) const { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine.
float& operator[] (size_t idx) { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine.
ImVec2 operator+(ImVec2 v)
{
return ImVec2(this->x + v.x, this->y + v.y);
}
ImVec2 operator-(ImVec2 v)
{
return ImVec2(this->x - v.x, this->y - v.y);
}
ImVec2 operator*(ImVec2 v)
{
return ImVec2(this->x * v.x, this->y * v.y);
}
ImVec2 operator/(ImVec2 v)
{
return ImVec2(this->x / v.x, this->y / v.y);
}
ImVec2 operator+(float c)
{
return ImVec2(this->x + c, this->y + c);
}
ImVec2 operator-(float c)
{
return ImVec2(this->x - c, this->y - c);
}
ImVec2 operator*(float c)
{
return ImVec2(this->x * c, this->y * c);
}
ImVec2 operator/(float c)
{
return ImVec2(this->x / c, this->y / c);
}
#ifdef IM_VEC2_CLASS_EXTRA
IM_VEC2_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec2.
#endif
Expand Down