diff options
author | Anilforextra <anilforextra@gmail.com> | 2021-09-29 09:36:34 +0545 |
---|---|---|
committer | Anilforextra <anilforextra@gmail.com> | 2021-09-29 09:36:34 +0545 |
commit | fc9767abb14348c2236b487f0bc6d18de65a38fd (patch) | |
tree | ef480b9a349b88a51b75296eae844c27a2504469 /modules | |
parent | 5aa099aaed359df6ff79fe31616b5601db2a42c5 (diff) |
Use functions defined in the their classes.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/csg/csg.cpp | 26 | ||||
-rw-r--r-- | modules/gltf/gltf_document.cpp | 5 | ||||
-rw-r--r-- | modules/gridmap/grid_map.cpp | 5 | ||||
-rw-r--r-- | modules/navigation/nav_map.cpp | 4 |
4 files changed, 17 insertions, 23 deletions
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index f7e92aaa90..229e1e2724 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -37,16 +37,16 @@ // Static helper functions. inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2, real_t p_distance) { - return (p_point1 - p_point2).length_squared() < p_distance * p_distance; + return p_point2.distance_squared_to(p_point1) < p_distance * p_distance; } inline static Vector2 interpolate_segment_uv(const Vector2 p_segment_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) { - float segment_length = (p_segment_points[1] - p_segment_points[0]).length(); if (p_segment_points[0].is_equal_approx(p_segment_points[1])) { return p_uvs[0]; } - float distance = (p_interpolation_point - p_segment_points[0]).length(); + float segment_length = p_segment_points[0].distance_to(p_segment_points[1]); + float distance = p_segment_points[0].distance_to(p_interpolation_point); float fraction = distance / segment_length; return p_uvs[0].lerp(p_uvs[1], fraction); @@ -596,7 +596,7 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de _add_distance(intersectionsA, intersectionsB, current_face.from_b, 0); } } else if (ray_intersects_triangle(face_center, face_normal, current_points, CMP_EPSILON, intersection_point)) { - real_t distance = (intersection_point - face_center).length(); + real_t distance = face_center.distance_to(intersection_point); _add_distance(intersectionsA, intersectionsB, current_face.from_b, distance); } } @@ -781,7 +781,7 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vect int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) { for (int vertex_idx = 0; vertex_idx < vertices.size(); ++vertex_idx) { - if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2) { + if (vertices[vertex_idx].point.distance_squared_to(p_point) < vertex_snap2) { return vertex_idx; } } @@ -961,7 +961,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ // Check if point is existing face vertex. bool existing = false; for (int i = 0; i < 3; ++i) { - if ((point_2D - face_vertices[i].point).length_squared() < vertex_snap2) { + if (face_vertices[i].point.distance_squared_to(point_2D) < vertex_snap2) { existing = true; break; } @@ -978,7 +978,7 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ }; Vector2 closest_point = Geometry2D::get_closest_point_to_segment(point_2D, edge_points); - if ((closest_point - point_2D).length_squared() < vertex_snap2) { + if (point_2D.distance_squared_to(closest_point) < vertex_snap2) { int opposite_vertex_idx = face.vertex_idx[(face_edge_idx + 2) % 3]; // If new vertex snaps to degenerate vertex, just delete this face. @@ -1041,7 +1041,7 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s bool on_edge = false; for (int edge_point_idx = 0; edge_point_idx < 2; ++edge_point_idx) { intersection_point = Geometry2D::get_closest_point_to_segment(p_segment_points[edge_point_idx], edge_points); - if ((intersection_point - p_segment_points[edge_point_idx]).length_squared() < vertex_snap2) { + if (p_segment_points[edge_point_idx].distance_squared_to(intersection_point) < vertex_snap2) { on_edge = true; break; } @@ -1050,8 +1050,8 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s // Else check if the segment intersects the edge. if (on_edge || Geometry2D::segment_intersects_segment(p_segment_points[0], p_segment_points[1], edge_points[0], edge_points[1], &intersection_point)) { // Check if intersection point is an edge point. - if ((intersection_point - edge_points[0]).length_squared() < vertex_snap2 || - (intersection_point - edge_points[1]).length_squared() < vertex_snap2) { + if ((edge_points[0].distance_squared_to(intersection_point) < vertex_snap2) || + (edge_points[1].distance_squared_to(intersection_point) < vertex_snap2)) { continue; } @@ -1078,7 +1078,7 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s // If opposite point is on the segment, add its index to segment indices too. Vector2 closest_point = Geometry2D::get_closest_point_to_segment(vertices[opposite_vertex_idx].point, p_segment_points); - if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2) { + if (vertices[opposite_vertex_idx].point.distance_squared_to(closest_point) < vertex_snap2) { _add_vertex_idx_sorted(r_segment_indices, opposite_vertex_idx); } @@ -1132,7 +1132,7 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { // Check if point is existing face vertex. for (int i = 0; i < 3; ++i) { - if ((p_point - face_vertices[i].point).length_squared() < vertex_snap2) { + if (face_vertices[i].point.distance_squared_to(p_point) < vertex_snap2) { return face.vertex_idx[i]; } } @@ -1150,7 +1150,7 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { }; Vector2 closest_point = Geometry2D::get_closest_point_to_segment(p_point, edge_points); - if ((closest_point - p_point).length_squared() < vertex_snap2) { + if (p_point.distance_squared_to(closest_point) < vertex_snap2) { on_edge = true; // Add the point as a new vertex. diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 97367b15df..a92eb88edb 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3757,10 +3757,7 @@ void GLTFDocument::spec_gloss_to_metal_base_color(const Color &p_specular_factor r_base_color.g = Math::lerp(base_color_from_diffuse.g, base_color_from_specular.g, r_metallic * r_metallic); r_base_color.b = Math::lerp(base_color_from_diffuse.b, base_color_from_specular.b, r_metallic * r_metallic); r_base_color.a = p_diffuse.a; - r_base_color.r = CLAMP(r_base_color.r, 0.0f, 1.0f); - r_base_color.g = CLAMP(r_base_color.g, 0.0f, 1.0f); - r_base_color.b = CLAMP(r_base_color.b, 0.0f, 1.0f); - r_base_color.a = CLAMP(r_base_color.a, 0.0f, 1.0f); + r_base_color = r_base_color.clamp(); } GLTFNodeIndex GLTFDocument::_find_highest_node(Ref<GLTFState> state, const Vector<GLTFNodeIndex> &subset) { diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 487e6deac0..116c0e00f9 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -377,10 +377,7 @@ int GridMap::get_cell_item_orientation(const Vector3i &p_position) const { } Vector3i GridMap::world_to_map(const Vector3 &p_world_position) const { - Vector3 map_position = p_world_position / cell_size; - map_position.x = floor(map_position.x); - map_position.y = floor(map_position.y); - map_position.z = floor(map_position.z); + Vector3 map_position = (p_world_position / cell_size).floor(); return Vector3i(map_position); } diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index 3150ca0bc8..962bf79150 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -664,7 +664,7 @@ void NavMap::sync() { } else { other1 = other_edge_p1.lerp(other_edge_p2, (1.0 - projected_p1_ratio) / (projected_p2_ratio - projected_p1_ratio)); } - if ((self1 - other1).length() > edge_connection_margin) { + if (other1.distance_to(self1) > edge_connection_margin) { continue; } @@ -675,7 +675,7 @@ void NavMap::sync() { } else { other2 = other_edge_p1.lerp(other_edge_p2, (0.0 - projected_p1_ratio) / (projected_p2_ratio - projected_p1_ratio)); } - if ((self2 - other2).length() > edge_connection_margin) { + if (other2.distance_to(self2) > edge_connection_margin) { continue; } |