summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2023-04-21 22:52:28 +0200
committerAki <please@ignore.pl>2024-04-05 19:41:19 +0200
commit654c94e1d312970413e376214b11bd554040d30f (patch)
tree217084920141425c3f7f5bbc4657a97523dde5c0 /engine/src
parent727ae858a73f4c36bf253a873530dc4dd78c498f (diff)
downloadkurator-654c94e1d312970413e376214b11bd554040d30f.zip
kurator-654c94e1d312970413e376214b11bd554040d30f.tar.gz
kurator-654c94e1d312970413e376214b11bd554040d30f.tar.bz2
Replaced Mouse dragging start+pos combo with a Rect
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/Point.cpp7
-rw-r--r--engine/src/Rect.cpp74
2 files changed, 81 insertions, 0 deletions
diff --git a/engine/src/Point.cpp b/engine/src/Point.cpp
index e01de57..8dd50bd 100644
--- a/engine/src/Point.cpp
+++ b/engine/src/Point.cpp
@@ -96,5 +96,12 @@ Point::operator!=(const Point& other) const
}
+Point
+abs(const Point& point)
+{
+ return {std::abs(point.x), std::abs(point.y)};
+}
+
+
} // namespace engine
} // namespace kurator
diff --git a/engine/src/Rect.cpp b/engine/src/Rect.cpp
new file mode 100644
index 0000000..293e099
--- /dev/null
+++ b/engine/src/Rect.cpp
@@ -0,0 +1,74 @@
+#include <kurator/engine/Rect.h>
+
+#include <algorithm>
+#include <cmath>
+
+#include <raylib.h>
+
+#include <kurator/engine/Point.h>
+
+
+using std::abs;
+
+
+namespace kurator
+{
+namespace engine
+{
+
+
+Rect::Rect() :
+ position {0, 0},
+ size {0, 0}
+{
+}
+
+
+Rect::Rect(const Point& first, const Point& second) :
+ position {std::min(first.x, second.x), std::min(first.y, second.y)},
+ size {abs(second - first)}
+{
+}
+
+
+Point Rect::topleft() const
+{
+ return position;
+}
+
+
+Point Rect::bottomright() const
+{
+ return position + size;
+}
+
+
+Point Rect::center() const
+{
+ return position + size.scale(0.5);
+}
+
+
+bool Rect::contains(const Point& point)
+{
+ const auto br = bottomright();
+ return point.x >= position.x && point.x <= br.x && point.y >= position.y && point.y <= br.y;
+}
+
+
+bool Rect::contains(const Point& circle, double radius)
+{
+ return CheckCollisionCircleRec(
+ {static_cast<float>(circle.x), static_cast<float>(circle.y)},
+ radius,
+ {
+ static_cast<float>(position.x),
+ static_cast<float>(position.y),
+ static_cast<float>(size.x),
+ static_cast<float>(size.y)
+ });
+}
+
+
+} // namespace engine
+} // namespace kurator