aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/GraphicsBase.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/cru/platform/GraphicsBase.h')
-rw-r--r--include/cru/platform/GraphicsBase.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/include/cru/platform/GraphicsBase.h b/include/cru/platform/GraphicsBase.h
index b0f653ef..d9057beb 100644
--- a/include/cru/platform/GraphicsBase.h
+++ b/include/cru/platform/GraphicsBase.h
@@ -5,6 +5,7 @@
#include "cru/base/Range.h"
#include "cru/base/String.h"
+#include <cmath>
#include <format>
#include <limits>
@@ -24,6 +25,11 @@ struct Point final {
constexpr Point Negate() const { return Point(-x, -y); }
+ static constexpr float Distance(const Point& p1, const Point& p2) {
+ auto dx = p1.x - p2.x, dy = p1.y - p2.y;
+ return std::sqrt(dx * dx + dy * dy);
+ }
+
float x = 0;
float y = 0;
};
@@ -36,6 +42,10 @@ constexpr Point operator-(const Point& left, const Point& right) {
return Point(left.x - right.x, left.y - right.y);
}
+constexpr Point operator/(const Point& point, float scale) {
+ return Point(point.x / scale, point.y / scale);
+}
+
constexpr bool operator==(const Point& left, const Point& right) {
return left.x == right.x && left.y == right.y;
}