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