跳到主要内容
版本:3.0 Beta 🧪

类:Point

Point 类表示具有 xy 坐标的二维点。它提供了各种数学运算和变换的实用函数,包括旋转。

该类的源文件位于 os/framework/Point.h


成员

x

  • Type: int16_t
  • 描述:点的 x 坐标。

y

  • Type: int16_t
  • 描述:点的 y 坐标。

构造函数

默认构造函数

Point();

初始化点,将 xy 都设置为 INT16_MIN,表示无效点。


从 X 和 Y 坐标创建

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): If true, reverses the rotation direction. Defaults to false.

Returns:

  • Point: A new point after rotation.

Comments