4 #include "../utils/unicode.h"
5 #include "../utils/formatter.h"
17 static const Vec2 NEGATIVE_X;
18 static const Vec2 POSITIVE_X;
19 static const Vec2 NEGATIVE_Y;
20 static const Vec2 POSITIVE_Y;
22 static const Vec2 DOWN;
23 static const Vec2 LEFT;
24 static const Vec2 ONE;
25 static const Vec2 RIGHT;
27 static const Vec2 ZERO;
36 Vec2(
float x,
float y):
43 float length()
const {
44 return fast_sqrt(x * x + y * y);
47 float length_squared()
const {
49 return MATH_Sum_of_Squares(x, y, 0.0f, 0.0f);
56 float l = fast_inverse_sqrt(length_squared());
61 Vec2 normalized()
const {
74 Vec2 operator*(
float rhs)
const {
75 Vec2 result(x * rhs, y * rhs);
79 Vec2& operator*=(
float rhs) {
94 Vec2 operator+(
const Vec2& rhs)
const {
95 return Vec2(x + rhs.x, y + rhs.y);
98 Vec2& operator/=(
float rhs) {
99 float l = fast_divide(1.0f, rhs);
104 Vec2 operator/(
float rhs)
const {
105 float l = fast_divide(1.0f, rhs);
106 Vec2 result(x * l, y * l);
110 Vec2 operator-()
const {
114 Vec2 operator-(
const Vec2& rhs)
const {
115 return Vec2(x - rhs.x, y - rhs.y);
118 float dot(
const Vec2& rhs)
const {
120 return MATH_fipr(x, y, 0.0f, 0.0f, rhs.x, rhs.y, 0.0f, 0.0f);
122 return x * rhs.x + y * rhs.y;
126 Vec3 xyz(
float z = 0.0f)
const;
128 Vec4 xyzw(
float z=0.0f,
float w=1.0f)
const;
130 friend std::ostream& operator<<(std::ostream& stream,
const Vec2& vec);
132 bool equals(
const Vec2& rhs)
const {
133 return x == rhs.x && y == rhs.y;
136 friend bool operator==(
const Vec2& lhs,
const Vec2& rhs);
139 bool operator==(
const Vec2& lhs,
const Vec2& rhs);
140 bool operator!=(
const Vec2& lhs,
const Vec2& rhs);
141 Vec2 operator*(
float lhs,
const Vec2& rhs);
143 std::ostream& operator<<(std::ostream& stream,
const Vec2& vec);