Skip to content

Commit d87dba7

Browse files
authored
relative point in rect helper (#2378)
1 parent f273639 commit d87dba7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

arcade/types/rect.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,20 @@ def uv_to_position(self, uv: Point2) -> Vec2:
572572
x, y = uv
573573
return Vec2(self.left + x * self.width, self.bottom + y * self.height)
574574

575+
def get_relative_to_anchor(self, point: Point2, anchor: Vec2 = AnchorPoint.CENTER) -> Vec2:
576+
"""Convert a point to a relative offset from the anchor point.
577+
578+
Args:
579+
point:
580+
The point to make relative.
581+
anchor:
582+
The anchor point to make the point relative to.
583+
"""
584+
x, y = point
585+
rx = x - (self.left + (self.width * anchor.x))
586+
ry = y - (self.bottom + (self.height * anchor.y))
587+
return Vec2(rx, ry)
588+
575589
def to_points(self) -> tuple[Vec2, Vec2, Vec2, Vec2]:
576590
"""Return a new :py:class:`tuple` of this rectangle's corner points.
577591

0 commit comments

Comments
 (0)