polygon_path_finder.h
1 #ifndef POLYGON_PATH_FINDER_H
2 #define POLYGON_PATH_FINDER_H
3 
4 #include "resource.h"
5 
6 class PolygonPathFinder : public Resource {
7 
8  OBJ_TYPE(PolygonPathFinder,Resource);
9 
10  struct Point {
11  Vector2 pos;
12  Set<int> connections;
13  float distance;
14  float penalty;
15  int prev;
16  };
17 
18  struct Edge {
19 
20  int points[2];
21 
22  _FORCE_INLINE_ bool operator<(const Edge& p_edge) const {
23 
24  if (points[0]==p_edge.points[0])
25  return points[1]<p_edge.points[1];
26  else
27  return points[0]<p_edge.points[0];
28  }
29 
30  Edge(int a=0, int b=0) {
31 
32  if (a>b) {
33  SWAP(a,b);
34  }
35  points[0] = a;
36  points[1] = b;
37  }
38  };
39 
40  Vector2 outside_point;
41  Rect2 bounds;
42 
43  Vector<Point> points;
44  Set<Edge> edges;
45 
46  bool _is_point_inside(const Vector2& p_point) const;
47 
48  void _set_data(const Dictionary& p_data);
49  Dictionary _get_data() const;
50 protected:
51 
52  static void _bind_methods();
53 public:
54 
55 
56  void setup(const Vector<Vector2>& p_points, const Vector<int>& p_connections);
57  Vector<Vector2> find_path(const Vector2& p_from, const Vector2& p_to);
58 
59  void set_point_penalty(int p_point,float p_penalty);
60  float get_point_penalty(int p_point) const;
61 
62  bool is_point_inside(const Vector2& p_point) const;
63  Vector2 get_closest_point(const Vector2& p_point) const;
64  Vector<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const;
65  Rect2 get_bounds() const;
66 
67 
69 };
70 
71 #endif // POLYGON_PATH_FINDER_H
Definition: math_2d.h:204
Definition: resource.h:89
Definition: dictionary.h:42
Definition: math_2d.h:65
Definition: polygon_path_finder.h:6