Merge pull request #50521 from aaronfranke/iseqapprox

Use `is_equal_approx` in more places
This commit is contained in:
Rémi Verschelde 2021-07-21 11:16:19 +02:00 committed by GitHub
commit d4bbdb8367
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 26 additions and 28 deletions

View file

@ -42,7 +42,7 @@ inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2,
inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) {
float segment_length = (p_segement_points[1] - p_segement_points[0]).length();
if (segment_length < CMP_EPSILON) {
if (p_segement_points[0].is_equal_approx(p_segement_points[1])) {
return p_uvs[0];
}
@ -53,13 +53,13 @@ inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2],
}
inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const Vector2 p_uvs[3], const Vector2 &p_interpolation_point) {
if (p_interpolation_point.distance_squared_to(p_vertices[0]) < CMP_EPSILON2) {
if (p_interpolation_point.is_equal_approx(p_vertices[0])) {
return p_uvs[0];
}
if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2) {
if (p_interpolation_point.is_equal_approx(p_vertices[1])) {
return p_uvs[1];
}
if (p_interpolation_point.distance_squared_to(p_vertices[2]) < CMP_EPSILON2) {
if (p_interpolation_point.is_equal_approx(p_vertices[2])) {
return p_uvs[2];
}
@ -589,7 +589,7 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de
Vector3 intersection_point;
// Check if faces are co-planar.
if ((current_normal - face_normal).length_squared() < CMP_EPSILON2 &&
if (current_normal.is_equal_approx(face_normal) &&
is_point_in_triangle(face_center, current_points)) {
// Only add an intersection if not a B face.
if (!face.from_b) {

View file

@ -778,7 +778,7 @@ CSGBrush *CSGMesh3D::_build_brush() {
}
}
bool flat = normal[0].distance_to(normal[1]) < CMP_EPSILON && normal[0].distance_to(normal[2]) < CMP_EPSILON;
bool flat = normal[0].is_equal_approx(normal[1]) && normal[0].is_equal_approx(normal[2]);
vw[as + j + 0] = vertex[0];
vw[as + j + 1] = vertex[1];
@ -820,7 +820,7 @@ CSGBrush *CSGMesh3D::_build_brush() {
}
}
bool flat = normal[0].distance_to(normal[1]) < CMP_EPSILON && normal[0].distance_to(normal[2]) < CMP_EPSILON;
bool flat = normal[0].is_equal_approx(normal[1]) && normal[0].is_equal_approx(normal[2]);
vw[as + j + 0] = vertex[0];
vw[as + j + 1] = vertex[1];

View file

@ -525,7 +525,7 @@ void FBXMeshData::reorganize_vertices(
}
const Vector3 vert_poly_normal = *nrml_arr->getptr(*pid);
if ((this_vert_poly_normal - vert_poly_normal).length_squared() > CMP_EPSILON) {
if (!vert_poly_normal.is_equal_approx(this_vert_poly_normal)) {
// Yes this polygon need duplication.
need_duplication = true;
break;
@ -586,7 +586,7 @@ void FBXMeshData::reorganize_vertices(
continue;
}
const Vector2 vert_poly_uv = *uvs->getptr(*pid);
if (((*this_vert_poly_uv) - vert_poly_uv).length_squared() > CMP_EPSILON) {
if (!vert_poly_uv.is_equal_approx(*this_vert_poly_uv)) {
// Yes this polygon need duplication.
need_duplication = true;
break;

View file

@ -734,7 +734,7 @@ void NavMap::dispatch_callbacks() {
void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys, Vector<Vector3> &path, const gd::NavigationPoly *from_poly, const Vector3 &p_to_point, const gd::NavigationPoly *p_to_poly) const {
Vector3 from = path[path.size() - 1];
if (from.distance_to(p_to_point) < CMP_EPSILON) {
if (from.is_equal_approx(p_to_point)) {
return;
}
Plane cut_plane;
@ -752,10 +752,10 @@ void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys
ERR_FAIL_COND(from_poly->back_navigation_poly_id == -1);
from_poly = &p_navigation_polys[from_poly->back_navigation_poly_id];
if (pathway_start.distance_to(pathway_end) > CMP_EPSILON) {
if (!pathway_start.is_equal_approx(pathway_end)) {
Vector3 inters;
if (cut_plane.intersects_segment(pathway_start, pathway_end, &inters)) {
if (inters.distance_to(p_to_point) > CMP_EPSILON && inters.distance_to(path[path.size() - 1]) > CMP_EPSILON) {
if (!inters.is_equal_approx(p_to_point) && !inters.is_equal_approx(path[path.size() - 1])) {
path.push_back(inters);
}
}