From 9da2309be783fd453da060fd3fe1ccd5fbeba8a9 Mon Sep 17 00:00:00 2001 From: lepelog <25211966+lepelog@users.noreply.github.com> Date: Mon, 6 Dec 2021 12:57:45 +0100 Subject: J2DGrafContext and J2DOrthoGraph --- include/JSystem/JGeometry.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'include/JSystem/JGeometry.h') diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h index 2bb4e5f852..0da0a2718b 100644 --- a/include/JSystem/JGeometry.h +++ b/include/JSystem/JGeometry.h @@ -51,9 +51,9 @@ struct TVec2 { } void setMin(const TVec2& min) { - if (min.x <= x) + if (x >= min.x) x = min.x; - if (min.y <= y) + if (y >= min.y) y = min.y; } @@ -70,7 +70,7 @@ struct TVec2 { } bool isAbove(const TVec2& other) const { - return (other.x <= x) && (other.y <= y) ? true : false; + return (x >= other.x) && (y >= other.y) ? true : false; } T x; @@ -90,14 +90,6 @@ template<> struct TBox > { f32 getWidth() const { return f.x - i.x; } f32 getHeight() const { return f.y - i.y; } - inline void operator= (const TBox >& rhs) { - // ??? - *(u32*)&i.x = *(u32*)&rhs.i.x; - *(u32*)&i.y = *(u32*)&rhs.i.y; - *(u32*)&f.x = *(u32*)&rhs.f.x; - *(u32*)&f.y = *(u32*)&rhs.f.y; - } - bool isValid() const { return f.isAbove(i); } void addPos(const TVec2& pos) { @@ -117,9 +109,19 @@ template<> struct TBox > { template struct TBox2 : TBox > { TBox2() {} + TBox2(const TVec2& i, const TVec2 f) { set(i, f); } TBox2(f32 x0, f32 y0, f32 x1, f32 y1) { set(x0, y0, x1, y1); } - inline const TBox2& operator=(const TBox2& rhs) { *(TBox >*)this = rhs; } + void absolute() { + if (!this->isValid()) { + TBox2 box(*this); + this->i.setMin(box.i); + this->i.setMin(box.f); + this->f.setMax(box.i); + this->f.setMax(box.f); + } + } + void set(const TBox2& other) { set(other.i, other.f); } void set(const TVec2& i, const TVec2 f) { this->i.set(i), this->f.set(f); } void set(f32 x0, f32 y0, f32 x1, f32 y1) { i.set(x0, y0); f.set(x1, y1); } @@ -129,4 +131,4 @@ struct TBox2 : TBox > { } // namespace JGeometry -#endif \ No newline at end of file +#endif -- cgit v1.2.3