diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-07 22:25:54 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-10-07 22:25:54 +0200 |
commit | db8679443fb6fcd5f9a97abf3e25c9e64f256607 (patch) | |
tree | 3adaf7df7db0ce66302490f3e5e9cbf263645929 /src/variant/rect2.cpp | |
parent | 0eba81ef79b96922a0e1637f812e4e1df4d29a4c (diff) | |
parent | 65eeb94f75d00cf523da114de3587f930cdec13f (diff) | |
download | redot-cpp-db8679443fb6fcd5f9a97abf3e25c9e64f256607.tar.gz |
Merge pull request #885 from aaronfranke/core-data-structs
Update core data structures to match the engine
Diffstat (limited to 'src/variant/rect2.cpp')
-rw-r--r-- | src/variant/rect2.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/variant/rect2.cpp b/src/variant/rect2.cpp index 53f06c6..1d15da7 100644 --- a/src/variant/rect2.cpp +++ b/src/variant/rect2.cpp @@ -41,6 +41,11 @@ bool Rect2::is_equal_approx(const Rect2 &p_rect) const { } bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const { +#ifdef MATH_CHECKS + if (unlikely(size.x < 0 || size.y < 0)) { + ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size."); + } +#endif real_t min = 0, max = 1; int axis = 0; real_t sign = 0; @@ -101,6 +106,11 @@ bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 } bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const { +#ifdef MATH_CHECKS + if (unlikely(size.x < 0 || size.y < 0 || p_rect.size.x < 0 || p_rect.size.y < 0)) { + ERR_PRINT("Rect2 size is negative, this is not supported. Use Rect2.abs() to get a Rect2 with a positive size."); + } +#endif //SAT intersection between local and transformed rect2 Vector2 xf_points[4] = { @@ -271,7 +281,7 @@ next4: } Rect2::operator String() const { - return String(position) + ", " + String(size); + return "[P: " + position.operator String() + ", S: " + size + "]"; } Rect2::operator Rect2i() const { |