diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-11-16 18:08:47 -0700 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-11-16 18:09:33 -0700 |
commit | 6d0c93dccf14eaf21018ada0ab8575a98858e536 (patch) | |
tree | 7c4c0396579da104b7be47aa26297011400d463e | |
parent | 11e03ae7f085b53505c242cf92615f7170c779ce (diff) |
Fix segment intersection in Geometry2D
Doing a multiplication to reduce the amount of tests was causing
precision which lead to 2D raycast detecting false positive contacts
in some cases with convex polygons.
-rw-r--r-- | core/math/geometry_2d.h | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index 6010159597..028ac0f4eb 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -181,8 +181,7 @@ public: D = Vector2(D.x * Bn.x + D.y * Bn.y, D.y * Bn.x - D.x * Bn.y); // Fail if C x B and D x B have the same sign (segments don't intersect). - // (equivalent to condition (C.y < 0 && D.y < CMP_EPSILON) || (C.y > 0 && D.y > CMP_EPSILON)) - if (C.y * D.y > CMP_EPSILON) { + if ((C.y < -CMP_EPSILON && D.y < -CMP_EPSILON) || (C.y > CMP_EPSILON && D.y > CMP_EPSILON)) { return false; } |