From 02d7f1df3458ca86a2167e158a59653ad2636da9 Mon Sep 17 00:00:00 2001 From: DigiDuncan Date: Sun, 29 Sep 2024 02:14:55 -0400 Subject: [PATCH] relative point in rect helper --- arcade/types/rect.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arcade/types/rect.py b/arcade/types/rect.py index 0c884034b..038e086fd 100644 --- a/arcade/types/rect.py +++ b/arcade/types/rect.py @@ -572,6 +572,20 @@ def uv_to_position(self, uv: Point2) -> Vec2: x, y = uv return Vec2(self.left + x * self.width, self.bottom + y * self.height) + def get_relative_to_anchor(self, point: Point2, anchor: Vec2 = AnchorPoint.CENTER) -> Vec2: + """Convert a point to a relative offset from the anchor point. + + Args: + point: + The point to make relative. + anchor: + The anchor point to make the point relative to. + """ + x, y = point + rx = x - (self.left + (self.width * anchor.x)) + ry = y - (self.bottom + (self.height * anchor.y)) + return Vec2(rx, ry) + def to_points(self) -> tuple[Vec2, Vec2, Vec2, Vec2]: """Return a new :py:class:`tuple` of this rectangle's corner points.