[nostalgia/geo] Add Bounds::setPt2
This commit is contained in:
parent
dd12857ba8
commit
99987ee423
@ -6,6 +6,7 @@
|
||||
|
||||
#include <ox/model/def.hpp>
|
||||
#include <ox/std/error.hpp>
|
||||
#include <ox/std/new.hpp>
|
||||
|
||||
#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)
|
||||
|
Loading…
Reference in New Issue
Block a user