From 99987ee42389fec021c2241bd52fd8289c07106c Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 1 Apr 2022 20:54:45 -0500 Subject: [PATCH] [nostalgia/geo] Add Bounds::setPt2 --- src/nostalgia/geo/bounds.hpp | 52 +++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/nostalgia/geo/bounds.hpp b/src/nostalgia/geo/bounds.hpp index 340360ee..8eccf82f 100644 --- a/src/nostalgia/geo/bounds.hpp +++ b/src/nostalgia/geo/bounds.hpp @@ -6,6 +6,7 @@ #include #include +#include #include "point.hpp" @@ -48,6 +49,11 @@ class Bounds { [[nodiscard]] constexpr Point pt2() const noexcept; + constexpr void setPt2(const Point &pt) noexcept; + + private: + constexpr void set(const Point &pt1, const Point &pt2) noexcept; + }; constexpr Bounds::Bounds(int x, int y, int w, int h) noexcept { @@ -58,25 +64,7 @@ constexpr Bounds::Bounds(int x, int y, int w, int h) noexcept { } constexpr Bounds::Bounds(const Point &pt1, const Point &pt2) noexcept { - int x1 = 0, x2 = 0, y1 = 0, y2 = 0; - if (pt1.x <= pt2.x) { - x1 = pt1.x; - x2 = pt2.x; - } else { - x1 = pt2.x; - x2 = pt1.x; - } - if (pt1.y <= pt2.y) { - y1 = pt1.y; - y2 = pt2.y; - } else { - y1 = pt2.y; - y2 = pt1.y; - } - this->x = x1; - this->y = y1; - this->width = x2 - x1; - this->height = y2 - y1; + set(pt1, pt2); } constexpr bool Bounds::intersects(const Bounds &o) const noexcept { @@ -107,6 +95,32 @@ constexpr Point Bounds::pt2() const noexcept { return {x2(), y2()}; } +constexpr void Bounds::setPt2(const Point &pt) noexcept { + set(pt1(), pt); +} + +constexpr void Bounds::set(const Point &pt1, const Point &pt2) noexcept { + int x1 = 0, x2 = 0, y1 = 0, y2 = 0; + if (pt1.x <= pt2.x) { + x1 = pt1.x; + x2 = pt2.x; + } else { + x1 = pt2.x; + x2 = pt1.x; + } + if (pt1.y <= pt2.y) { + y1 = pt1.y; + y2 = pt2.y; + } else { + y1 = pt2.y; + y2 = pt1.y; + } + this->x = x1; + this->y = y1; + this->width = x2 - x1; + this->height = y2 - y1; +} + oxModelBegin(Bounds) oxModelField(x) oxModelField(y)