63 inline explicit Point(
float _x,
float _y)
77 return reinterpret_cast<float*
>(
this);
81 inline const float*
Array()
const
83 return reinterpret_cast<const float*
>(
this);
89 return sqrtf(x*x + y*y);
109 return Point(left.
x + right.
x, left.
y + right.
y);
123 return Point(left.
x - right.
x, left.
y - right.
y);
137 return Point(left * right.
x, left * right.
y);
143 return Point(left.
x * right, left.
y * right);
157 return Point(left.
x / right, left.
y / right);
166 s <<
"[" << x <<
", " << y <<
"]";
191 return sqrtf((a.
x-b.
x)*(a.
x-b.
x) + (a.
y-b.
y)*(a.
y-b.
y));
const float TOLERANCE
Tolerance level – minimum accepted float value.
Definition: const.h:36
Point(float _x, float _y)
Constructs a point from given coords: (x,y)
Definition: point.h:63
float x
X coord.
Definition: point.h:52
Point operator-() const
Returns the inverted point.
Definition: point.h:93
const Point & operator-=(const Point &right)
Subtracts the given vector.
Definition: point.h:113
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:189
friend const Point operator*(const float &left, const Point &right)
Multiplies point by scalar.
Definition: point.h:135
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: point.h:81
void LoadZero()
Sets the zero point: (0,0)
Definition: point.h:69
float y
Y coord.
Definition: point.h:54
const Point & operator/=(const float &right)
Divides by given scalar.
Definition: point.h:147
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:40
float * Array()
Returns the struct cast to float* array; use with care!
Definition: point.h:75
Namespace for (new) math code.
Definition: const.h:32
Point()
Constructs a zero point: (0,0)
Definition: point.h:57
void Swap(int &a, int &b)
Swaps two integers.
Definition: func.h:104
float Length()
Returns the distance from (0,0) to the point (x,y)
Definition: point.h:87
2D point
Definition: point.h:49
const Point & operator*=(const float &right)
Multiplies by given scalar.
Definition: point.h:127
Constants used in math functions.
friend const Point operator*(const Point &left, const float &right)
Multiplies point by scalar.
Definition: point.h:141
bool PointsEqual(const Point &a, const Point &b, float tolerance=TOLERANCE)
Checks if two vectors are equal within given tolerance.
Definition: point.h:173
friend const Point operator/(const Point &left, const float &right)
Divides point by scalar.
Definition: point.h:155
friend const Point operator+(const Point &left, const Point &right)
Adds two points.
Definition: point.h:107
const Point & operator+=(const Point &right)
Adds the given point.
Definition: point.h:99
std::string ToString() const
Returns a string "[x, y]".
Definition: point.h:162
friend const Point operator-(const Point &left, const Point &right)
Subtracts two points.
Definition: point.h:121