From 8db3c0a4dbf32d498bd9dfd84eab7f4a18757fea Mon Sep 17 00:00:00 2001 From: romulox_x Date: Sun, 1 Feb 2015 09:23:31 -0800 Subject: [PATCH] changed PolygonPathFinder::get_closest_point to return the closest position inside, rather then the closest vertex --- scene/resources/polygon_path_finder.cpp | 26 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 9f691d6ad39..e8cdec66df0 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -525,24 +525,32 @@ bool PolygonPathFinder::is_point_inside(const Vector2& p_point) const { Vector2 PolygonPathFinder::get_closest_point(const Vector2& p_point) const { - int closest_idx=-1; float closest_dist=1e20; - for(int i=0;i::Element *E=edges.front();E;E=E->next()) { + + const Edge& e=E->get(); + Vector2 seg[2]={ + points[e.points[0]].pos, + points[e.points[1]].pos + }; + + + Vector2 closest = Geometry::get_closest_point_to_segment_2d(p_point,seg); + float d = p_point.distance_squared_to(closest); - float d = p_point.distance_squared_to(points[i].pos); if (d PolygonPathFinder::get_intersections(const Vector2& p_from, const Vector2& p_to) const { Vector inters;