Use approximate equallity methods in many places

This commit is contained in:
Aaron Franke 2019-01-16 10:42:53 -05:00
parent c577ec6ae4
commit b659e1eb2b
No known key found for this signature in database
GPG key ID: 40A1750B977E56BF
21 changed files with 66 additions and 66 deletions

View file

@ -80,11 +80,11 @@ public:
}
static bool edge_compare(const Vector<Vector2> &p_vertices, const Edge &p_a, const Edge &p_b) {
if (p_vertices[p_a.edge[0]].distance_to(p_vertices[p_b.edge[0]]) < CMP_EPSILON && p_vertices[p_a.edge[1]].distance_to(p_vertices[p_b.edge[1]]) < CMP_EPSILON) {
if (Math::is_zero_approx(p_vertices[p_a.edge[0]].distance_to(p_vertices[p_b.edge[0]])) && Math::is_zero_approx(p_vertices[p_a.edge[1]].distance_to(p_vertices[p_b.edge[1]]))) {
return true;
}
if (p_vertices[p_a.edge[0]].distance_to(p_vertices[p_b.edge[1]]) < CMP_EPSILON && p_vertices[p_a.edge[1]].distance_to(p_vertices[p_b.edge[0]]) < CMP_EPSILON) {
if (Math::is_zero_approx(p_vertices[p_a.edge[0]].distance_to(p_vertices[p_b.edge[1]])) && Math::is_zero_approx(p_vertices[p_a.edge[1]].distance_to(p_vertices[p_b.edge[0]]))) {
return true;
}

View file

@ -836,7 +836,7 @@ Geometry::MeshData Geometry::build_convex_mesh(const PoolVector<Plane> &p_planes
Vector3 rel = edge1_A - edge0_A;
real_t den = clip.normal.dot(rel);
if (Math::abs(den) < CMP_EPSILON)
if (Math::is_zero_approx(den))
continue; // point too short
real_t dist = -(clip.normal.dot(edge0_A) - clip.d) / den;

View file

@ -181,8 +181,8 @@ public:
}
}
// finally do the division to get sc and tc
sc = (Math::abs(sN) < CMP_EPSILON ? 0.0 : sN / sD);
tc = (Math::abs(tN) < CMP_EPSILON ? 0.0 : tN / tD);
sc = (Math::is_zero_approx(sN) ? 0.0 : sN / sD);
tc = (Math::is_zero_approx(tN) ? 0.0 : tN / tD);
// get the difference of the two closest points
Vector3 dP = w + (sc * u) - (tc * v); // = S1(sc) - S2(tc)
@ -195,7 +195,7 @@ public:
Vector3 e2 = p_v2 - p_v0;
Vector3 h = p_dir.cross(e2);
real_t a = e1.dot(h);
if (a > -CMP_EPSILON && a < CMP_EPSILON) // parallel test
if (Math::is_zero_approx(a)) // parallel test
return false;
real_t f = 1.0 / a;
@ -233,7 +233,7 @@ public:
Vector3 e2 = p_v2 - p_v0;
Vector3 h = rel.cross(e2);
real_t a = e1.dot(h);
if (a > -CMP_EPSILON && a < CMP_EPSILON) // parallel test
if (Math::is_zero_approx(a)) // parallel test
return false;
real_t f = 1.0 / a;
@ -535,7 +535,7 @@ public:
// see http://paulbourke.net/geometry/pointlineplane/
const real_t denom = p_dir_b.y * p_dir_a.x - p_dir_b.x * p_dir_a.y;
if (Math::abs(denom) < CMP_EPSILON) { // parallel?
if (Math::is_zero_approx(denom)) { // parallel?
return false;
}