src/utilities/geometry/Polygon3d.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_GEOMETRY_POLYGON_HPP | ||
| 7 | #define UTILITIES_GEOMETRY_POLYGON_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | |||
| 11 | #include "Point3d.hpp" | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | namespace openstudio { | ||
| 15 | |||
| 16 | class Vector3d; | ||
| 17 | |||
| 18 | class UTILITIES_API Polygon3d | ||
| 19 | { | ||
| 20 | public: | ||
| 21 | // Constructs an empty polygon | ||
| 22 | 24 | Polygon3d() = default; | |
| 23 | |||
| 24 | // Construct a polygon with an outer path | ||
| 25 | Polygon3d(const Point3dVector& outerPath); | ||
| 26 | |||
| 27 | // Constructs a polygon with an outer path and one or more inner paths | ||
| 28 | Polygon3d(const Point3dVector& outerPath, const Point3dVectorVector& innerPaths); | ||
| 29 | |||
| 30 | // Copy and move operators are implicitly declared (Rule of 1), but we want the copy ctor for SWIG so we have to define all of them | ||
| 31 |
1/1✓ Branch 2 taken 257 times.
|
257 | Polygon3d(const Polygon3d& other) = default; |
| 32 | 782 | Polygon3d(Polygon3d&& other) noexcept = default; | |
| 33 | 199 | Polygon3d& operator=(const Polygon3d&) = default; | |
| 34 | 2 | Polygon3d& operator=(Polygon3d&&) noexcept = default; | |
| 35 | // ~Polygon3d() noexcept = default; | ||
| 36 | |||
| 37 | // Assigns an outer path for the polygon | ||
| 38 | void setOuterPath(const Point3dVector& outerPath); | ||
| 39 | |||
| 40 | // Returns the polygon's outer path | ||
| 41 | Point3dVector getOuterPath() const; | ||
| 42 | |||
| 43 | // Returns the polygon's inner paths | ||
| 44 | Point3dVectorVector getInnerPaths() const; | ||
| 45 | |||
| 46 | // Adds a point to the outer path of the polygon | ||
| 47 | void addPoint(const Point3d& point); | ||
| 48 | |||
| 49 | // Adds an inner path to the polygon | ||
| 50 | void addHole(const Point3dVector& hole); | ||
| 51 | |||
| 52 | // Calculates the Newell Vector for the polygon | ||
| 53 | Vector3d newellVector() const; | ||
| 54 | |||
| 55 | // Calculates the outward normal of the polygon | ||
| 56 | Vector3d outwardNormal() const; | ||
| 57 | |||
| 58 | // Calculates the gross area of the polygon (area excluding holes) | ||
| 59 | double grossArea() const; | ||
| 60 | |||
| 61 | // Calculates the net area of the polygon (gross area - area of holes) | ||
| 62 | double netArea() const; | ||
| 63 | |||
| 64 | // Gets the perimeter of the outer path of the polygon | ||
| 65 | double perimeter() const; | ||
| 66 | |||
| 67 | // Determines whether the polygon os clockwise (normal down) or anti-clockwise (normal up) | ||
| 68 | bool isClockwise() const; | ||
| 69 | |||
| 70 | // Calculates the centroid of the polygon | ||
| 71 | Point3d centroid() const; | ||
| 72 | |||
| 73 | // Point is on the outer path or one of the inner paths | ||
| 74 | bool pointInPolygon(const Point3d& point, double tol = 0.01) const; | ||
| 75 | |||
| 76 | // Point inside outer path and not inside a hole | ||
| 77 | bool within(const Point3d& point, double tol = 0.01) const; | ||
| 78 | |||
| 79 | // Point is inside the outer path and not inside a hole or on the outer path or one of the inner paths | ||
| 80 | bool inside(const Point3d& point, double tol = 0.01) const; | ||
| 81 | |||
| 82 | // gets the size of the outer path | ||
| 83 | size_t getSize() const; | ||
| 84 | |||
| 85 | // gets an edge on thge outer path | ||
| 86 | Point3dVector getEdge(size_t i) const; | ||
| 87 | |||
| 88 | // Returns the ovelapping segments between this polygon and the line | ||
| 89 | std::vector<Point3dVector> overlap(const Point3dVector& line) const; | ||
| 90 | |||
| 91 | private: | ||
| 92 | // The polygon's outer path | ||
| 93 | Point3dVector m_outerPath; | ||
| 94 | |||
| 95 | // The polygons inner paths | ||
| 96 | Point3dVectorVector m_innerPaths; | ||
| 97 | }; | ||
| 98 | } // namespace openstudio | ||
| 99 | |||
| 100 | #endif //UTILITIES_GEOMETRY_POLYGON_HPP | ||
| 101 |