Merge pull request #31395 from ptrojahn/floatsarenasty

Replace is_zero_approx(A.distance_to(B)) with A==B
This commit is contained in:
Rémi Verschelde 2019-08-20 12:54:40 +02:00 committed by GitHub
commit a8db4c848d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 13 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) { static bool edge_compare(const Vector<Vector2> &p_vertices, const Edge &p_a, const Edge &p_b) {
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]]))) { if (p_vertices[p_a.edge[0]] == p_vertices[p_b.edge[0]] && p_vertices[p_a.edge[1]] == p_vertices[p_b.edge[1]]) {
return true; return true;
} }
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]]))) { if (p_vertices[p_a.edge[0]] == p_vertices[p_b.edge[1]] && p_vertices[p_a.edge[1]] == p_vertices[p_b.edge[0]]) {
return true; return true;
} }

View file

@ -242,7 +242,7 @@ void CSGBrushOperation::BuildPoly::_clip_segment(const CSGBrush *p_brush, int p_
//check if edge and poly share a vertex, of so, assign it to segment_idx //check if edge and poly share a vertex, of so, assign it to segment_idx
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
if (Math::is_zero_approx(segment[j].distance_to(points[i].point))) { if (segment[j] == points[i].point) {
segment_idx[j] = i; segment_idx[j] = i;
inserted_points.push_back(i); inserted_points.push_back(i);
break; break;
@ -310,7 +310,7 @@ void CSGBrushOperation::BuildPoly::_clip_segment(const CSGBrush *p_brush, int p_
Vector2 edgeseg[2] = { points[edges[i].points[0]].point, points[edges[i].points[1]].point }; Vector2 edgeseg[2] = { points[edges[i].points[0]].point, points[edges[i].points[1]].point };
Vector2 closest = Geometry::get_closest_point_to_segment_2d(segment[j], edgeseg); Vector2 closest = Geometry::get_closest_point_to_segment_2d(segment[j], edgeseg);
if (Math::is_zero_approx(closest.distance_to(segment[j]))) { if (closest == segment[j]) {
//point rest of this edge //point rest of this edge
res = closest; res = closest;
found = true; found = true;
@ -439,7 +439,7 @@ void CSGBrushOperation::BuildPoly::clip(const CSGBrush *p_brush, int p_face, Mes
//transform A points to 2D //transform A points to 2D
if (Math::is_zero_approx(segment[0].distance_to(segment[1]))) if (segment[0] == segment[1])
return; //too small return; //too small
_clip_segment(p_brush, p_face, segment, mesh_merge, p_for_B); _clip_segment(p_brush, p_face, segment, mesh_merge, p_for_B);
@ -461,10 +461,10 @@ void CSGBrushOperation::_collision_callback(const CSGBrush *A, int p_face_a, Map
{ {
//check if either is a degenerate //check if either is a degenerate
if (Math::is_zero_approx(va[0].distance_to(va[1])) || Math::is_zero_approx(va[0].distance_to(va[2])) || Math::is_zero_approx(va[1].distance_to(va[2]))) if (va[0] == va[1] || va[0] == va[2] || va[1] == va[2])
return; return;
if (Math::is_zero_approx(vb[0].distance_to(vb[1])) || Math::is_zero_approx(vb[0].distance_to(vb[2])) || Math::is_zero_approx(vb[1].distance_to(vb[2]))) if (vb[0] == vb[1] || vb[0] == vb[2] || vb[1] == vb[2])
return; return;
} }

View file

@ -551,7 +551,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
left_poly = p; left_poly = p;
portal_left = apex_point; portal_left = apex_point;
portal_right = apex_point; portal_right = apex_point;
if (!path.size() || !Math::is_zero_approx(path[path.size() - 1].distance_to(apex_point))) if (!path.size() || path[path.size() - 1] != apex_point)
path.push_back(apex_point); path.push_back(apex_point);
skip = true; skip = true;
} }
@ -569,7 +569,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
right_poly = p; right_poly = p;
portal_right = apex_point; portal_right = apex_point;
portal_left = apex_point; portal_left = apex_point;
if (!path.size() || !Math::is_zero_approx(path[path.size() - 1].distance_to(apex_point))) if (!path.size() || path[path.size() - 1] != apex_point)
path.push_back(apex_point); path.push_back(apex_point);
} }
} }

View file

@ -2870,9 +2870,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
const Vector3 &v1 = t1.value.loc; const Vector3 &v1 = t1.value.loc;
const Vector3 &v2 = t2.value.loc; const Vector3 &v2 = t2.value.loc;
if (Math::is_zero_approx(v0.distance_to(v2))) { if (v0 == v2) {
//0 and 2 are close, let's see if 1 is close //0 and 2 are close, let's see if 1 is close
if (!Math::is_zero_approx(v0.distance_to(v1))) { if (v0 != v1) {
//not close, not optimizable //not close, not optimizable
return false; return false;
} }
@ -2959,9 +2959,9 @@ bool Animation::_transform_track_optimize_key(const TKey<TransformKey> &t0, cons
const Vector3 &v1 = t1.value.scale; const Vector3 &v1 = t1.value.scale;
const Vector3 &v2 = t2.value.scale; const Vector3 &v2 = t2.value.scale;
if (Math::is_zero_approx(v0.distance_to(v2))) { if (v0 == v2) {
//0 and 2 are close, let's see if 1 is close //0 and 2 are close, let's see if 1 is close
if (!Math::is_zero_approx(v0.distance_to(v1))) { if (v0 != v1) {
//not close, not optimizable //not close, not optimizable
return false; return false;
} }