Skip to content

Commit

Permalink
Prevent float rounding issues in LineVsPoly test
Browse files Browse the repository at this point in the history
Closes #7
  • Loading branch information
GaryOderNichts committed May 8, 2022
1 parent 93f97d4 commit d08fff8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions soh/src/code/z_bgcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,14 @@ s32 CollisionPoly_LineVsPoly(CollisionPoly* poly, Vec3s* vtxList, Vec3f* posA, V
(poly->normal.x * posB->x + poly->normal.y * posB->y + poly->normal.z * posB->z) * COLPOLY_NORMAL_FRAC +
plane.originDist;

// on some platforms this ends up as very small numbers due to rounding issues
if (IS_ZERO(planeDistA)) {
planeDistA = 0.0f;
}
if (IS_ZERO(planeDistB)) {
planeDistB = 0.0f;
}

planeDistDelta = planeDistA - planeDistB;
if ((planeDistA >= 0.0f && planeDistB >= 0.0f) || (planeDistA < 0.0f && planeDistB < 0.0f) ||
(chkOneFace && planeDistA < 0.0f && planeDistB > 0.0f) || IS_ZERO(planeDistDelta)) {
Expand Down

0 comments on commit d08fff8

Please sign in to comment.