Cogs.Core
Polygon.h
1#pragma once
2
3#include "../FoundationBase.h"
4
5#include "Glm.hpp"
6
7#include <vector>
8
9namespace Cogs {
10 namespace Geometry {
16 class COGSFOUNDATION_API Polygon {
17 public:
18 using List = std::vector<Polygon>;
19 using PointList = std::vector<glm::vec3>;
20
21 Polygon() = default;
22 Polygon(const PointList& initialPoints);
23 Polygon(const Polygon&) = default;
24
25 void setPoints(const PointList& pointList);
26 void addPoint(const glm::vec3& point);
27 void clearPoints();
28 void fixUp();
29
30 const PointList& getPoints() const { return points; }
31 const glm::vec3& getPoint(size_t idx) const { return points[idx]; }
32 size_t getNoOfPoints() const { return points.size(); }
33 float calcArea() const { return std::fabs(calcSignedArea(points.begin(), points.end())); }
34 bool isPointInside(const glm::vec3& p) const { return isPointInside(p, points); }
35
36 List add(const Polygon& polygon) const;
37 List subtract(const Polygon& polygon) const;
38
39 private:
40 PointList points;
41
42 static bool isClockwise(const PointList& pointList);
43 static bool isPointInside(const glm::vec3& p, const PointList& pointList);
44 static float calcSignedArea(const PointList::const_iterator& start, const PointList::const_iterator& end);
45 };
46 }
47}
Generic 2D concave or convex polygon.
Definition: Polygon.h:16
@ Geometry
Store entity vector fields (vector<vec3>, vector<vec2>, vector<int>, vector<float>).
Contains all Cogs related functionality.
Definition: FieldSetter.h:23