Sista v3.0.0-alpha.1
Sista is a C++ lightweight OS-agnostic library for terminal animations and videogames
|
Represents 2D coordinates with x and y values. More...
#include <coordinates.hpp>
Public Member Functions | |
Coordinates () | |
Default constructor initializing coordinates to (0,0). | |
Coordinates (unsigned short, unsigned short) | |
Parameterized constructor. | |
std::pair< unsigned short, unsigned short > | toPair () const |
Converts the Coordinates instance to a std::pair. | |
bool | operator== (const Coordinates &) const |
Equality operator. | |
bool | operator!= (const Coordinates &) const |
Inequality operator. | |
bool | operator< (const Coordinates &) const |
Less-than operator for ordering. | |
Coordinates | operator+ (const Coordinates &) const |
Addition operator. | |
Coordinates | operator- (const Coordinates &) const |
Subtraction operator. | |
Coordinates | operator* (const unsigned short) const |
Scalar multiplication operator. | |
Coordinates | operator+= (const Coordinates &) |
Compound addition assignment operator. | |
Coordinates | operator-= (const Coordinates &) |
Compound subtraction assignment operator. | |
Static Public Member Functions | |
static Coordinates | fromPair (const std::pair< unsigned short, unsigned short > &) |
Creates a Coordinates instance from a std::pair. | |
Public Attributes | |
unsigned short | y |
unsigned short | x |
Represents 2D coordinates with x and y values.
This struct encapsulates 2D coordinates using unsigned short integers for both the x (column) and y (row) values. It provides constructors, conversion methods, and overloaded operators for comparison and arithmetic operations.
The coordinates system in Sista is defined such that y
represents the row (vertical position) that increases downwards, and x
represents the column (horizontal position) that increases to the right.
sista::Coordinates::Coordinates | ( | ) |
Default constructor initializing coordinates to (0,0).
x coordinate
sista::Coordinates::Coordinates | ( | unsigned short | y_, |
unsigned short | x_ | ||
) |
Parameterized constructor.
y_ | The y coordinate (row). |
x_ | The x coordinate (column). |
|
static |
Creates a Coordinates instance from a std::pair.
p | A std::pair where first is y and second is x. |
This static method constructs a Coordinates object from a given std::pair. The first element of the pair corresponds to the y coordinate, and the second element corresponds to the x coordinate.
bool sista::Coordinates::operator!= | ( | const Coordinates & | other | ) | const |
Inequality operator.
other | The other Coordinates instance to compare with. |
Coordinates sista::Coordinates::operator* | ( | const unsigned short | multiplier | ) | const |
Scalar multiplication operator.
multiplier | The scalar value to multiply both coordinates by. |
Coordinates sista::Coordinates::operator+ | ( | const Coordinates & | other | ) | const |
Addition operator.
other | The other Coordinates instance to add. |
Coordinates sista::Coordinates::operator+= | ( | const Coordinates & | other | ) |
Compound addition assignment operator.
other | The other Coordinates instance to add. |
Coordinates sista::Coordinates::operator- | ( | const Coordinates & | other | ) | const |
Subtraction operator.
other | The other Coordinates instance to subtract. |
Coordinates sista::Coordinates::operator-= | ( | const Coordinates & | other | ) |
Compound subtraction assignment operator.
other | The other Coordinates instance to subtract. |
bool sista::Coordinates::operator< | ( | const Coordinates & | other | ) | const |
Less-than operator for ordering.
other | The other Coordinates instance to compare with. |
The ordering is first based on the y coordinate (row). If the y coordinates are equal, then the x coordinate (column) is used for comparison.
bool sista::Coordinates::operator== | ( | const Coordinates & | other | ) | const |
Equality operator.
other | The other Coordinates instance to compare with. |
std::pair< unsigned short, unsigned short > sista::Coordinates::toPair | ( | ) | const |
Converts the Coordinates instance to a std::pair.
This method converts the current Coordinates object into a std::pair, with the first element representing the y coordinate and the second element representing the x coordinate.
unsigned short sista::Coordinates::x |
y coordinate
unsigned short sista::Coordinates::y |