64 inline explicit Point(
float _x,
float _y)
78 return reinterpret_cast<float*
>(
this);
82 inline const float*
Array()
const 84 return reinterpret_cast<const float*
>(
this);
90 return sqrtf(x*x + y*y);
110 return Point(left.
x + right.
x, left.
y + right.
y);
124 return Point(left.
x - right.
x, left.
y - right.
y);
138 return Point(left * right.
x, left * right.
y);
144 return Point(left.
x * right, left.
y * right);
158 return Point(left.
x / right, left.
y / right);
167 s <<
"[" << x <<
", " << y <<
"]";
192 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:37
Point(float _x, float _y)
Constructs a point from given coords: (x,y)
Definition: point.h:64
float x
X coord.
Definition: point.h:53
Point operator-() const
Returns the inverted point.
Definition: point.h:94
const Point & operator-=(const Point &right)
Subtracts the given point.
Definition: point.h:114
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:190
friend const Point operator*(const float &left, const Point &right)
Multiplies point by scalar.
Definition: point.h:136
const float * Array() const
Returns the struct cast to const float* array; use with care!
Definition: point.h:82
void LoadZero()
Sets the zero point: (0,0)
Definition: point.h:70
float y
Y coord.
Definition: point.h:55
const Point & operator/=(const float &right)
Divides by given scalar.
Definition: point.h:148
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:41
float * Array()
Returns the struct cast to float* array; use with care!
Definition: point.h:76
Namespace for (new) math code.
Definition: device.h:39
Point()
Constructs a zero point: (0,0)
Definition: point.h:58
void Swap(int &a, int &b)
Swaps two integers.
Definition: func.h:114
float Length()
Returns the distance from (0,0) to the point (x,y)
Definition: point.h:88
2D point
Definition: point.h:50
const Point & operator*=(const float &right)
Multiplies by given scalar.
Definition: point.h:128
Constants used in math functions.
friend const Point operator*(const Point &left, const float &right)
Multiplies point by scalar.
Definition: point.h:142
bool PointsEqual(const Point &a, const Point &b, float tolerance=TOLERANCE)
Checks if two vectors are equal within given tolerance.
Definition: point.h:174
friend const Point operator/(const Point &left, const float &right)
Divides point by scalar.
Definition: point.h:156
friend const Point operator+(const Point &left, const Point &right)
Adds two points.
Definition: point.h:108
const Point & operator+=(const Point &right)
Adds the given point.
Definition: point.h:100
std::string ToString() const
Returns a string "[x, y]".
Definition: point.h:163
friend const Point operator-(const Point &left, const Point &right)
Subtracts two points.
Definition: point.h:122