summaryrefslogtreecommitdiffstats
path: root/core/math/rect2.h
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-08-22 00:10:39 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-08-22 00:10:39 +0200
commit39b77ea04e5075b15cd704e4d39c156884cbbc38 (patch)
tree9567bb76710fe7bdf3eb4a84ad0a5f073df6ab28 /core/math/rect2.h
parent100fbb51abc7cf8bc373caf0836601cfd9a8c1f1 (diff)
parent7db24a9ad59aeae3e9f8945c518074f76ef80820 (diff)
downloadredot-engine-39b77ea04e5075b15cd704e4d39c156884cbbc38.tar.gz
Merge pull request #95790 from aaronfranke/rect-aabb-support
Simplify Rect2/AABB `get_support` function
Diffstat (limited to 'core/math/rect2.h')
-rw-r--r--core/math/rect2.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/core/math/rect2.h b/core/math/rect2.h
index 9cb341b689..817923c134 100644
--- a/core/math/rect2.h
+++ b/core/math/rect2.h
@@ -285,13 +285,15 @@ struct [[nodiscard]] Rect2 {
return Rect2(position.round(), size.round());
}
- Vector2 get_support(const Vector2 &p_normal) const {
- Vector2 half_extents = size * 0.5f;
- Vector2 ofs = position + half_extents;
- return Vector2(
- (p_normal.x > 0) ? -half_extents.x : half_extents.x,
- (p_normal.y > 0) ? -half_extents.y : half_extents.y) +
- ofs;
+ Vector2 get_support(const Vector2 &p_direction) const {
+ Vector2 support = position;
+ if (p_direction.x > 0.0f) {
+ support.x += size.x;
+ }
+ if (p_direction.y > 0.0f) {
+ support.y += size.y;
+ }
+ return support;
}
_FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const {