From 6d0c93dccf14eaf21018ada0ab8575a98858e536 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Tue, 16 Nov 2021 18:08:47 -0700 Subject: 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. --- core/math/geometry_2d.h | 3 +-- 1 file changed, 1 insertion(+), 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; } -- cgit v1.2.3