Class: Point
The Point class represents a 2D point with x and y coordinates. It provides various utility functions for mathematical operations and transformations, including rotations.
The source file for this class is located in os/framework/Point.h
Membersβ
xβ
- Type:
int16_t - Description: The x-coordinate of the point.
yβ
- Type:
int16_t - Description: The y-coordinate of the point.
Constructorsβ
Default Constructorβ
Point();
Initializes the point with both x and y set to INT16_MIN, indicating an invalid point.
From X and Y Coordinatesβ
Point(int16_t x, int16_t y);
Initializes the point with the specified x and y coordinates.
Parameters:
x(int16_t): The x-coordinate.y(int16_t): The y-coordinate.
From uint32_tβ
Point(uint32_t rawByte);
Constructs a point from a 32-bit integer, where the higher 16 bits represent the x coordinate and the lower 16 bits represent the y coordinate.
Parameters:
rawByte(uint32_t): A packed representation of the point.
Operatorsβ
Additionβ
Point operator+(const Point& cp) const;
Adds the coordinates of two points and returns a new point.
Subtractionβ
Point operator-(const Point& cp) const;
Subtracts the coordinates of one point from another and returns a new point.
Equalityβ
bool operator==(const Point& cp) const;
Checks if two points are equal.
Inequalityβ
bool operator!=(const Point& cp) const;
Checks if two points are not equal.
Less Thanβ
bool operator<(const Point& cp) const;
Compares two points lexicographically, first by x then by y.
bool operator<(const Point& cp) const { return x < cp.x || (x == cp.x && y < cp.y); }
Multiplicationβ
Point operator*(const int val) const;
Multiplies both coordinates by a scalar value and returns a new point.
Divisionβ
Point operator/(const int val) const;
Divides both coordinates by a scalar value and returns a new point.
Conversion to boolβ
operator bool();
Checks if the point is valid (both x and y are not INT16_MIN).
Conversion to uint32_tβ
operator uint32_t();
Converts the point to a packed 32-bit integer representation.
Static Methodsβ
Invalidβ
static Point Invalid();
Returns a point with x and y set to INT16_MIN, representing an invalid state.
Methodsβ
Rotateβ
Point Rotate(EDirection rotation, Point dimension, bool reverse = false);
Rotates the point within a bounded dimension based on the specified direction.
Parameters:
rotation(EDirection): The direction to rotate.dimension(Point): The bounding dimensions.reverse(bool, optional): Iftrue, reverses the rotation direction. Defaults tofalse.
Returns:
Point: A new point after rotation.
Comments