2D integer point for UI and input coordinates.
More...
|
| constexpr | Point () noexcept=default |
| | Default constructor.
|
| constexpr | Point (const int32_t &x, const int32_t &y) noexcept |
| | Constructs a point with the given coordinates.
|
| constexpr | Point (const int32_t *values) noexcept |
| | Constructs a point from an array.
|
| constexpr int32_t * | c_arr () noexcept |
| | Pointer to the coordinate array (x, then y).
|
| constexpr const int32_t * | c_arr () const noexcept |
| | Read-only pointer to the coordinate array (x, then y).
|
| constexpr Point & | operator+= (const Point &point) noexcept |
| | Adds point to this point.
|
| constexpr Point & | operator-= (const Point &point) noexcept |
| | Subtracts point from this point.
|
| template<PointScalar T> |
| constexpr Point & | operator*= (const T &scalar) noexcept |
| | Multiplies both coordinates by scalar and truncates to integer.
|
| template<PointScalar T> |
| constexpr Point & | operator/= (const T &scalar) noexcept |
| | Divides both coordinates by scalar and truncates to integer.
|
| constexpr void | setZero () noexcept |
| | Sets x and y to zero.
|
| constexpr bool | isZero () const noexcept |
| | Returns whether both coordinates are zero.
|
| constexpr bool | isEqual (const Point &point, int32_t epsilon=0) const noexcept |
| | Equality within epsilon.
|
|
| int32_t | x |
| | X coordinate.
|
| int32_t | y |
| | Y coordinate.
|
2D integer point for UI and input coordinates.
Value type with x and y for pixel positions, mouse coordinates, and layout. Prefer toy::math::Vector2 for floating-point or world coordinates.
Key Features
- Constexpr support: Most operations are constexpr.
- Exception safety: All operations are noexcept.
- UI-oriented: Integer coordinates for pixel-perfect layout.
- Type safety: Distinct type; coordinates are named
x and y.
Usage Example
buttonPos +=
Point(5, 5);
2D integer point for UI and input coordinates.
Definition point.hpp:95
constexpr Point() noexcept=default
Default constructor.
Umbrella header for the math module.
Performance Characteristics
- Construction, assignment, arithmetic, comparison: O(1).
- Memory: 8 bytes; stack-friendly.
Safety Guarantees
- Contracts: Division by zero and null values are asserted in debug.
- Exception safety: All operations are noexcept.
- Note
- For approximate equality use isEqual() with a tolerance.
- See also
- toy::math::Vector2
◆ Point() [1/3]
| toy::math::Point::Point |
( |
| ) |
|
|
constexprdefaultnoexcept |
◆ Point() [2/3]
| toy::math::Point::Point |
( |
const int32_t & | x, |
|
|
const int32_t & | y ) |
|
constexprnoexcept |
Constructs a point with the given coordinates.
- Parameters
-
| x | X coordinate. |
| y | Y coordinate. |
◆ Point() [3/3]
| toy::math::Point::Point |
( |
const int32_t * | values | ) |
|
|
explicitconstexprnoexcept |
Constructs a point from an array.
- Parameters
-
| values | Pointer to at least two elements; values[0] is x, values[1] is y. |
- Precondition
- values != nullptr; array has at least two elements.
- Postcondition
- x == values[0], y == values[1].
◆ c_arr() [1/2]
| const int32_t * toy::math::Point::c_arr |
( |
| ) |
const |
|
nodiscardconstexprnoexcept |
Read-only pointer to the coordinate array (x, then y).
- Returns
- Pointer to x; y follows contiguously.
◆ c_arr() [2/2]
| int32_t * toy::math::Point::c_arr |
( |
| ) |
|
|
nodiscardconstexprnoexcept |
Pointer to the coordinate array (x, then y).
- Returns
- Pointer to x; y follows contiguously.
◆ isEqual()
| bool toy::math::Point::isEqual |
( |
const Point & | point, |
|
|
int32_t | epsilon = 0 ) const |
|
nodiscardconstexprnoexcept |
Equality within epsilon.
- Parameters
-
| point | Other point. |
| epsilon | Maximum allowed difference per coordinate (default: 0). |
- Returns
true if |x − point.x| ≤ epsilon and |y − point.y| ≤ epsilon.
- Precondition
- epsilon ≥
0.
◆ isZero()
| bool toy::math::Point::isZero |
( |
| ) |
const |
|
nodiscardconstexprnoexcept |
Returns whether both coordinates are zero.
- Returns
true if x and y are zero, false otherwise.
◆ operator*=()
template<PointScalar T>
| Point & toy::math::Point::operator*= |
( |
const T & | scalar | ) |
|
|
constexprnoexcept |
Multiplies both coordinates by scalar and truncates to integer.
- Template Parameters
-
- Parameters
-
- Returns
- Reference to
*this.
◆ operator+=()
| Point & toy::math::Point::operator+= |
( |
const Point & | point | ) |
|
|
constexprnoexcept |
Adds point to this point.
- Parameters
-
- Returns
- Reference to
*this.
- Postcondition
- Coordinates are the sum of the previous values and point.
◆ operator-=()
| Point & toy::math::Point::operator-= |
( |
const Point & | point | ) |
|
|
constexprnoexcept |
Subtracts point from this point.
- Parameters
-
- Returns
- Reference to
*this.
- Postcondition
- Coordinates are the difference of the previous values and point.
◆ operator/=()
template<PointScalar T>
| Point & toy::math::Point::operator/= |
( |
const T & | scalar | ) |
|
|
constexprnoexcept |
Divides both coordinates by scalar and truncates to integer.
- Template Parameters
-
- Parameters
-
- Returns
- Reference to
*this.
- Precondition
- scalar !=
0.
◆ setZero()
| void toy::math::Point::setZero |
( |
| ) |
|
|
constexprnoexcept |
Sets x and y to zero.
- Postcondition
- Point is at the origin.
| int32_t toy::math::Point::x |
| int32_t toy::math::Point::y |
The documentation for this class was generated from the following files: