diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2018-08-11 00:32:45 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2018-08-11 00:33:01 -0500 |
commit | 14fe7230f4db402fba1efb74a1a17ce8a4dd20bb (patch) | |
tree | 116fdbdc9b57409b975a10f622fc0f2bc70f27f4 /core/math/vector2.h | |
parent | 2eb8a9749ea005325e6918288a1b6f1be311eebf (diff) | |
download | redot-engine-14fe7230f4db402fba1efb74a1a17ce8a4dd20bb.tar.gz |
[Core] Move Vector2i and Rect2i out of math_2d.h
Diffstat (limited to 'core/math/vector2.h')
-rw-r--r-- | core/math/vector2.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/core/math/vector2.h b/core/math/vector2.h index 809cedf9c9..7c8882f6e2 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -34,6 +34,8 @@ #include "math_funcs.h" #include "ustring.h" +struct Vector2i; + struct Vector2 { union { @@ -247,4 +249,68 @@ Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real typedef Vector2 Size2; typedef Vector2 Point2; +/* INTEGER STUFF */ + +struct Vector2i { + + union { + int x; + int width; + }; + union { + int y; + int height; + }; + + _FORCE_INLINE_ int &operator[](int p_idx) { + return p_idx ? y : x; + } + _FORCE_INLINE_ const int &operator[](int p_idx) const { + return p_idx ? y : x; + } + + Vector2i operator+(const Vector2i &p_v) const; + void operator+=(const Vector2i &p_v); + Vector2i operator-(const Vector2i &p_v) const; + void operator-=(const Vector2i &p_v); + Vector2i operator*(const Vector2i &p_v1) const; + + Vector2i operator*(const int &rvalue) const; + void operator*=(const int &rvalue); + + Vector2i operator/(const Vector2i &p_v1) const; + + Vector2i operator/(const int &rvalue) const; + + void operator/=(const int &rvalue); + + Vector2i operator-() const; + bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); } + bool operator>(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y > p_vec2.y) : (x > p_vec2.x); } + + bool operator==(const Vector2i &p_vec2) const; + bool operator!=(const Vector2i &p_vec2) const; + + real_t get_aspect() const { return width / (real_t)height; } + + operator String() const { return String::num(x) + ", " + String::num(y); } + + operator Vector2() const { return Vector2(x, y); } + inline Vector2i(const Vector2 &p_vec2) { + x = (int)p_vec2.x; + y = (int)p_vec2.y; + } + inline Vector2i(int p_x, int p_y) { + x = p_x; + y = p_y; + } + inline Vector2i() { + x = 0; + y = 0; + } +}; + +typedef Vector2i Size2i; +typedef Vector2i Point2i; + #endif // VECTOR2_H |