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 0c391b11..4e88ca26 100644
--- a/include/cru/platform/GraphicsBase.h
+++ b/include/cru/platform/GraphicsBase.h
@@ -2,6 +2,7 @@
#include <cru/base/Range.h>
#include <cru/base/StringUtil.h>
+#include <cmath>
#include <format>
#include <limits>
@@ -21,6 +22,11 @@ struct Point final {
constexpr Point Negate() const { return Point(-x, -y); }
+ constexpr float Distance(const Point& other) {
+ auto dx = x - other.x, dy = y - other.y;
+ return std::sqrt(dx * dx + dy * dy);
+ }
+
std::string ToString() const {
return std::format("Point(x: {}, y: {})", x, y);
}
@@ -39,6 +45,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);
+}
+
struct Size final {
constexpr Size() = default;
constexpr Size(const float width, const float height)