60 inline explicit Point(
float _x,
float _y)
74 return reinterpret_cast<float*
>(
this);
78 inline const float*
Array()
const
80 return reinterpret_cast<const float*
>(
this);
86 return sqrtf(
x*
x +
y*
y);
106 return Point(left.
x + right.
x, left.
y + right.
y);
120 return Point(left.
x - right.
x, left.
y - right.
y);
134 return Point(left * right.
x, left * right.
y);
140 return Point(left.
x * right, left.
y * right);
154 return Point(left.
x / right, left.
y / right);
163 s <<
"[" <<
x <<
", " <<
y <<
"]";
188 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:33
Point(float _x, float _y)
Constructs a point from given coords: (x,y)
Definition: point.h:60
float x
X coord.
Definition: point.h:49
Point operator-() const
Returns the inverted point.
Definition: point.h:90
const Point & operator-=(const Point &right)
Subtracts the given vector.
Definition: point.h:110
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:186
friend const Point operator*(const float &left, const Point &right)
Multiplies point by scalar.
Definition: point.h:132
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: point.h:78
void LoadZero()
Sets the zero point: (0,0)
Definition: point.h:66
float y
Y coord.
Definition: point.h:51
const Point & operator/=(const float &right)
Divides by given scalar.
Definition: point.h:144
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:38
float * Array()
Returns the struct cast to float* array; use with care!
Definition: point.h:72
Point()
Constructs a zero point: (0,0)
Definition: point.h:54
void Swap(int &a, int &b)
Swaps two integers.
Definition: func.h:102
float Length()
Returns the distance from (0,0) to the point (x,y)
Definition: point.h:84
2D point
Definition: point.h:46
const Point & operator*=(const float &right)
Multiplies by given scalar.
Definition: point.h:124
Constants used in math functions.
friend const Point operator*(const Point &left, const float &right)
Multiplies point by scalar.
Definition: point.h:138
bool PointsEqual(const Point &a, const Point &b, float tolerance=TOLERANCE)
Checks if two vectors are equal within given tolerance.
Definition: point.h:170
friend const Point operator/(const Point &left, const float &right)
Divides point by scalar.
Definition: point.h:152
friend const Point operator+(const Point &left, const Point &right)
Adds two points.
Definition: point.h:104
const Point & operator+=(const Point &right)
Adds the given point.
Definition: point.h:96
std::string ToString() const
Returns a string "[x, y]".
Definition: point.h:159
friend const Point operator-(const Point &left, const Point &right)
Subtracts two points.
Definition: point.h:118