Merge pull request #103993 from aaronfranke/geometry-segment

Directly use segment points in Geometry2D/3D function parameters
This commit is contained in:
Thaddeus Crews 2025-04-01 08:01:34 -05:00
commit d52b84e472
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
30 changed files with 205 additions and 224 deletions

View file

@ -328,8 +328,7 @@ void NavMeshQueries3D::_query_task_build_path_corridor(NavMeshPathQueryTask3D &p
continue;
}
Vector3 pathway[2] = { connection.pathway_start, connection.pathway_end };
const Vector3 new_entry = Geometry3D::get_closest_point_to_segment(least_cost_poly.entry, pathway);
const Vector3 new_entry = Geometry3D::get_closest_point_to_segment(least_cost_poly.entry, connection.pathway_start, connection.pathway_end);
const real_t new_traveled_distance = least_cost_poly.entry.distance_to(new_entry) * poly_travel_cost + poly_enter_cost + least_cost_poly.traveled_distance;
// Check if the neighbor polygon has already been processed.
@ -585,8 +584,7 @@ void NavMeshQueries3D::_query_task_post_process_corridorfunnel(NavMeshPathQueryT
// Set the apex poly/point to the end point
NavigationPoly *apex_poly = &navigation_polys[least_cost_id];
Vector3 back_pathway[2] = { apex_poly->back_navigation_edge_pathway_start, apex_poly->back_navigation_edge_pathway_end };
const Vector3 back_edge_closest_point = Geometry3D::get_closest_point_to_segment(end_point, back_pathway);
const Vector3 back_edge_closest_point = Geometry3D::get_closest_point_to_segment(end_point, apex_poly->back_navigation_edge_pathway_start, apex_poly->back_navigation_edge_pathway_end);
if (end_point.is_equal_approx(back_edge_closest_point)) {
// The end point is basically on top of the last crossed edge, funneling around the corners would at best do nothing.
// At worst it would add an unwanted path point before the last point due to precision issues so skip to the next polygon.
@ -1178,7 +1176,8 @@ LocalVector<uint32_t> NavMeshQueries3D::get_simplified_path_indices(const LocalV
}
void NavMeshQueries3D::simplify_path_segment(int p_start_inx, int p_end_inx, const LocalVector<Vector3> &p_points, real_t p_epsilon, LocalVector<uint32_t> &r_simplified_path_indices) {
Vector3 path_segment[2] = { p_points[p_start_inx], p_points[p_end_inx] };
const Vector3 path_segment_a = p_points[p_start_inx];
const Vector3 path_segment_b = p_points[p_end_inx];
real_t point_max_distance = 0.0;
int point_max_index = 0;
@ -1186,7 +1185,7 @@ void NavMeshQueries3D::simplify_path_segment(int p_start_inx, int p_end_inx, con
for (int i = p_start_inx; i < p_end_inx; i++) {
const Vector3 &checked_point = p_points[i];
const Vector3 closest_point = Geometry3D::get_closest_point_to_segment(checked_point, path_segment);
const Vector3 closest_point = Geometry3D::get_closest_point_to_segment(checked_point, path_segment_a, path_segment_b);
real_t distance_squared = closest_point.distance_squared_to(checked_point);
if (distance_squared > point_max_distance) {