Skip to content

Commit

Permalink
Fix segment intersection in Geometry2D
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pouleyKetchoupp committed Nov 17, 2021
1 parent 11e03ae commit 6d0c93d
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions core/math/geometry_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ class Geometry2D {
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;
}

Expand Down

0 comments on commit 6d0c93d

Please sign in to comment.