Searching...
No Matches
PolygonTriangulation Class Reference

#include <polygon_triangulation.h>

struct  Vertex

## Public Member Functions

PolygonTriangulation (SHAPE_POLY_SET::TRIANGULATED_POLYGON &aResult)

bool TesselatePolygon (const SHAPE_LINE_CHAIN &aPoly)

## Private Member Functions

int32_t zOrder (const double aX, const double aY) const
Calculate the Morton code of the Vertex http://www.graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN. More...

VertexremoveNullTriangles (Vertex *aStart)
Iterate through the list to remove NULL triangles if they exist. More...

VertexcreateList (const ClipperLib::Path &aPath)
Take a Clipper path and converts it into a circular, doubly-linked list for triangulation. More...

VertexcreateList (const SHAPE_LINE_CHAIN &points)
Take a SHAPE_LINE_CHAIN and links each point into a circular, doubly-linked list. More...

bool earcutList (Vertex *aPoint, int pass=0)
Walk through a circular linked list starting at aPoint. More...

bool isEar (Vertex *aEar) const
Check whether the given vertex is in the middle of an ear. More...

void splitPolygon (Vertex *start)
If we cannot find an ear to slice in the current polygon list, we use this to split the polygon into two separate lists and slice them each independently. More...

bool goodSplit (const Vertex *a, const Vertex *b) const
Check if a segment joining two vertices lies fully inside the polygon. More...

double area (const Vertex *p, const Vertex *q, const Vertex *r) const
Return the twice the signed area of the triangle formed by vertices p, q, and r. More...

bool intersects (const Vertex *p1, const Vertex *q1, const Vertex *p2, const Vertex *q2) const
Check for intersection between two segments, end points included. More...

bool intersectsPolygon (const Vertex *a, const Vertex *b) const
Check whether the segment from vertex a -> vertex b crosses any of the segments of the polygon of which vertex a is a member. More...

bool locallyInside (const Vertex *a, const Vertex *b) const
Check whether the segment from vertex a -> vertex b is inside the polygon around the immediate area of vertex a. More...

VertexinsertVertex (const VECTOR2I &pt, Vertex *last)
Create an entry in the vertices lookup and optionally inserts the newly created vertex into an existing linked list. More...

## Private Attributes

BOX2I m_bbox

std::deque< Vertexm_vertices

SHAPE_POLY_SET::TRIANGULATED_POLYGONm_result

## Detailed Description

Definition at line 59 of file polygon_triangulation.h.

## ◆ PolygonTriangulation()

 PolygonTriangulation::PolygonTriangulation ( SHAPE_POLY_SET::TRIANGULATED_POLYGON & aResult )
inline

Definition at line 62 of file polygon_triangulation.h.

## ◆ area()

 double PolygonTriangulation::area ( const Vertex * p, const Vertex * q, const Vertex * r ) const
inlineprivate

Return the twice the signed area of the triangle formed by vertices p, q, and r.

Definition at line 609 of file polygon_triangulation.h.

References PolygonTriangulation::Vertex::x, and PolygonTriangulation::Vertex::y.

Referenced by earcutList(), intersects(), isEar(), locallyInside(), and removeNullTriangles().

## ◆ createList() [1/2]

 Vertex * PolygonTriangulation::createList ( const ClipperLib::Path & aPath )
inlineprivate

Take a Clipper path and converts it into a circular, doubly-linked list for triangulation.

Definition at line 330 of file polygon_triangulation.h.

Referenced by TesselatePolygon().

## ◆ createList() [2/2]

 Vertex * PolygonTriangulation::createList ( const SHAPE_LINE_CHAIN & points )
inlineprivate

Take a SHAPE_LINE_CHAIN and links each point into a circular, doubly-linked list.

Definition at line 371 of file polygon_triangulation.h.

## ◆ earcutList()

 bool PolygonTriangulation::earcutList ( Vertex * aPoint, int pass = 0 )
inlineprivate

Walk through a circular linked list starting at aPoint.

For each point, test to see if the adjacent points form a triangle that is completely enclosed by the remaining polygon (an "ear" sticking off the polygon). If the three points form an ear, we log the ear's location and remove the center point from the linked list.

This function can be called recursively in the case of difficult polygons. In cases where there is an intersection (not technically allowed by KiCad, but could exist in an edited file), we create a single triangle and remove both vertices before attempting to.

Definition at line 413 of file polygon_triangulation.h.

Referenced by splitPolygon(), and TesselatePolygon().

## ◆ goodSplit()

 bool PolygonTriangulation::goodSplit ( const Vertex * a, const Vertex * b ) const
