BVB Source Codes

CRYENGINE Show Polygon2d.h Source code

Return Download CRYENGINE: download Polygon2d.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #ifndef POLYGON2D_H
  4. #define POLYGON2D_H
  5.  
  6. #include "Utils.h"
  7.  
  8. #include "LineSeg.h"
  9. #include "BiDirMap.h"
  10.  
  11. class BspLineSegSplitter;
  12. class BspTree2d;
  13.  
  14. /**
  15.  * @brief 2D polygon class with support for set operations and subsequent contour extraction.
  16.  */
  17. class Polygon2d
  18. {
  19. public:
  20.  
  21.         /**
  22.          * Not really a stand-alone polygon edge class, vertices are only stored as
  23.          * indices into the owning Polygon2d::m_vertices.
  24.          */
  25.         class Edge
  26.         {
  27.         public:
  28.                 Edge(int ind0 = -1, int ind1 = -1);
  29.  
  30.                 bool operator<(const Edge& rhs) const;
  31.                 bool operator==(const Edge& rhs) const;
  32.  
  33.                 int m_vertIndex0;
  34.                 int m_vertIndex1;
  35.         };
  36.  
  37.         Polygon2d();
  38.         Polygon2d(const LineSegVec& edges);
  39.         Polygon2d(const Polygon2d& rhs);
  40.         ~Polygon2d();
  41.  
  42.         Polygon2d& operator=(const Polygon2d& rhs);
  43.  
  44.         int        AddVertex(const Vector2d&);
  45.         int        AddEdge(const Edge&);
  46.         int        AddEdge(const Vector2d& v0, const Vector2d& v1);
  47.  
  48.         bool       GetVertex(int i, Vector2d& vertex) const;
  49.         bool       GetEdge(int i, Edge& edge) const;
  50.  
  51.         int        NumVertices() const;
  52.         int        NumEdges() const;
  53.  
  54.         // calculates the contiguous pts from the edges. If removeInterior then any contours that are encircled
  55.         // by another contour get removed. All are guaranteed to be anti-clockwise wound
  56.         void     CalculateContours(bool removeInterior);
  57.         // returns the number of unique contours
  58.         unsigned GetContourQuantity() const;
  59.         // gets the ith contour - returns the number of points
  60.         unsigned GetContour(unsigned i, const Vector2d** ppPts) const;
  61.  
  62.         /// Set inversion operator.
  63.         Polygon2d operator~() const;
  64.  
  65.         /// Set union operator.
  66.         Polygon2d operator|(const Polygon2d& rhs) const;
  67.  
  68.         /// Set intersection operator.
  69.         Polygon2d operator&(const Polygon2d& rhs) const;
  70.  
  71.         /// Symmetric difference (AKA xor) operator.
  72.         Polygon2d operator^(const Polygon2d& rhs) const;
  73.  
  74.         /// Complement (or set difference) operator.
  75.         Polygon2d operator-(const Polygon2d& rhs) const;
  76.  
  77.         // this only makes sense if there's only one contour
  78.         bool IsWoundAnticlockwise() const;
  79.  
  80.         void CollapseVertices(double tol);
  81.  
  82. private:
  83.  
  84.         /// Computes BspTree2d using this polygon's edges as dividing hyperplanes and caches it in m_bsp.
  85.         void ComputeBspTree() const;
  86.         /// Cuts all of this polygon's edges by edge splitter passed in the argument.
  87.         void Cut(BspLineSegSplitter&) const;
  88.  
  89.         BidirectionalMap<int, Vector2d> m_vertices;
  90.         BidirectionalMap<int, Edge>     m_edges;
  91.  
  92.         /// Cached corresponding BSP tree, useful during set operations.
  93.         mutable BspTree2d*                 m_bsp;
  94.  
  95.         std::vector<std::vector<Vector2d>> m_contours;
  96. };
  97.  
  98. #endif
  99.  
downloadPolygon2d.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top