UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
convexpolygon.h
Go to the documentation of this file.
1 #ifndef PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_
2 #define PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_
3 
5 #include <vector>
6 
7 namespace pyramidworks {
8 namespace geometry {
9 
12 class ConvexPolygon : public GeometricShape {
13  public:
17  ConvexPolygon(const std::vector<ugdk::Vector2D>& vertices);
18 
19  void set_vertices(const std::vector<ugdk::Vector2D>& vertices) { vertices_ = vertices; this->calculateSize(); }
20 
21  bool Intersects(const ugdk::Vector2D& this_pos, const GeometricShape *obj, const ugdk::Vector2D& that_pos) const;
22  bool Intersects(const ugdk::Vector2D& this_pos, const Rect *obj, const ugdk::Vector2D& that_pos) const;
23  bool Intersects(const ugdk::Vector2D& this_pos, const Circle *obj, const ugdk::Vector2D& that_pos) const;
24  bool Intersects(const ugdk::Vector2D& this_pos, const ConvexPolygon *obj, const ugdk::Vector2D& that_pos) const;
26 
27  double bbox_width() { return bbox_half_width_*2; }
28  double bbox_height() { return bbox_half_height_*2; }
29 
30  private:
31  std::vector<ugdk::Vector2D> vertices_;
32  double bbox_half_width_, bbox_half_height_;
33 
34  void calculateSize();
35 
38 
45  bool checkAxisSeparation(const std::vector<ugdk::Vector2D>& obj1, const ugdk::Vector2D& obj1pos,
46  const std::vector<ugdk::Vector2D>& obj2, const ugdk::Vector2D& obj2pos) const;
47  bool axisSeparationTest(const ugdk::Vector2D& p1, const ugdk::Vector2D& p2, const ugdk::Vector2D& ref,
48  const std::vector<ugdk::Vector2D>& obj, const ugdk::Vector2D& obj2pos) const;
49  bool insideSameSpace(const ugdk::Vector2D& line, const ugdk::Vector2D& point) const;
50 };
51 
52 } // namespace geometry
53 } // namespace pyramidworks
54 
55 
56 #endif /* PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_ */