mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-06 04:15:59 -04:00
Initial Point constexpr support: constructors and comparison operators
This commit is contained in:
parent
6b80bc2c3c
commit
d11345b6df
@ -25,29 +25,6 @@
|
|||||||
|
|
||||||
namespace SDL2pp {
|
namespace SDL2pp {
|
||||||
|
|
||||||
Point::Point() {
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point::Point(const SDL_Point& point) {
|
|
||||||
x = point.x;
|
|
||||||
y = point.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
Point::Point(int nx, int ny) {
|
|
||||||
x = nx;
|
|
||||||
y = ny;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Point::operator==(const Point& other) const {
|
|
||||||
return x == other.x && y == other.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Point::operator!=(const Point& other) const {
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Point::GetX() const {
|
int Point::GetX() const {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,8 @@ public:
|
|||||||
/// Creates a Point(0, 0)
|
/// Creates a Point(0, 0)
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Point();
|
constexpr Point() : SDL_Point{0, 0} {
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct a point from existing SDL_Point
|
/// \brief Construct a point from existing SDL_Point
|
||||||
@ -61,16 +62,18 @@ public:
|
|||||||
/// \param[in] point Existing SDL_Point
|
/// \param[in] point Existing SDL_Point
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Point(const SDL_Point& point);
|
constexpr Point(const SDL_Point& point) : SDL_Point{point.x, point.y} {
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Construct the point from given coordinates
|
/// \brief Construct the point from given coordinates
|
||||||
///
|
///
|
||||||
/// \param[in] nx X coordinate
|
/// \param[in] x X coordinate
|
||||||
/// \param[in] ny Y coordinate
|
/// \param[in] y Y coordinate
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Point(int nx, int ny);
|
constexpr Point(int x, int y) : SDL_Point{x, y} {
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Copy constructor
|
/// \brief Copy constructor
|
||||||
@ -108,7 +111,9 @@ public:
|
|||||||
/// \returns True if two points are identical
|
/// \returns True if two points are identical
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator==(const Point& other) const;
|
constexpr bool operator==(const Point& other) const {
|
||||||
|
return x == other.x && y == other.y;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Inequality operator
|
/// \brief Inequality operator
|
||||||
@ -118,7 +123,9 @@ public:
|
|||||||
/// \returns True if two points are not identical
|
/// \returns True if two points are not identical
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool operator!=(const Point& other) const;
|
constexpr bool operator!=(const Point& other) const {
|
||||||
|
return x != other.x || y != other.y;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Get X coordinate of the point
|
/// \brief Get X coordinate of the point
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# simple command-line tests
|
# simple command-line tests
|
||||||
SET(CLI_TESTS
|
SET(CLI_TESTS
|
||||||
test_pointrect
|
test_pointrect
|
||||||
|
test_pointrect_constexpr
|
||||||
test_rwops
|
test_rwops
|
||||||
test_optional
|
test_optional
|
||||||
test_error
|
test_error
|
||||||
|
24
tests/test_pointrect_constexpr.cc
Normal file
24
tests/test_pointrect_constexpr.cc
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <SDL2pp/Point.hh>
|
||||||
|
#include <SDL2pp/Rect.hh>
|
||||||
|
|
||||||
|
#include "testing.h"
|
||||||
|
|
||||||
|
using namespace SDL2pp;
|
||||||
|
|
||||||
|
BEGIN_TEST()
|
||||||
|
// note that this is merely a compilation test; EXPECT_s are mainly
|
||||||
|
// used to silence `unused variable' warnings
|
||||||
|
{
|
||||||
|
constexpr SDL_Point sp{1, 2};
|
||||||
|
constexpr Point p1;
|
||||||
|
constexpr Point p2(sp);
|
||||||
|
constexpr Point p3(1, 2);
|
||||||
|
constexpr Point p4(p2);
|
||||||
|
|
||||||
|
constexpr bool b1 = p2 == p4;
|
||||||
|
constexpr bool b2 = p1 != p2;
|
||||||
|
|
||||||
|
EXPECT_TRUE(b1);
|
||||||
|
EXPECT_TRUE(b2);
|
||||||
|
}
|
||||||
|
END_TEST()
|
Loading…
x
Reference in New Issue
Block a user