inlineprivate

Check if a segment joining two vertices lies fully inside the polygon.

To do this, we first ensure that the line isn't along the polygon edge. Next, we know that if the line doesn't intersect the polygon, then it is either fully inside or fully outside the polygon. Finally, by checking whether the segment is enclosed by the local triangles, we distinguish between these two cases and no further checks are needed.

Definition at line 598 of file polygon_triangulation.h.

Referenced by splitPolygon().

## ◆ insertVertex()

 Vertex * PolygonTriangulation::insertVertex ( const VECTOR2I & pt, Vertex * last )
inlineprivate

Create an entry in the vertices lookup and optionally inserts the newly created vertex into an existing linked list.

Returns
a pointer to the newly created vertex.

Definition at line 675 of file polygon_triangulation.h.

Referenced by createList().

## ◆ intersects()

 bool PolygonTriangulation::intersects ( const Vertex * p1, const Vertex * q1, const Vertex * p2, const Vertex * q2 ) const
inlineprivate

Check for intersection between two segments, end points included.

Returns
true if p1-p2 intersects q1-q2.

Definition at line 619 of file polygon_triangulation.h.

References area().

Referenced by earcutList(), and intersectsPolygon().

## ◆ intersectsPolygon()

 bool PolygonTriangulation::intersectsPolygon ( const Vertex * a, const Vertex * b ) const
inlineprivate

Check whether the segment from vertex a -> vertex b crosses any of the segments of the polygon of which vertex a is a member.

Returns
true if the segment intersects the edge of the polygon.

Definition at line 634 of file polygon_triangulation.h.

Referenced by goodSplit().

## ◆ isEar()

 bool PolygonTriangulation::isEar ( Vertex * aEar ) const
inlineprivate

Check whether the given vertex is in the middle of an ear.

This works by walking forward and backward in zOrder to the limits of the minimal bounding box formed around the triangle, checking whether any points are located inside the given triangle.

Returns
true if aEar is the apex point of a ear in the polygon.

Definition at line 504 of file polygon_triangulation.h.

Referenced by earcutList().

## ◆ locallyInside()

 bool PolygonTriangulation::locallyInside ( const Vertex * a, const Vertex * b ) const
inlineprivate

Check whether the segment from vertex a -> vertex b is inside the polygon around the immediate area of vertex a.

We don't define the exact area over which the segment is inside but it is guaranteed to be inside the polygon immediately adjacent to vertex a.

Returns
true if the segment from a->b is inside a's polygon next to vertex a.

Definition at line 661 of file polygon_triangulation.h.

Referenced by earcutList(), and goodSplit().

## ◆ removeNullTriangles()

 Vertex * PolygonTriangulation::removeNullTriangles ( Vertex * aStart )
inlineprivate

Iterate through the list to remove NULL triangles if they exist.

This should only be called as a last resort when tesselation fails as the NULL triangles are inserted as Steiner points to improve the triangulation regularity of polygons

Definition at line 297 of file polygon_triangulation.h.

Referenced by earcutList().

## ◆ splitPolygon()

 void PolygonTriangulation::splitPolygon ( Vertex * start )
inlineprivate

If we cannot find an ear to slice in the current polygon list, we use this to split the polygon into two separate lists and slice them each independently.

This is assured to generate at least one new ear if the split is successful

Definition at line 560 of file polygon_triangulation.h.

Referenced by earcutList().

## ◆ TesselatePolygon()

 bool PolygonTriangulation::TesselatePolygon ( const SHAPE_LINE_CHAIN & aPoly )
inline

Place the polygon Vertices into a circular linked list and check for lists that have only 0, 1 or 2 elements and therefore cannot be polygons

Definition at line 66 of file polygon_triangulation.h.

Referenced by SHAPE_POLY_SET::CacheTriangulation().

## ◆ zOrder()

 int32_t PolygonTriangulation::zOrder ( const double aX, const double aY ) const
inlineprivate

## ◆ m_bbox

 BOX2I PolygonTriangulation::m_bbox
private

Definition at line 698 of file polygon_triangulation.h.

Referenced by TesselatePolygon(), and zOrder().

## ◆ m_result

 SHAPE_POLY_SET::TRIANGULATED_POLYGON& PolygonTriangulation::m_result
private

Definition at line 700 of file polygon_triangulation.h.

Referenced by earcutList(), insertVertex(), and TesselatePolygon().

## ◆ m_vertices

 std::deque PolygonTriangulation::m_vertices
private

The documentation for this class was generated from the following file: