mirror of
https://github.com/tiennm99/godot.git
synced 2026-08-06 08:22:49 +00:00
Use approximate equallity methods in many places
This commit is contained in:
@@ -542,7 +542,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
|
||||
|
||||
if (CLOCK_TANGENT(apex_point, portal_left, left) >= 0) {
|
||||
//process
|
||||
if (portal_left.distance_squared_to(apex_point) < CMP_EPSILON || CLOCK_TANGENT(apex_point, left, portal_right) > 0) {
|
||||
if (Math::is_zero_approx(portal_left.distance_squared_to(apex_point)) || CLOCK_TANGENT(apex_point, left, portal_right) > 0) {
|
||||
left_poly = p;
|
||||
portal_left = left;
|
||||
} else {
|
||||
@@ -552,7 +552,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
|
||||
left_poly = p;
|
||||
portal_left = apex_point;
|
||||
portal_right = apex_point;
|
||||
if (!path.size() || path[path.size() - 1].distance_to(apex_point) > CMP_EPSILON)
|
||||
if (!path.size() || !Math::is_zero_approx(path[path.size() - 1].distance_to(apex_point)))
|
||||
path.push_back(apex_point);
|
||||
skip = true;
|
||||
}
|
||||
@@ -560,7 +560,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
|
||||
|
||||
if (!skip && CLOCK_TANGENT(apex_point, portal_right, right) <= 0) {
|
||||
//process
|
||||
if (portal_right.distance_squared_to(apex_point) < CMP_EPSILON || CLOCK_TANGENT(apex_point, right, portal_left) < 0) {
|
||||
if (Math::is_zero_approx(portal_right.distance_squared_to(apex_point)) || CLOCK_TANGENT(apex_point, right, portal_left) < 0) {
|
||||
right_poly = p;
|
||||
portal_right = right;
|
||||
} else {
|
||||
@@ -570,7 +570,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
|
||||
right_poly = p;
|
||||
portal_right = apex_point;
|
||||
portal_left = apex_point;
|
||||
if (!path.size() || path[path.size() - 1].distance_to(apex_point) > CMP_EPSILON)
|
||||
if (!path.size() || !Math::is_zero_approx(path[path.size() - 1].distance_to(apex_point)))
|
||||
path.push_back(apex_point);
|
||||
}
|
||||
}
|
||||
@@ -596,7 +596,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
|
||||
}
|
||||
}
|
||||
|
||||
if (!path.size() || path[path.size() - 1].distance_squared_to(begin_point) > CMP_EPSILON) {
|
||||
if (!path.size() || !Math::is_zero_approx(path[path.size() - 1].distance_squared_to(begin_point))) {
|
||||
path.push_back(begin_point); // Add the begin point
|
||||
} else {
|
||||
path.write[path.size() - 1] = begin_point; // Replace first midpoint by the exact begin point
|
||||
@@ -604,7 +604,7 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vect
|
||||
|
||||
path.invert();
|
||||
|
||||
if (path.size() <= 1 || path[path.size() - 1].distance_squared_to(end_point) > CMP_EPSILON) {
|
||||
if (path.size() <= 1 || !Math::is_zero_approx(path[path.size() - 1].distance_squared_to(end_point))) {
|
||||
path.push_back(end_point); // Add the end point
|
||||
} else {
|
||||
path.write[path.size() - 1] = end_point; // Replace last midpoint by the exact end point
|
||||
|
||||
Reference in New Issue
Block a user