Sista v3.0.0-alpha.1
Sista is a C++ lightweight OS-agnostic library for terminal animations and videogames
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
sista::Coordinates Struct Reference

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
 

Detailed Description

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.

See also
fromPair
toPair

Constructor & Destructor Documentation

◆ Coordinates() [1/2]

sista::Coordinates::Coordinates ( )

Default constructor initializing coordinates to (0,0).

x coordinate

◆ Coordinates() [2/2]

sista::Coordinates::Coordinates ( unsigned short  y_,
unsigned short  x_ 
)

Parameterized constructor.

Parameters
y_The y coordinate (row).
x_The x coordinate (column).

Member Function Documentation

◆ fromPair()

Coordinates sista::Coordinates::fromPair ( const std::pair< unsigned short, unsigned short > &  p)
static

Creates a Coordinates instance from a std::pair.

Parameters
pA std::pair where first is y and second is x.
Returns
A Coordinates instance with the specified y and x values.

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.

See also
toPair

◆ operator!=()

bool sista::Coordinates::operator!= ( const Coordinates other) const

Inequality operator.

Parameters
otherThe other Coordinates instance to compare with.
Returns
True if the coordinates are not equal, false otherwise.

◆ operator*()

Coordinates sista::Coordinates::operator* ( const unsigned short  multiplier) const

Scalar multiplication operator.

Parameters
multiplierThe scalar value to multiply both coordinates by.
Returns
A new Coordinates instance with both coordinates multiplied by the scalar.
Note
This operation does not ensure that the resulting coordinates are within any specific bounds.

◆ operator+()

Coordinates sista::Coordinates::operator+ ( const Coordinates other) const

Addition operator.

Parameters
otherThe other Coordinates instance to add.
Returns
A new Coordinates instance representing the sum of the two coordinates.
Note
This operation does not ensure that the resulting coordinates are within any specific bounds.

◆ operator+=()

Coordinates sista::Coordinates::operator+= ( const Coordinates other)

Compound addition assignment operator.

Parameters
otherThe other Coordinates instance to add.
Returns
A reference to the updated Coordinates instance.
Note
This operation modifies the current instance and does not ensure that the resulting coordinates are within any specific bounds.

◆ operator-()

Coordinates sista::Coordinates::operator- ( const Coordinates other) const

Subtraction operator.

Parameters
otherThe other Coordinates instance to subtract.
Returns
A new Coordinates instance representing the difference of the two coordinates.
Warning
This operation does not check for underflow; ensure that the result is valid.

◆ operator-=()

Coordinates sista::Coordinates::operator-= ( const Coordinates other)

Compound subtraction assignment operator.

Parameters
otherThe other Coordinates instance to subtract.
Returns
A reference to the updated Coordinates instance.
Warning
This operation modifies the current instance and does not check for underflow; ensure that the result is valid.

◆ operator<()

bool sista::Coordinates::operator< ( const Coordinates other) const

Less-than operator for ordering.

Parameters
otherThe other Coordinates instance to compare with.
Returns
True if this coordinate is less than the other, false otherwise.

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.

◆ operator==()

bool sista::Coordinates::operator== ( const Coordinates other) const

Equality operator.

Parameters
otherThe other Coordinates instance to compare with.
Returns
True if both coordinates are equal, false otherwise.

◆ toPair()

std::pair< unsigned short, unsigned short > sista::Coordinates::toPair ( ) const

Converts the Coordinates instance to a std::pair.

Returns
A std::pair where first is y and second is x.

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.

See also
fromPair

Member Data Documentation

◆ x

unsigned short sista::Coordinates::x

y coordinate

◆ y

unsigned short sista::Coordinates::y

The documentation for this struct was generated from the following files: