|
ActiveLib
|
#include <Polygon.h>


Classes | |
| struct | Index |
Public Types | |
| using | base = container::Vector<PolyPoint> |
| Base storage class for Polygon. | |
| using | Unique = std::unique_ptr<Polygon> |
| Unique pointer. | |
| using | Shared = std::shared_ptr<Polygon> |
| Shared pointer. | |
| using | Option = std::optional<Polygon> |
| Optional. | |
Public Types inherited from active::container::Vector< PolyPoint > | |
| using | base |
| Base container type. | |
| using | value_type |
| Stored type. | |
| using | size_type |
| Container size (index) type. | |
| using | iterator |
| Container iterator type. | |
| using | const_iterator |
| Container const iterator type. | |
Public Member Functions | |
| Polygon (vertex_index size=defSize, part_index holeSize=0, bool isClosed=true) | |
| Polygon (const std::initializer_list< PolyPoint > &points, bool isClosed=true) | |
| Polygon (const Box &source, double angle=0.0) | |
| Polygon (const Polygon &source) | |
| Polygon (Polygon &&source) noexcept | |
| virtual | ~Polygon ()=default |
| virtual Polygon * | clonePtr () const |
| virtual Polygon * | movePtr () |
| virtual Polygon::Unique | cloneGeometry () const |
| virtual Polygon & | operator= (const Polygon &source) |
| virtual Polygon & | operator= (Polygon &&source) noexcept |
| PolyPoint * | operator[] (vertex_index index) |
| const PolyPoint * | operator[] (vertex_index index) const |
| Polygon | operator+ (const Point &offset) const |
| Polygon & | operator+= (const Point &offset) |
| Polygon | operator- (const Point &offset) const |
| Polygon & | operator-= (const Point &offset) |
| Polygon | operator* (const double &mult) const |
| Polygon & | operator*= (const double &mult) |
| Polygon | operator* (const Matrix3x3 &mult) const |
| Polygon & | operator*= (const Matrix3x3 &mult) |
| Polygon | operator* (const Matrix4x4 &mult) const |
| Polygon & | operator*= (const Matrix4x4 &mult) |
| Polygon | operator/ (const double &mult) const |
| Polygon & | operator/= (const double &mult) |
| virtual bool | isValid (bool doIntersect=false, double prec=math::eps) const |
| bool | isEqual2D (const Polygon &ref, double prec=math::eps) const |
| bool | isEqual3D (const Polygon &ref, double prec=math::eps) const |
| vertex_index | vertSize (bool isOuter=true) const |
| vertex_index | edgeSize () const |
| part_index | getHoleSize () const |
| vertex_id | getTopID () const |
| Polygon * | getHole (part_index which) const |
| PolyVector * | getHoles () const |
| std::optional< Rotation > | getDirection () const |
| Box::Option | bounds () const |
| double | getPerimeter2D () const |
| double | getPerimeter3D () const |
| vertex_index | tracePerimeter (double len, PolyPoint &endPos) const |
| double | getArea (bool isNet=true, bool isResultSigned=false) const |
| double | getInternalAngleAt (vertex_index index) const |
| bool | isTangentialAt (vertex_index vertex, double anglePrec=math::epsAngle) const |
| bool | isReflection (vertex_index index, const LinEquation &ref, double prec=math::eps) const |
| Point::Option | getInternalPoint () const |
| std::optional< Index > | findVertexById (vertex_id ID) const |
| std::optional< Index > | findVertexByLocation (const Point &pt, double prec=math::eps) const |
| const Polygon & | getShape (part_index index) const |
| Polygon & | getShape (part_index index) |
| base::iterator | iteratorAt (vertex_index index) |
| base::const_iterator | iteratorAt (vertex_index index) const |
| vertex_index | wrapIndex (vertex_index index) const |
| XPoint | closestPointAlong3D (const Point &ref, bool withHoles, double prec=math::eps) const |
| XPoint | closestPointAlong2D (const Point &ref, bool withHoles, double prec=math::eps) const |
| Position | positionOf (const Point &ref, double prec=math::eps) const |
| vertex_index | intersectionWith (const Line &ref, XList &inter, double prec=math::eps) const |
| vertex_index | intersectionWith (const Arc &ref, XList &inter, double prec=math::eps) const |
| vertex_index | intersectionWith (const PolyEdge &ref, XList &inter, double prec=math::eps) const |
| vertex_index | intersectionWith (const Polygon &ref, XList &inter, double prec=math::eps) const |
| void | splitWith (const LinEquation &ref, PolyVector *polyRight=nullptr, PolyVector *polyLeft=nullptr, double prec=math::eps) const |
| void | splitWith (const Polygon &ref, PolyVector *polyIn=nullptr, PolyVector *polyOut=nullptr, double prec=math::eps) const |
| part_index | resolveSelfIntersect (PolyVector &resolved, double prec=math::eps) const |
| bool | crosses (const Line &ref, double prec=math::eps) const |
| bool | encloses (const Point &ref, double prec=math::eps) const |
| bool | encloses (const Polygon &ref, double prec=math::eps) const |
| bool | overlaps (const Polygon &ref, double prec=math::eps) const |
| vertex_id | allocateID () |
| void | setTopID (vertex_id topId) |
| void | clear (bool allVertices=true, bool allHoles=true) |
| Polygon * | insertHole (const Polygon &hole) |
| Polygon * | insertHole (Polygon *hole=nullptr) |
| Polygon * | emplaceHole (Polygon::Unique &&hole) |
| Polygon * | emplaceHole (Polygon &&hole) |
| void | setHoles (std::unique_ptr< PolyVector > &&holes=nullptr) |
| void | setHoles (PolyVector &&hole) |
| void | removeHole (part_index which) |
| Polygon::Unique | releaseHole (part_index which) |
| vertex_id | addNodeAlong (vertex_id ID, const Point &pos, double prec=math::eps) |
| virtual bool | insertUniqueVertex (PolyPoint &&pt, vertOption where=std::nullopt) |
| std::unique_ptr< PolyVector > | releaseHoles () |
| virtual void | setDirection (Rotation direct=clockwise, bool withHoles=true, bool invertHoleDir=false) |
| virtual void | reverse () |
| bool | removeDuplicates2D (double prec=math::eps) |
| bool | removeDuplicates3D (double prec=math::eps) |
| void | optimise (bool doColin=false, double prec=math::eps) |
| void | renumber (bool restart=false) |
| void | facet () |
| void | setBaseLevel (double z=0) |
| void | alignTo (const Plane &plane) |
Public Member Functions inherited from active::container::Vector< PolyPoint > | |
| Vector (size_type toReserve=0) | |
| Vector (const std::initializer_list< Derived > &items) | |
| Vector (const Vector &source) | |
| Vector (Vector &&source) | |
| virtual | ~Vector ()=default |
| auto | operator= (const Vector &source) |
| auto | operator= (Vector &&source) |
| void | push_back (PolyPoint *item) |
| void | emplace_back (PolyPoint &&item) |
| void | emplace_back (const PolyPoint &item) |
| void | emplace_back (value_type &&item) |
| void | emplace_back (value_type &item) |
| auto | insert (const_iterator pos, PolyPoint *item) |
| auto | emplace (const_iterator pos, PolyPoint &&item) |
| auto | emplace (const_iterator pos, value_type &item) |
| auto | release (iterator &pos) |
| auto | release (const_iterator pos) |
Public Member Functions inherited from active::utility::Cloner | |
| virtual | ~Cloner ()=default |
Public Member Functions inherited from active::utility::Mover | |
| virtual | ~Mover ()=default |
Public Attributes | |
| bool | isHole = false |
| True if the polygon is a hole. | |
| bool | isClosed = true |
| True if the polygon is closed, i.e. an edge is assumed from the last vertex to the first. | |
Static Public Attributes | |
| static const vertex_index | defSize = 5 |
| The default number of vertices in a new polygon. | |
A class to represent a polygon (or open polyline)
NB: Refer to PolyPoint for an description of the vertex/edge class. A polygon/polyline is simply an array of PolyPoint objects (or objects serived from PolyPoint). Note that using an array of polymorphic objects (allocated on the heap) is intentional. Although not as fast as a contiguous allocation for the entire array, supporting a polymorphic vertex type supports additional metadata describing the edge leading to the edge (or the vertex itself in some cases). The base PolyPoint class only defines a sweep angle for the edge, but polygonal shapes often add more information, e.g. graphic attributes (colour/linetype/etc) or 3D properties (edge profile/visibility/etc). Maintaining parallel arrays or vertices and edges compounds the complexity of all functions that mutate the polygon shape. Any function processing or mutating polygon vertices can treat any polygon in the same way irrespective of the associated metadata. Although there is a slight speed penalty to this approach, the ease of managing polygon content outweighs it (and alernative may not ultimately prove to be faster).
A Polygon can be marked as open or closed - open simply means there is no edge connecting the first and last vertex, i.e. an open polyline. This modifies functions like edgeSize (counts the number of edges) which will be less than the number or vertices for open polylines. Closure should not be denoted by duplicating the first into the last (this is seen as a redundancy at best).
The Polygon array acts like a loop for indexing or subscripting into a specific vertex, e.g. the last vertex can be accessed like this:
auto lastVertex = polygon[-1];
Therefore it is impossible for the index to be out of range (unless the polygon is empty). This greatly simplifies algorithms that iterate through the edges - it is perfectly valid to write:
double len = 0.0;
for (auto vertex = edgeSize(); vertex--; )
len += (*this)[vertex + 1]->lengthFrom2D(*(*this)[vertex]);
…where vertex + 1 will exceed the array bounds and loop back to the first vertex (0).
| Polygon::Polygon | ( | vertex_index | size = defSize, |
| part_index | holeSize = 0, | ||
| bool | isClosed = true ) |
Constructor
| size | The number of vertices to reserve space for |
| holeSize | The number of holes to reserve space for |
| isClosed | Set to true if this polygon is closed |

|
inline |
Constructor
| points | The polygon vertices |
| isClosed | Set to true if this polygon is closed |
| Polygon::Polygon | ( | const Box & | source, |
| double | angle = 0.0 ) |
Constructor
| source | The box to base the construction of this polygon on |
| angle | The rotation angle of the box |

| Polygon::Polygon | ( | const Polygon & | source | ) |
Copy constructor
| source | The object to copy |
|
noexcept |
Move constructor
| source | The object to move |
|
virtualdefault |
Destructor
Introduce a new node along the specified polygon edge
| ID | The ID of the edge vertex to start searching from |
| pos | The coordinates of the new node |
| prec | The required precision |


| void Polygon::alignTo | ( | const Plane & | plane | ) |
Align the z coordinates of the polygon vertices to a specified plane
| plane | The plane to align the polygon to |

|
inline |
Allocate a new vertex ID

| Box::Option Polygon::bounds | ( | ) | const |
Get the polygon bounds


| void Polygon::clear | ( | bool | allVertices = true, |
| bool | allHoles = true ) |
Clear the specified polygon content
| allVertices | True to clear all vertices |
| allHoles | True to clear all holes |

|
virtual |
Clone method, copying just the raw geometry (all vertices will be reduced to PolyPoints)
|
inlinevirtual |
Clone method
Implements active::utility::Cloner.

| XPoint Polygon::closestPointAlong2D | ( | const Point & | ref, |
| bool | withHoles, | ||
| double | prec = math::eps ) const |
Get the closest point in the polygon to a given point in 2D
| ref | The reference point |
| prec | The required precision |


| XPoint Polygon::closestPointAlong3D | ( | const Point & | ref, |
| bool | withHoles, | ||
| double | prec = math::eps ) const |
Get the closest point in the polygon to a given point in 3D
| ref | The reference point |
| prec | The required precision |


Determine if this crosses a specified line (not just touching)
| ref | The reference line |
| prec | The required precision |

|
inline |
Get the number of edges in the polygon


Emplace a hole in the polygon
| hole | The hole to emplace |

| Polygon * Polygon::emplaceHole | ( | Polygon::Unique && | hole | ) |
Emplace a hole in the polygon
| hole | The hole to emplace |

Determine if the this encloses a specified point (closure assumed)
| ref | The reference point |
| prec | The required precision |


Determine if the this encloses a specified polygon (closure assumed)
| ref | The reference point |
| prec | The required precision |

| void Polygon::facet | ( | ) |
Facet the curved edges on the polygon

| std::optional< Polygon::Index > Polygon::findVertexById | ( | vertex_id | ID | ) | const |
Find a vertex with the specified ID (optionally searching holes)
| ID | The ID to search for |


| std::optional< Polygon::Index > Polygon::findVertexByLocation | ( | const Point & | pt, |
| double | prec = math::eps ) const |
Find a vertex at the specified point
| pt | The point to match |
| prec | The required precision |


| double Polygon::getArea | ( | bool | isNet = true, |
| bool | isResultSigned = false ) const |
Calculate the polygon area (closure assumed)
| isNet | True if the net area is calculated (less holes) |
| isResultSigned | True if the result should be signed (reflecting the polygon direction) |


| std::optional< Rotation > Polygon::getDirection | ( | ) | const |
Get the direction of the polygon


| Polygon * Polygon::getHole | ( | part_index | which | ) | const |
Get the requested hole
| which | The index of the polygon to get |

|
inline |
Get the list of holes in this polygon
| part_index Polygon::getHoleSize | ( | ) | const |
Get the number of holes in the polygon

| double Polygon::getInternalAngleAt | ( | vertex_index | index | ) | const |
Get the internal angle between the edges at the given index index The vertex index return The angle between the two edges

| Point::Option Polygon::getInternalPoint | ( | ) | const |
Get a point inside the polygon

| double Polygon::getPerimeter2D | ( | ) | const |
Calculate the polygon perimeter (non-closure handled)

| double Polygon::getPerimeter3D | ( | ) | const |
Calculate the polygon perimeter (non-closure handled)


| Polygon & Polygon::getShape | ( | part_index | index | ) |
Get one of the subpolygons of which this polygon consists
| index | The index of the shape |

| const Polygon & Polygon::getShape | ( | part_index | index | ) | const |
Get one of the subpolygons of which this polygon consists
| index | The index of the shape |


|
inline |
Get the highest vertex ID

Insert a hole in the polygon
| hole | The hole to insert |

Insert a hole in the polygon
| hole | The hole to insert (nullptr = create a new polygon) |

|
virtual |
Insert a new node to a polygon, testing that the vertex is unique
| pt | The new node to insert |
| where | The position to insert the new point (nullopt = at the end) |


| vertex_index Polygon::intersectionWith | ( | const Arc & | ref, |
| XList & | inter, | ||
| double | prec = math::eps ) const |
Get the intersection(s) between this polygon and an arc
| ref | The reference arc |
| inter | The intersection list to populate |
| prec | The required precision |

| vertex_index Polygon::intersectionWith | ( | const Line & | ref, |
| XList & | inter, | ||
| double | prec = math::eps ) const |
Get the intersection(s) between this polygon and a line
| ref | The reference line |
| inter | The intersection list to populate |
| prec | The required precision |


| vertex_index Polygon::intersectionWith | ( | const PolyEdge & | ref, |
| XList & | inter, | ||
| double | prec = math::eps ) const |
Get the intersection(s) between this polygon and a poly-edge
| ref | The reference poly-edge |
| inter | The intersection list to populate |
| prec | The required precision |

| vertex_index Polygon::intersectionWith | ( | const Polygon & | ref, |
| XList & | inter, | ||
| double | prec = math::eps ) const |
Get the intersection(s) between this polygon and another polygon
| ref | The reference polygon |
| inter | The intersection list to populate |
| prec | The required precision |

Determine if two polygons are equal in 2D
| ref | The polygon to compare |
| prec | The required precision |

Determine if two polygons are equal in 3D
| ref | The polygon to compare |
| prec | The required precision |

| bool Polygon::isReflection | ( | vertex_index | index, |
| const LinEquation & | ref, | ||
| double | prec = math::eps ) const |
Determine if the polygon reflects off a specified line at a specified vertex
| index | The index of the vertex to test |
| ref | The reference line |
| prec | The required precision |

| bool Polygon::isTangentialAt | ( | vertex_index | vertex, |
| double | anglePrec = math::epsAngle ) const |
Determine if the edges at a specified vertex are tangential
| vertex | The index of the vertex to check |
| anglePrec | The angle precision |

|
virtual |
Determine if the polygon is valid (must have 2 or more vertices)
| doIntersect | True if the polygon should be checked for intersecting edges (crossing each other) |
| prec | The required precision |


| Polygon::base::iterator Polygon::iteratorAt | ( | vertex_index | index | ) |
Get an iterator pointing to the specified vertex
| index | The vertex index (will be wrapped) |

| Polygon::base::const_iterator Polygon::iteratorAt | ( | vertex_index | index | ) | const |
Get an iterator pointing to the specified vertex
| index | The vertex index (will be wrapped) |

|
inlinevirtual |
Object cloning with move
Implements active::utility::Mover.

| Polygon Polygon::operator* | ( | const double & | mult | ) | const |
Multiplication operator
| mult | The amount to scale the polygon by |
Multiplication operator
| mult | The matrix to multiply the polygon by |
Multiplication operator
| mult | The matrix to multiply the polygon by |
| Polygon & Polygon::operator*= | ( | const double & | mult | ) |
Multiplication with assignment operator
| mult | The amount to scale the polygon by |

Multiplication with assignment operator
| mult | The matrix to multiply the polygon by |

Multiplication with assignment operator
| mult | The matrix to multiply the polygon by |

Addition operator
| offset | The amount to offset the polygon by |
Addition with assignment operator
| offset | The amount to offset the polygon by |

Subtraction operator
| offset | The amount to offset the polygon by |
Subtraction with assignment operator
| offset | The amount to offset the polygon by |

| Polygon Polygon::operator/ | ( | const double & | mult | ) | const |
Division operator
| mult | The amount to scale the polygon by |
| Polygon & Polygon::operator/= | ( | const double & | mult | ) |
Division with assignment operator
| mult | The amount to scale the polygon by |

Assignment operator
| source | The object to copy |

Assignment operator
| source | The object to move |

| PolyPoint * Polygon::operator[] | ( | vertex_index | index | ) |
Subscript operator
| index | An index into the polygon |

| const PolyPoint * Polygon::operator[] | ( | vertex_index | index | ) | const |
Subscript operator
| index | An index into the polygon |

| void Polygon::optimise | ( | bool | doColin = false, |
| double | prec = math::eps ) |
Optimise the polygon (eliminate duplicates, co-linear points) param doColin True if colinear points should be removed
| prec | The required precision |

Determine if the this overlaps a specified polygon (closure assumed)
| ref | The reference point |
| prec | The required precision |

Get the position of a point relative to the polygon (closure assumed)
| ref | The reference point |
| prec | The required precision |


| Polygon::Unique Polygon::releaseHole | ( | part_index | which | ) |
Release a hole from the polygon
| which | The index of the hole to release |
| PolyVector::Unique Polygon::releaseHoles | ( | ) |
Remove the polygon holes and release them to the caller
| bool Polygon::removeDuplicates2D | ( | double | prec = math::eps | ) |
Remove duplicate adjoining vertices in 2D
| prec | The required precision |

| bool Polygon::removeDuplicates3D | ( | double | prec = math::eps | ) |
Remove duplicate adjoining vertices in 3D
| prec | The required precision |

| void Polygon::removeHole | ( | part_index | which | ) |
Remove a hole from the polygon
| which | The index of the hole to remove |
| void Polygon::renumber | ( | bool | restart = false | ) |
Renumber the polygon vertices


| part_index Polygon::resolveSelfIntersect | ( | PolyVector & | resolved, |
| double | prec = math::eps ) const |
Resolve the polygon into a list of polygons with no self-intersection
| resolved | The list of resolved polygons |
| prec | The required precision |

|
virtual |
Reverse the polygon direction (clockwise/anticlockwise)


| void Polygon::setBaseLevel | ( | double | z = 0 | ) |
Set the level (z coordinate) of all the polygon vertices
| z | The required level |

|
virtual |
Redirect the order of the polygon in the specified direction
| direct | The direction of the polygon |
| withHoles | True to also set the direction of holes |
| invertHoleDir | True to set the opposite sense for the holes |


| void active::geometry::Polygon::setHoles | ( | PolyVector && | hole | ) |
Set the holes in the polygon
| hole | The list of holes to set in the polygon |
| void active::geometry::Polygon::setHoles | ( | std::unique_ptr< PolyVector > && | holes = nullptr | ) |
Set the holes in the polygon
| holes | The list of holes to set in the polygon (nullptr to erase all) |
|
inline |
Set the highest vertex ID
| topId | The highest vertex ID |
| void Polygon::splitWith | ( | const LinEquation & | ref, |
| PolyVector * | polyRight = nullptr, | ||
| PolyVector * | polyLeft = nullptr, | ||
| double | prec = math::eps ) const |
Calculate the polygons created by splitting this polygon along a line
| ref | The cutting line |
| polyRight | The split polygons to the right of the reference line (nullptr = discard) |
| polyLeft | The split polygons to the left of the reference line (nullptr = discard) |
| prec | The required precision |

| void Polygon::splitWith | ( | const Polygon & | ref, |
| PolyVector * | polyIn = nullptr, | ||
| PolyVector * | polyOut = nullptr, | ||
| double | prec = math::eps ) const |
Calculate the polygons created by splitting this polygon with another polygon
| ref | The cutting polygon |
| polyIn | The split polygons inside the reference polygon (nullptr = discard) |
| polyOut | The split polygons outside the reference polygon (nullptr = discard) |
| prec | The required precision |

| vertex_index Polygon::tracePerimeter | ( | double | len, |
| PolyPoint & | endPos ) const |
Trace the polygon perimeter for the specified length
| len | The length to length for |
| endPos | The point reached |

| vertex_index Polygon::vertSize | ( | bool | isOuter = true | ) | const |
Get the number of vertices in the polygon
| isOuter | True to count the outer polygon vertices only (exclude holes) |


| vertex_index Polygon::wrapIndex | ( | vertex_index | index | ) | const |
Wrap an index into the polygon range
| index | The index |

