| 19 | /// @brief An example point class |
| 20 | template <class T> |
| 21 | struct point { |
| 22 | /// The `x` coordinate of the point. |
| 23 | T x{0}; |
| 24 | /// The `y` coordinate of the point. |
| 25 | T y{0}; |
| 26 | |
| 27 | /// A static routine that returns the origin point. |
| 28 | /// @return The point `(0, 0)` |
| 29 | static constexpr auto origin() { return point(); } |
| 30 | |
| 31 | |
| 32 | /// Default constructor of default definition. |
| 33 | constexpr point() noexcept = default; |
| 34 | |
| 35 | /// Value-based constructor that takes `x` and `y` values and sinks them into place. |
| 36 | /// @param _x The `x` coordinate to sink. |
| 37 | /// @param _y The `y` coordinate to sink. |
| 38 | constexpr point(T _x, T _y) noexcept : x(std::move(_x)), y(std::move(_y)) {} |
| 39 | |
| 40 | /// Equality operator. |
| 41 | /// @return `true` iff the two points' `x` and `y` coordinates are memberwise equal. |
| 42 | friend inline constexpr bool operator==(const point& a, const point& b) { |
| 43 | return (a.x == b.x) && (a.y == b.y); |
| 44 | } |
| 45 | |
| 46 | /// Inequality operator. |
| 47 | /// @return `true` iff the two points' `x` or `y` coordinates are memberwise inequal. |
| 48 | friend inline constexpr bool operator!=(const point& a, const point& b) { return !(a == b); } |
| 49 | |
| 50 | /// Subtraction operator. |
| 51 | /// @param a The point to be subtracted from. |
| 52 | /// @param b The point to subtract. |
| 53 | /// @return A new point whose axis values are subtractions of the two inputs' axis values. |
| 54 | friend inline constexpr point operator-(const point& a, const point& b) { |
| 55 | return point(a.x - b.x, a.y - b.y); |
| 56 | } |
| 57 | |
| 58 | /// Subtraction-assignment operator. |
| 59 | /// @param a The point to subtract from this point |
| 60 | /// @return A reference to `this`. |
| 61 | constexpr point& operator-=(const point& a) { |
| 62 | x -= a.x; |
| 63 | y -= a.y; |
| 64 | return *this; |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | //------------------------------------------------------------------------------------------------------------------------------------------ |