22#ifndef SDL2PP_POINT_HH
23#define SDL2PP_POINT_HH
30#include <SDL2pp/Export.hh>
51class SDL2PP_EXPORT
Point :
public SDL_Point {
59 constexpr Point() : SDL_Point{0, 0} {
68 constexpr Point(
const SDL_Point& point) : SDL_Point{point.x, point.y} {
78 constexpr Point(
int x,
int y) : SDL_Point{x, y} {
115 constexpr
int GetX()
const {
162 return Point(-x, -y);
174 return Point(x + other.x, y + other.y);
186 return Point(x - other.x, y - other.y);
199 return Point(x / value, y / value);
212 return Point(x / other.x, y / other.y);
226 return Point(x % value, y % value);
240 return Point(x % other.x, y % other.y);
254 return Point(x * value, y * value);
268 return Point(x * other.x, y * other.y);
393 Point GetClamped(
const Rect& rect)
const;
414 Point GetWrapped(
const Rect& rect)
const;
439 return a.x == b.x && a.y == b.y;
475SDL2PP_EXPORT std::ostream& operator<<(std::ostream& stream,
const SDL2pp::Point& point);
484struct hash<SDL2pp::Point> {
494 size_t seed = std::hash<int>()(p.x);
495 seed ^= std::hash<int>()(p.y) + 0x9e3779b9 + (seed<<6) + (seed>>2);
2D point
Definition: Point.hh:51
constexpr Point operator+(const Point &other) const
Get point's memberwise addition with another point.
Definition: Point.hh:173
constexpr Point operator/(const Point &other) const
Get point's memberwise division by another point.
Definition: Point.hh:211
constexpr Point operator-(const Point &other) const
Get point's memberwise subtraction with another point.
Definition: Point.hh:185
constexpr Point()
Default constructor.
Definition: Point.hh:59
Point & operator-=(const Point &other)
Memberwise subtract another point.
Definition: Point.hh:293
Point(const Point &) noexcept=default
Copy constructor.
constexpr Point operator%(const Point &other) const
Get point's memberwise remainder from division by another point.
Definition: Point.hh:239
constexpr Point operator*(int value) const
Get point's memberwise multiplication by an integer.
Definition: Point.hh:253
constexpr Point(int x, int y)
Construct the point from given coordinates.
Definition: Point.hh:78
Point & operator%=(int value)
Memberwise remainder from division by an integer.
Definition: Point.hh:335
Point & SetX(int nx)
Set X coordinate of the point.
Definition: Point.hh:127
Point & operator+=(const Point &other)
Memberwise add another point.
Definition: Point.hh:279
constexpr int GetY() const
Get Y coordinate of the point.
Definition: Point.hh:138
Point & SetY(int ny)
Set Y coordinate of the point.
Definition: Point.hh:150
Point & operator%=(const Point &other)
Memberwise remainder from division by another point.
Definition: Point.hh:350
constexpr Point operator%(int value) const
Get point's memberwise remainder from division by an integer.
Definition: Point.hh:225
constexpr Point(const SDL_Point &point)
Construct a point from existing SDL_Point.
Definition: Point.hh:68
Point & operator*=(int value)
Memberwise multiply by an integer.
Definition: Point.hh:364
Point & operator*=(const Point &other)
Memberwise multiply by another point.
Definition: Point.hh:378
constexpr Point operator*(const Point &other) const
Get point's memberwise multiplication by anoter point.
Definition: Point.hh:267
constexpr Point operator-() const
Get point's memberwise negation.
Definition: Point.hh:161
Point & operator/=(int value)
Memberwise divide by an integer.
Definition: Point.hh:307
Point & operator/=(const Point &other)
Definition: Point.hh:321
constexpr Point operator/(int value) const
Get point's memberwise division by an integer.
Definition: Point.hh:198
Point(Point &&) noexcept=default
Move constructor.
2D rectangle
Definition: Rect.hh:50
size_t operator()(const SDL2pp::Point &p) const
Hash function for SDL2pp::Point.
Definition: Point.hh:493