KiCad PCB EDA Suite
SHAPE_POLY_SET Class Reference

Class SHAPE_POLY_SET. More...

#include <shape_poly_set.h>

Inheritance diagram for SHAPE_POLY_SET:
SHAPE

Classes

class  ITERATOR_TEMPLATE
 Class ITERATOR_TEMPLATE. More...
 
class  SEGMENT_ITERATOR_TEMPLATE
 Class SEGMENT_ITERATOR_TEMPLATE. More...
 
struct  TRIANGULATED_POLYGON
 
struct  VERTEX_INDEX
 Struct VERTEX_INDEX. More...
 

Public Types

enum  POLYGON_MODE { PM_FAST = true, PM_STRICTLY_SIMPLE = false }
 operations on polygons use a aFastMode param if aFastMode is PM_FAST (true) the result can be a weak polygon if aFastMode is PM_STRICTLY_SIMPLE (false) (default) the result is (theorically) a strictly simple polygon, but calculations can be really significantly time consuming Most of time PM_FAST is preferable. More...
 
typedef std::vector< SHAPE_LINE_CHAINPOLYGON
 

represents a single polygon outline with holes.

More...
 
typedef struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
 Struct VERTEX_INDEX. More...
 
typedef ITERATOR_TEMPLATE< VECTOR2IITERATOR
 
typedef ITERATOR_TEMPLATE< const VECTOR2ICONST_ITERATOR
 
typedef SEGMENT_ITERATOR_TEMPLATE< SEGSEGMENT_ITERATOR
 
typedef SEGMENT_ITERATOR_TEMPLATE< const SEGCONST_SEGMENT_ITERATOR
 

Public Member Functions

 SHAPE_POLY_SET ()
 
 SHAPE_POLY_SET (const SHAPE_POLY_SET &aOther)
 Copy constructor SHAPE_POLY_SET Performs a deep copy of aOther into this. More...
 
bool GetRelativeIndices (int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
 Function GetRelativeIndices. More...
 
bool GetGlobalIndex (VERTEX_INDEX aRelativeIndices, int &aGlobalIdx)
 Function GetGlobalIndex computes the global index of a vertex from the relative indices of polygon, contour and vertex. More...
 
SHAPEClone () const override
 Function Clone() More...
 
int NewOutline ()
 

Creates a new empty polygon in the set and returns its index

More...
 
int NewHole (int aOutline=-1)
 

Creates a new hole in a given outline

More...
 
int AddOutline (const SHAPE_LINE_CHAIN &aOutline)
 

Adds a new outline to the set and returns its index

More...
 
int AddHole (const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
 

Adds a new hole to the given outline (default: last) and returns its index

More...
 
int Append (int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
 

Appends a vertex at the end of the given outline/hole (default: the last outline)

More...
 
void Append (const SHAPE_POLY_SET &aSet)
 

Merges polygons from two sets.

More...
 
void Append (const VECTOR2I &aP, int aOutline=-1, int aHole=-1)
 

Appends a vertex at the end of the given outline/hole (default: the last outline)

More...
 
void InsertVertex (int aGlobalIndex, VECTOR2I aNewVertex)
 Function InsertVertex Adds a vertex in the globally indexed position aGlobalIndex. More...
 
VECTOR2IVertex (int aIndex, int aOutline, int aHole)
 

Returns the index-th vertex in a given hole outline within a given outline

More...
 
const VECTOR2ICVertex (int aIndex, int aOutline, int aHole) const
 

Returns the index-th vertex in a given hole outline within a given outline

More...
 
VECTOR2IVertex (int aGlobalIndex)
 

Returns the aGlobalIndex-th vertex in the poly set

More...
 
const VECTOR2ICVertex (int aGlobalIndex) const
 

Returns the aGlobalIndex-th vertex in the poly set

More...
 
VECTOR2IVertex (VERTEX_INDEX aIndex)
 

Returns the index-th vertex in a given hole outline within a given outline

More...
 
const VECTOR2ICVertex (VERTEX_INDEX aIndex) const
 

Returns the index-th vertex in a given hole outline within a given outline

More...
 
bool GetNeighbourIndexes (int aGlobalIndex, int *aPrevious, int *aNext)
 Returns the global indexes of the previous and the next corner of the aGlobalIndex-th corner of a contour in the polygon set. More...
 
bool IsPolygonSelfIntersecting (int aPolygonIndex)
 Function IsPolygonSelfIntersecting. More...
 
bool IsSelfIntersecting ()
 Function IsSelfIntersecting Checks whether any of the polygons in the set is self intersecting. More...
 
int OutlineCount () const
 

Returns the number of outlines in the set

More...
 
int VertexCount (int aOutline=-1, int aHole=-1) const
 

Returns the number of vertices in a given outline/hole

More...
 
int HoleCount (int aOutline) const
 

Returns the number of holes in a given outline

More...
 
SHAPE_LINE_CHAINOutline (int aIndex)
 

Returns the reference to aIndex-th outline in the set

More...
 
SHAPE_POLY_SET Subset (int aFirstPolygon, int aLastPolygon)
 Function Subset returns a subset of the polygons in this set, the ones between aFirstPolygon and aLastPolygon. More...
 
SHAPE_POLY_SET UnitSet (int aPolygonIndex)
 
SHAPE_LINE_CHAINHole (int aOutline, int aHole)
 

Returns the reference to aHole-th hole in the aIndex-th outline

More...
 
POLYGONPolygon (int aIndex)
 

Returns the aIndex-th subpolygon in the set

More...
 
const POLYGONPolygon (int aIndex) const
 
const TRIANGULATED_POLYGONTriangulatedPolygon (int aIndex) const
 
const SHAPE_LINE_CHAINCOutline (int aIndex) const
 
const SHAPE_LINE_CHAINCHole (int aOutline, int aHole) const
 
const POLYGONCPolygon (int aIndex) const
 
ITERATOR Iterate (int aFirst, int aLast, bool aIterateHoles=false)
 Function Iterate returns an object to iterate through the points of the polygons between aFirst and aLast. More...
 
ITERATOR Iterate (int aOutline)
 Function Iterate. More...
 
ITERATOR IterateWithHoles (int aOutline)
 Function IterateWithHoles. More...
 
ITERATOR Iterate ()
 Function Iterate. More...
 
ITERATOR IterateWithHoles ()
 Function IterateWithHoles. More...
 
CONST_ITERATOR CIterate (int aFirst, int aLast, bool aIterateHoles=false) const
 
CONST_ITERATOR CIterate (int aOutline) const
 
CONST_ITERATOR CIterateWithHoles (int aOutline) const
 
CONST_ITERATOR CIterate () const
 
CONST_ITERATOR CIterateWithHoles () const
 
ITERATOR IterateFromVertexWithHoles (int aGlobalIdx)
 
SEGMENT_ITERATOR IterateSegments (int aFirst, int aLast, bool aIterateHoles=false)
 

Returns an iterator object, for iterating between aFirst and aLast outline, with or

without holes (default: without) More...

 
SEGMENT_ITERATOR IterateSegments (int aPolygonIdx)
 

Returns an iterator object, for iterating aPolygonIdx-th polygon edges

More...
 
SEGMENT_ITERATOR IterateSegments ()
 

Returns an iterator object, for all outlines in the set (no holes)

More...
 
SEGMENT_ITERATOR IterateSegmentsWithHoles ()
 

Returns an iterator object, for all outlines in the set (with holes)

More...
 
SEGMENT_ITERATOR IterateSegmentsWithHoles (int aOutline)
 

Returns an iterator object, for the aOutline-th outline in the set (with holes)

More...
 
void BooleanAdd (const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
 

Performs boolean polyset union For aFastMode meaning, see function booleanOp

More...
 
void BooleanSubtract (const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
 

Performs boolean polyset difference For aFastMode meaning, see function booleanOp

More...
 
void BooleanIntersection (const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
 

Performs boolean polyset intersection For aFastMode meaning, see function booleanOp

More...
 
void BooleanAdd (const SHAPE_POLY_SET &a, const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
 

Performs boolean polyset union between a and b, store the result in it self For aFastMode meaning, see function booleanOp

More...
 
void BooleanSubtract (const SHAPE_POLY_SET &a, const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
 

Performs boolean polyset difference between a and b, store the result in it self For aFastMode meaning, see function booleanOp

More...
 
void BooleanIntersection (const SHAPE_POLY_SET &a, const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
 

Performs boolean polyset intersection between a and b, store the result in it self For aFastMode meaning, see function booleanOp

More...
 
void Inflate (int aFactor, int aCircleSegmentsCount)
 

Performs outline inflation/deflation, using round corners.

More...
 
void Fracture (POLYGON_MODE aFastMode)
 

Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the outer ring to the inner holes For aFastMode meaning, see function booleanOp

More...
 
void Unfracture (POLYGON_MODE aFastMode)
 

Converts a single outline slitted ("fractured") polygon into a set ouf outlines with holes.

More...
 
bool HasHoles () const
 

Returns true if the polygon set has any holes.

More...
 
void Simplify (POLYGON_MODE aFastMode)
 

Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMode meaning, see function booleanOp

More...
 
int NormalizeAreaOutlines ()
 Function NormalizeAreaOutlines Convert a self-intersecting polygon to one (or more) non self-intersecting polygon(s) Removes null segments. More...
 
const std::string Format () const override
 
bool Parse (std::stringstream &aStream) override
 
void Move (const VECTOR2I &aVector) override
 
bool IsSolid () const override
 
const BOX2I BBox (int aClearance=0) const override
 Function BBox() More...
 
bool PointOnEdge (const VECTOR2I &aP) const
 Function PointOnEdge() More...
 
bool Collide (const VECTOR2I &aP, int aClearance=0) const override
 Function Collide Checks whether the point aP collides with the inside of the polygon set; if the point lies on an edge or on a corner of any of the polygons, there is no collision: the edges does not belong to the polygon itself. More...
 
bool Collide (const SEG &aSeg, int aClearance=0) const override
 Function Collide() More...
 
bool CollideVertex (const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0)
 Function CollideVertex Checks whether aPoint collides with any vertex of any of the contours of the polygon. More...
 
bool CollideEdge (const VECTOR2I &aPoint, VERTEX_INDEX &aClosestVertex, int aClearance=0)
 Function CollideEdge Checks whether aPoint collides with any edge of any of the contours of the polygon. More...
 
bool Contains (const VECTOR2I &aP, int aSubpolyIndex=-1) const
 

Returns true if a given subpolygon contains the point aP.

More...
 
bool IsEmpty () const
 

Returns true if the set is empty (no polygons at all)

More...
 
void RemoveVertex (int aGlobalIndex)
 Function RemoveVertex deletes the aGlobalIndex-th vertex. More...
 
void RemoveVertex (VERTEX_INDEX aRelativeIndices)
 Function RemoveVertex deletes the vertex indexed by aIndex (index of polygon, contour and vertex). More...
 
void RemoveAllContours ()
 

Removes all outlines & holes (clears) the polygon set.

More...
 
void RemoveContour (int aContourIdx, int aPolygonIdx=-1)
 Function RemoveContour deletes the aContourIdx-th contour of the aPolygonIdx-th polygon in the set. More...
 
int RemoveNullSegments ()
 Function RemoveNullSegments looks for null segments; ie, segments whose ends are exactly the same and deletes them. More...
 
int TotalVertices () const
 

Returns total number of vertices stored in the set.

More...
 
void DeletePolygon (int aIdx)
 

Deletes aIdx-th polygon from the set

More...
 
POLYGON ChamferPolygon (unsigned int aDistance, int aIndex=0)
 Function Chamfer returns a chamfered version of the aIndex-th polygon. More...
 
POLYGON FilletPolygon (unsigned int aRadius, unsigned int aSegments, int aIndex=0)
 Function Fillet returns a filleted version of the aIndex-th polygon. More...
 
SHAPE_POLY_SET Chamfer (int aDistance)
 Function Chamfer returns a chamfered version of the polygon set. More...
 
SHAPE_POLY_SET Fillet (int aRadius, int aSegments)
 Function Fillet returns a filleted version of the polygon set. More...
 
int DistanceToPolygon (VECTOR2I aPoint, int aIndex)
 Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aPoint. More...
 
int DistanceToPolygon (SEG aSegment, int aIndex, int aSegmentWidth=0)
 Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aSegment with a possible width. More...
 
int Distance (VECTOR2I aPoint)
 Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the set. More...
 
int Distance (SEG aSegment, int aSegmentWidth=0)
 Function DistanceToPolygon computes the minimum distance between aSegment and all the polygons in the set. More...
 
bool IsVertexInHole (int aGlobalIdx)
 Function IsVertexInHole. More...
 
SHAPE_POLY_SEToperator= (const SHAPE_POLY_SET &)
 
void CacheTriangulation ()
 
bool IsTriangulationUpToDate () const
 
SHAPE_TYPE Type () const
 Function Type() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance, VECTOR2I &aMTV) const
 Function Collide() More...
 
virtual bool Collide (const SHAPE *aShape, int aClearance=0) const
 
virtual VECTOR2I Centre () const
 Function Centre() More...
 

Protected Types

typedef VECTOR2I::extended_type ecoord
 

Protected Attributes

SHAPE_TYPE m_type
 

type of our shape

More...
 

Private Types

enum  CORNER_MODE { CHAMFERED, FILLETED }
 Operations ChamferPolygon and FilletPolygon are computed under the private chamferFillet method; this enum is defined to make the necessary distinction when calling this method from the public ChamferPolygon and FilletPolygon methods. More...
 
typedef std::vector< POLYGONPOLYSET
 

Private Member Functions

SHAPE_LINE_CHAINgetContourForCorner (int aCornerId, int &aIndexWithinContour)
 
VECTOR2Ivertex (int aCornerId)
 
const VECTOR2Icvertex (int aCornerId) const
 
void fractureSingle (POLYGON &paths)
 
void unfractureSingle (POLYGON &path)
 
void importTree (ClipperLib::PolyTree *tree)
 
void booleanOp (ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
 Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ... More...
 
void booleanOp (ClipperLib::ClipType aType, const SHAPE_POLY_SET &aShape, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
 
bool pointInPolygon (const VECTOR2I &aP, const SHAPE_LINE_CHAIN &aPath) const
 
const ClipperLib::Path convertToClipper (const SHAPE_LINE_CHAIN &aPath, bool aRequiredOrientation)
 
const SHAPE_LINE_CHAIN convertFromClipper (const ClipperLib::Path &aPath)
 
bool containsSingle (const VECTOR2I &aP, int aSubpolyIndex) const
 containsSingle function Checks whether the point aP is inside the aSubpolyIndex-th polygon of the polyset. More...
 
POLYGON chamferFilletPolygon (CORNER_MODE aMode, unsigned int aDistance, int aIndex, int aSegments=-1)
 Function chamferFilletPolygon Returns the camfered or filleted version of the aIndex-th polygon in the set, depending on the aMode selected. More...
 
void triangulateSingle (const POLYGON &aPoly, SHAPE_POLY_SET::TRIANGULATED_POLYGON &aResult)
 
MD5_HASH checksum () const
 

Private Attributes

POLYSET m_polys
 
std::vector< std::unique_ptr< TRIANGULATED_POLYGON > > m_triangulatedPolys
 
bool m_triangulationValid = false
 
MD5_HASH m_hash
 

Detailed Description

Class SHAPE_POLY_SET.

Represents a set of closed polygons. Polygons may be nonconvex, self-intersecting and have holes. Provides boolean operations (using Clipper library as the backend).

Let us define the terms used on this class to clarify methods names and comments:

  • Polygon: each polygon in the set.
  • Outline: first polyline in each polygon; represents its outer contour.
  • Hole: second and following polylines in the polygon.
  • Contour: each polyline of each polygon in the set, whether or not it is an outline or a hole.
  • Vertex (or corner): each one of the points that define a contour.

TODO: add convex partitioning & spatial index

Definition at line 56 of file shape_poly_set.h.

Member Typedef Documentation

typedef VECTOR2I::extended_type SHAPE::ecoord
protectedinherited

Definition at line 60 of file shape.h.

represents a single polygon outline with holes.

The first entry is the outline,

the remaining (if any), are the holes

Definition at line 61 of file shape_poly_set.h.

typedef std::vector<POLYGON> SHAPE_POLY_SET::POLYSET
private

Definition at line 1116 of file shape_poly_set.h.

Struct VERTEX_INDEX.

Structure to hold the necessary information in order to index a vertex on a SHAPE_POLY_SET object: the polygon index, the contour index relative to the polygon and the vertex index relative the contour.

Member Enumeration Documentation

Operations ChamferPolygon and FilletPolygon are computed under the private chamferFillet method; this enum is defined to make the necessary distinction when calling this method from the public ChamferPolygon and FilletPolygon methods.

Enumerator
CHAMFERED 
FILLETED 

Definition at line 1091 of file shape_poly_set.h.

operations on polygons use a aFastMode param if aFastMode is PM_FAST (true) the result can be a weak polygon if aFastMode is PM_STRICTLY_SIMPLE (false) (default) the result is (theorically) a strictly simple polygon, but calculations can be really significantly time consuming Most of time PM_FAST is preferable.

PM_STRICTLY_SIMPLE can be used in critical cases (Gerber output for instance)

Enumerator
PM_FAST 
PM_STRICTLY_SIMPLE 

Definition at line 773 of file shape_poly_set.h.

Constructor & Destructor Documentation

SHAPE_POLY_SET::SHAPE_POLY_SET ( )

Definition at line 49 of file shape_poly_set.cpp.

Referenced by Clone(), and Collide().

49  :
51 {
52 }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
convex polygon
Definition: shape.h:48
SHAPE_POLY_SET::SHAPE_POLY_SET ( const SHAPE_POLY_SET aOther)

Copy constructor SHAPE_POLY_SET Performs a deep copy of aOther into this.

Parameters
aOtheris the SHAPE_POLY_SET object that will be copied.

Definition at line 55 of file shape_poly_set.cpp.

55  :
56  SHAPE( SH_POLY_SET ), m_polys( aOther.m_polys )
57 {
58 }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
convex polygon
Definition: shape.h:48

Member Function Documentation

int SHAPE_POLY_SET::AddHole ( const SHAPE_LINE_CHAIN aHole,
int  aOutline = -1 
)

Adds a new hole to the given outline (default: last) and returns its index

Definition at line 438 of file shape_poly_set.cpp.

References m_polys.

Referenced by ZONE_CONTAINER::AddPolygon(), and PCB_EDIT_FRAME::End_Zone().

439 {
440  assert( m_polys.size() );
441 
442  if( aOutline < 0 )
443  aOutline += m_polys.size();
444 
445  POLYGON& poly = m_polys[aOutline];
446 
447  assert( poly.size() );
448 
449  poly.push_back( aHole );
450 
451  return poly.size() - 1;
452 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
int SHAPE_POLY_SET::AddOutline ( const SHAPE_LINE_CHAIN aOutline)

Adds a new outline to the set and returns its index

Definition at line 424 of file shape_poly_set.cpp.

References SHAPE_LINE_CHAIN::IsClosed(), and m_polys.

Referenced by ZONE_CONTAINER::AddPolygon(), CINFO3D_VISU::AddShapeWithClearanceToContainer(), CINFO3D_VISU::buildPadShapePolygon(), Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), D_PAD::MergePrimitivesAsPolygon(), CPolyLine::NormalizeAreaOutlines(), and NormalizeAreaOutlines().

425 {
426  assert( aOutline.IsClosed() );
427 
428  POLYGON poly;
429 
430  poly.push_back( aOutline );
431 
432  m_polys.push_back( poly );
433 
434  return m_polys.size() - 1;
435 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
bool IsClosed() const
Function IsClosed()
int SHAPE_POLY_SET::Append ( int  x,
int  y,
int  aOutline = -1,
int  aHole = -1,
bool  aAllowDuplication = false 
)

Appends a vertex at the end of the given outline/hole (default: the last outline)

Function Append adds a new vertex to the contour indexed by aOutline and aHole (defaults to the outline of the last polygon).

Parameters
xis the x coordinate of the new vertex.
yis the y coordinate of the new vertex.
aOutlineis the index of the polygon.
aHoleis the index of the hole (-1 for the main outline),
aAllowDuplicationis a flag to indicate whether it is allowed to add this corner even if it is duplicated.
Returns
int - the number of corners of the selected contour after the addition.

Definition at line 178 of file shape_poly_set.cpp.

References m_polys.

Referenced by addHoleToPolygon(), Append(), ZONE_CONTAINER::AppendCorner(), BuildBoardPolygonOutlines(), D_PAD::buildCustomPadPolygon(), CINFO3D_VISU::buildPadShapePolygon(), D_PAD::BuildPadShapePolygon(), BuildUnconnectedThermalStubsPolygonList(), ZONE_FILLER::buildZoneFeatureHoleList(), DRC::checkClearancePadToPad(), DRC::checkClearanceSegmToPad(), ConvertOutlineToPolygon(), ConvertPolyListToPolySet(), GERBER_DRAW_ITEM::ConvertSegmentToPolygon(), D_CODE::ConvertShapeToPolygon(), CINFO3D_VISU::createNewPadWithClearance(), CreateThermalReliefPadPolygon(), DRC::doFootprintOverlappingDrc(), KIGFX::PCB_PAINTER::draw(), D_PAD::DrawShape(), GERBER_FILE_IMAGE::Execute_DCODE_Command(), GERBER_FILE_IMAGE::Execute_G_Command(), fillArcPOLY(), getRectangleAlongCentreLine(), InsertVertex(), LEGACY_PLUGIN::loadZONE_CONTAINER(), ZONE_CONTAINER::operator=(), PCB_PARSER::parseZONE_CONTAINER(), ZONE_CREATE_HELPER::performZoneCutout(), DXF_PLOTTER::PlotPoly(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), DRAWSEGMENT::SetPolyPoints(), PNS_KICAD_IFACE::syncPad(), TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(), TransformCircleToPolygon(), ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(), TransformRingToPolygon(), TransformRoundedEndsSegmentToPolygon(), TransformRoundRectToPolygon(), DRAWSEGMENT::TransformShapeWithClearanceToPolygon(), D_PAD::TransformShapeWithClearanceToPolygon(), ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet(), and ZONE_CONTAINER::ZONE_CONTAINER().

179 {
180  if( aOutline < 0 )
181  aOutline += m_polys.size();
182 
183  int idx;
184 
185  if( aHole < 0 )
186  idx = 0;
187  else
188  idx = aHole + 1;
189 
190  assert( aOutline < (int) m_polys.size() );
191  assert( idx < (int) m_polys[aOutline].size() );
192 
193  m_polys[aOutline][idx].Append( x, y, aAllowDuplication );
194 
195  return m_polys[aOutline][idx].PointCount();
196 }
void SHAPE_POLY_SET::Append ( const SHAPE_POLY_SET aSet)

Merges polygons from two sets.

Definition at line 1321 of file shape_poly_set.cpp.

References m_polys.

1322 {
1323  m_polys.insert( m_polys.end(), aSet.m_polys.begin(), aSet.m_polys.end() );
1324 }
void SHAPE_POLY_SET::Append ( const VECTOR2I aP,
int  aOutline = -1,
int  aHole = -1 
)

Appends a vertex at the end of the given outline/hole (default: the last outline)

Definition at line 1327 of file shape_poly_set.cpp.

References Append(), VECTOR2< T >::x, and VECTOR2< T >::y.

1328 {
1329  Append( aP.x, aP.y, aOutline, aHole );
1330 }
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...
const BOX2I SHAPE_POLY_SET::BBox ( int  aClearance = 0) const
overridevirtual

Function BBox()

Computes a bounding box of the shape, with a margin of aClearance a collision.

Parameters
aClearancehow much the bounding box is expanded wrs to the minimum enclosing rectangle for the shape.
Returns
the bounding box.

Implements SHAPE.

Definition at line 1196 of file shape_poly_set.cpp.

References BOX2< Vec >::Inflate(), m_polys, and BOX2< Vec >::Merge().

Referenced by BOARD::CombineAllAreasInNet(), Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), APERTURE_MACRO::GetApertureMacroShape(), D_PAD::GetBestAnchorPosition(), GERBER_DRAW_ITEM::GetBoundingBox(), BOARD::TestAreaIntersection(), KIGFX::PREVIEW::POLYGON_ITEM::ViewBBox(), and KIGFX::PREVIEW::CENTRELINE_RECT_ITEM::ViewBBox().

1197 {
1198  BOX2I bb;
1199 
1200  for( unsigned i = 0; i < m_polys.size(); i++ )
1201  {
1202  if( i == 0 )
1203  bb = m_polys[i][0].BBox();
1204  else
1205  bb.Merge( m_polys[i][0].BBox() );
1206  }
1207 
1208  bb.Inflate( aClearance );
1209  return bb;
1210 }
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect...
Definition: box2.h:350
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:266
const BOX2I BBox(int aClearance=0) const override
Function BBox()
void SHAPE_POLY_SET::BooleanAdd ( const SHAPE_POLY_SET b,
POLYGON_MODE  aFastMode 
)

Performs boolean polyset union For aFastMode meaning, see function booleanOp

Definition at line 544 of file shape_poly_set.cpp.

References booleanOp().

Referenced by D_PAD::buildCustomPadPolygon(), BOARD::CombineAreas(), DXF_PLOTTER::PlotPoly(), PlotSolderMaskLayer(), and C3D_RENDER_OGL_LEGACY::reload().

545 {
546  booleanOp( ctUnion, b, aFastMode );
547 }
void booleanOp(ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...
void SHAPE_POLY_SET::BooleanAdd ( const SHAPE_POLY_SET a,
const SHAPE_POLY_SET b,
POLYGON_MODE  aFastMode 
)

Performs boolean polyset union between a and b, store the result in it self For aFastMode meaning, see function booleanOp

Definition at line 562 of file shape_poly_set.cpp.

References booleanOp().

565 {
566  booleanOp( ctUnion, a, b, aFastMode );
567 }
void booleanOp(ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...
void SHAPE_POLY_SET::BooleanIntersection ( const SHAPE_POLY_SET b,
POLYGON_MODE  aFastMode 
)

Performs boolean polyset intersection For aFastMode meaning, see function booleanOp

Definition at line 556 of file shape_poly_set.cpp.

References booleanOp().

Referenced by Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), and DRC::doFootprintOverlappingDrc().

557 {
558  booleanOp( ctIntersection, b, aFastMode );
559 }
void booleanOp(ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...
void SHAPE_POLY_SET::BooleanIntersection ( const SHAPE_POLY_SET a,
const SHAPE_POLY_SET b,
POLYGON_MODE  aFastMode 
)

Performs boolean polyset intersection between a and b, store the result in it self For aFastMode meaning, see function booleanOp

Definition at line 578 of file shape_poly_set.cpp.

References booleanOp().

581 {
582  booleanOp( ctIntersection, a, b, aFastMode );
583 }
void booleanOp(ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...
void SHAPE_POLY_SET::booleanOp ( ClipperLib::ClipType  aType,
const SHAPE_POLY_SET aOtherShape,
POLYGON_MODE  aFastMode 
)
private

Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...

and polygon simplification (merging overlaping polygons)

Parameters
aTypeis the transform type ( see ClipperLib::ClipType )
aOtherShapeis the SHAPE_LINE_CHAIN to combine with me.
aFastModeis an option to choose if the result can be a weak polygon or a stricty simple polygon. if aFastMode is PM_FAST the result can be a weak polygon if aFastMode is PM_STRICTLY_SIMPLE (default) the result is (theorically) a strictly simple polygon, but calculations can be really significantly time consuming

Definition at line 486 of file shape_poly_set.cpp.

References convertToClipper(), importTree(), m_polys, and PM_STRICTLY_SIMPLE.

Referenced by BooleanAdd(), BooleanIntersection(), BooleanSubtract(), and Simplify().

488 {
489  Clipper c;
490 
491  if( aFastMode == PM_STRICTLY_SIMPLE )
492  c.StrictlySimple( true );
493 
494  for( const POLYGON& poly : m_polys )
495  {
496  for( unsigned int i = 0; i < poly.size(); i++ )
497  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptSubject, true );
498  }
499 
500  for( const POLYGON& poly : aOtherShape.m_polys )
501  {
502  for( unsigned int i = 0; i < poly.size(); i++ )
503  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptClip, true );
504  }
505 
506  PolyTree solution;
507 
508  c.Execute( aType, solution, pftNonZero, pftNonZero );
509 
510  importTree( &solution );
511 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
const ClipperLib::Path convertToClipper(const SHAPE_LINE_CHAIN &aPath, bool aRequiredOrientation)
void importTree(ClipperLib::PolyTree *tree)
void SHAPE_POLY_SET::booleanOp ( ClipperLib::ClipType  aType,
const SHAPE_POLY_SET aShape,
const SHAPE_POLY_SET aOtherShape,
POLYGON_MODE  aFastMode 
)
private

Definition at line 514 of file shape_poly_set.cpp.

References convertToClipper(), importTree(), m_polys, and PM_STRICTLY_SIMPLE.

518 {
519  Clipper c;
520 
521  if( aFastMode == PM_STRICTLY_SIMPLE )
522  c.StrictlySimple( true );
523 
524  for( const POLYGON& poly : aShape.m_polys )
525  {
526  for( unsigned int i = 0; i < poly.size(); i++ )
527  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptSubject, true );
528  }
529 
530  for( const POLYGON& poly : aOtherShape.m_polys )
531  {
532  for( unsigned int i = 0; i < poly.size(); i++ )
533  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptClip, true );
534  }
535 
536  PolyTree solution;
537 
538  c.Execute( aType, solution, pftNonZero, pftNonZero );
539 
540  importTree( &solution );
541 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
const ClipperLib::Path convertToClipper(const SHAPE_LINE_CHAIN &aPath, bool aRequiredOrientation)
void importTree(ClipperLib::PolyTree *tree)
void SHAPE_POLY_SET::BooleanSubtract ( const SHAPE_POLY_SET b,
POLYGON_MODE  aFastMode 
)

Performs boolean polyset difference For aFastMode meaning, see function booleanOp

Definition at line 550 of file shape_poly_set.cpp.

References booleanOp().

Referenced by addHoleToPolygon(), ZONE_FILLER::computeRawFilledAreas(), CreateThermalReliefPadPolygon(), C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads(), APERTURE_MACRO::GetApertureMacroShape(), CPolyLine::NormalizeAreaOutlines(), and NormalizeAreaOutlines().

551 {
552  booleanOp( ctDifference, b, aFastMode );
553 }
void booleanOp(ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...
void SHAPE_POLY_SET::BooleanSubtract ( const SHAPE_POLY_SET a,
const SHAPE_POLY_SET b,
POLYGON_MODE  aFastMode 
)

Performs boolean polyset difference between a and b, store the result in it self For aFastMode meaning, see function booleanOp

Definition at line 570 of file shape_poly_set.cpp.

References booleanOp().

573 {
574  booleanOp( ctDifference, a, b, aFastMode );
575 }
void booleanOp(ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...
void SHAPE_POLY_SET::CacheTriangulation ( )

Definition at line 2000 of file shape_poly_set.cpp.

References checksum(), MD5_HASH::IsValid(), m_hash, m_triangulatedPolys, m_triangulationValid, OutlineCount(), PM_FAST, Polygon(), triangulateSingle(), and Unfracture().

Referenced by ZONE_CONTAINER::CacheTriangulation().

2001 {
2002  bool recalculate = !m_hash.IsValid();
2003  MD5_HASH hash;
2004 
2005  if( !m_triangulationValid )
2006  recalculate = true;
2007 
2008  if( !recalculate )
2009  {
2010  hash = checksum();
2011 
2012  if( m_hash != hash )
2013  {
2014  m_hash = hash;
2015  recalculate = true;
2016  }
2017  }
2018 
2019  if( !recalculate )
2020  return;
2021 
2022  SHAPE_POLY_SET tmpSet = *this;
2023  tmpSet.Unfracture( PM_FAST );
2024 
2025  m_triangulatedPolys.clear();
2026 
2027  for( int i = 0; i < tmpSet.OutlineCount(); i++ )
2028  {
2029  m_triangulatedPolys.push_back( std::make_unique<TRIANGULATED_POLYGON>() );
2030  triangulateSingle( tmpSet.Polygon( i ), *m_triangulatedPolys.back() );
2031  }
2032 
2033  m_triangulationValid = true;
2034  m_hash = checksum();
2035 }
MD5_HASH checksum() const
int OutlineCount() const
Returns the number of outlines in the set
std::vector< std::unique_ptr< TRIANGULATED_POLYGON > > m_triangulatedPolys
Class SHAPE_POLY_SET.
void triangulateSingle(const POLYGON &aPoly, SHAPE_POLY_SET::TRIANGULATED_POLYGON &aResult)
bool IsValid() const
Definition: md5_hash.h:23
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
void Unfracture(POLYGON_MODE aFastMode)
Converts a single outline slitted ("fractured") polygon into a set ouf outlines with holes...
virtual VECTOR2I SHAPE::Centre ( ) const
inlinevirtualinherited

Function Centre()

Computes a center-of-mass of the shape

Returns
the center-of-mass point

Definition at line 150 of file shape.h.

References SHAPE::BBox(), and BOX2< Vec >::Centre().

151  {
152  return BBox( 0 ).Centre(); // if nothing better is available....
153  }
virtual const BOX2I BBox(int aClearance=0) const =0
Function BBox()
Vec Centre() const
Definition: box2.h:67
SHAPE_POLY_SET SHAPE_POLY_SET::Chamfer ( int  aDistance)

Function Chamfer returns a chamfered version of the polygon set.

Parameters
aDistanceis the chamfering distance.
Returns
SHAPE_POLY_SET - A set containing the chamfered version of this set.

Definition at line 1679 of file shape_poly_set.cpp.

References ChamferPolygon(), and m_polys.

Referenced by ZONE_CONTAINER::BuildSmoothedPoly().

1680 {
1681  SHAPE_POLY_SET chamfered;
1682 
1683  for( unsigned int polygonIdx = 0; polygonIdx < m_polys.size(); polygonIdx++ )
1684  chamfered.m_polys.push_back( ChamferPolygon( aDistance, polygonIdx ) );
1685 
1686  return chamfered;
1687 }
POLYGON ChamferPolygon(unsigned int aDistance, int aIndex=0)
Function Chamfer returns a chamfered version of the aIndex-th polygon.
Class SHAPE_POLY_SET.
SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon ( CORNER_MODE  aMode,
unsigned int  aDistance,
int  aIndex,
int  aSegments = -1 
)
private

Function chamferFilletPolygon Returns the camfered or filleted version of the aIndex-th polygon in the set, depending on the aMode selected.

Parameters
aModerepresent which action will be taken: CORNER_MODE::CHAMFERED will return a chamfered version of the polygon, CORNER_MODE::FILLETED will return a filleted version of the polygon.
aDistanceis the chamfering distance if aMode = CHAMFERED; if aMode = FILLETED, is the filleting radius.
aIndexis the index of the polygon that will be chamfered/filleted.
aSegmentsis the number of filleting segments if aMode = FILLETED. If aMode = CHAMFERED, it is unused.
Returns
POLYGON - the chamfered/filleted version of the polygon.

Definition at line 1701 of file shape_poly_set.cpp.

References SHAPE_LINE_CHAIN::Append(), KiROUND(), SHAPE_LINE_CHAIN::Point(), Polygon(), RemoveNullSegments(), SHAPE_LINE_CHAIN::SetClosed(), and VECTOR2< T >::x.

Referenced by ChamferPolygon(), and FilletPolygon().

1705 {
1706  // Null segments create serious issues in calculations. Remove them:
1708 
1709  SHAPE_POLY_SET::POLYGON currentPoly = Polygon( aIndex );
1710  SHAPE_POLY_SET::POLYGON newPoly;
1711 
1712  // If the chamfering distance is zero, then the polygon remain intact.
1713  if( aDistance == 0 )
1714  {
1715  return currentPoly;
1716  }
1717 
1718  // Iterate through all the contours (outline and holes) of the polygon.
1719  for( SHAPE_LINE_CHAIN& currContour : currentPoly )
1720  {
1721  // Generate a new contour in the new polygon
1722  SHAPE_LINE_CHAIN newContour;
1723 
1724  // Iterate through the vertices of the contour
1725  for( int currVertex = 0; currVertex < currContour.PointCount(); currVertex++ )
1726  {
1727  // Current vertex
1728  int x1 = currContour.Point( currVertex ).x;
1729  int y1 = currContour.Point( currVertex ).y;
1730 
1731  // Indices for previous and next vertices.
1732  int prevVertex;
1733  int nextVertex;
1734 
1735  // Previous and next vertices indices computation. Necessary to manage the edge cases.
1736 
1737  // Previous vertex is the last one if the current vertex is the first one
1738  prevVertex = currVertex == 0 ? currContour.PointCount() - 1 : currVertex - 1;
1739 
1740  // next vertex is the first one if the current vertex is the last one.
1741  nextVertex = currVertex == currContour.PointCount() - 1 ? 0 : currVertex + 1;
1742 
1743  // Previous vertex computation
1744  double xa = currContour.Point( prevVertex ).x - x1;
1745  double ya = currContour.Point( prevVertex ).y - y1;
1746 
1747  // Next vertex computation
1748  double xb = currContour.Point( nextVertex ).x - x1;
1749  double yb = currContour.Point( nextVertex ).y - y1;
1750 
1751  // Compute the new distances
1752  double lena = hypot( xa, ya );
1753  double lenb = hypot( xb, yb );
1754 
1755  // Make the final computations depending on the mode selected, chamfered or filleted.
1756  if( aMode == CORNER_MODE::CHAMFERED )
1757  {
1758  double distance = aDistance;
1759 
1760  // Chamfer one half of an edge at most
1761  if( 0.5 * lena < distance )
1762  distance = 0.5 * lena;
1763 
1764  if( 0.5 * lenb < distance )
1765  distance = 0.5 * lenb;
1766 
1767  int nx1 = KiROUND( distance * xa / lena );
1768  int ny1 = KiROUND( distance * ya / lena );
1769 
1770  newContour.Append( x1 + nx1, y1 + ny1 );
1771 
1772  int nx2 = KiROUND( distance * xb / lenb );
1773  int ny2 = KiROUND( distance * yb / lenb );
1774 
1775  newContour.Append( x1 + nx2, y1 + ny2 );
1776  }
1777  else // CORNER_MODE = FILLETED
1778  {
1779  double cosine = ( xa * xb + ya * yb ) / ( lena * lenb );
1780 
1781  double radius = aDistance;
1782  double denom = sqrt( 2.0 / ( 1 + cosine ) - 1 );
1783 
1784  // Do nothing in case of parallel edges
1785  if( std::isinf( denom ) )
1786  continue;
1787 
1788  // Limit rounding distance to one half of an edge
1789  if( 0.5 * lena * denom < radius )
1790  radius = 0.5 * lena * denom;
1791 
1792  if( 0.5 * lenb * denom < radius )
1793  radius = 0.5 * lenb * denom;
1794 
1795  // Calculate fillet arc absolute center point (xc, yx)
1796  double k = radius / sqrt( .5 * ( 1 - cosine ) );
1797  double lenab = sqrt( ( xa / lena + xb / lenb ) * ( xa / lena + xb / lenb ) +
1798  ( ya / lena + yb / lenb ) * ( ya / lena + yb / lenb ) );
1799  double xc = x1 + k * ( xa / lena + xb / lenb ) / lenab;
1800  double yc = y1 + k * ( ya / lena + yb / lenb ) / lenab;
1801 
1802  // Calculate arc start and end vectors
1803  k = radius / sqrt( 2 / ( 1 + cosine ) - 1 );
1804  double xs = x1 + k * xa / lena - xc;
1805  double ys = y1 + k * ya / lena - yc;
1806  double xe = x1 + k * xb / lenb - xc;
1807  double ye = y1 + k * yb / lenb - yc;
1808 
1809  // Cosine of arc angle
1810  double argument = ( xs * xe + ys * ye ) / ( radius * radius );
1811 
1812  // Make sure the argument is in [-1,1], interval in which the acos function is
1813  // defined
1814  if( argument < -1 )
1815  argument = -1;
1816  else if( argument > 1 )
1817  argument = 1;
1818 
1819  double arcAngle = acos( argument );
1820 
1821  // Calculate the number of segments
1822  unsigned int segments = ceil( (double) aSegments * ( arcAngle / ( 2 * M_PI ) ) );
1823 
1824  double deltaAngle = arcAngle / segments;
1825  double startAngle = atan2( -ys, xs );
1826 
1827  // Flip arc for inner corners
1828  if( xa * yb - ya * xb <= 0 )
1829  deltaAngle *= -1;
1830 
1831  double nx = xc + xs;
1832  double ny = yc + ys;
1833 
1834  newContour.Append( KiROUND( nx ), KiROUND( ny ) );
1835 
1836  // Store the previous added corner to make a sanity check
1837  int prevX = KiROUND( nx );
1838  int prevY = KiROUND( ny );
1839 
1840  for( unsigned int j = 0; j < segments; j++ )
1841  {
1842  nx = xc + cos( startAngle + (j + 1) * deltaAngle ) * radius;
1843  ny = yc - sin( startAngle + (j + 1) * deltaAngle ) * radius;
1844 
1845  // Sanity check: the rounding can produce repeated corners; do not add them.
1846  if( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY )
1847  {
1848  newContour.Append( KiROUND( nx ), KiROUND( ny ) );
1849  prevX = KiROUND( nx );
1850  prevY = KiROUND( ny );
1851  }
1852  }
1853  }
1854  }
1855 
1856  // Close the current contour and add it the new polygon
1857  newContour.SetClosed( true );
1858  newPoly.push_back( newContour );
1859  }
1860 
1861  return newPoly;
1862 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetClosed(bool aClosed)
Function SetClosed()
int RemoveNullSegments()
Function RemoveNullSegments looks for null segments; ie, segments whose ends are exactly the same and...
Class SHAPE_LINE_CHAIN.
VECTOR2I & Point(int aIndex)
Function Point()
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::ChamferPolygon ( unsigned int  aDistance,
int  aIndex = 0 
)

Function Chamfer returns a chamfered version of the aIndex-th polygon.

Parameters
aDistanceis the chamfering distance.
aIndexis the index of the polygon to be chamfered.
Returns
POLYGON - A polygon containing the chamfered version of the aIndex-th polygon.

Definition at line 1555 of file shape_poly_set.cpp.

References chamferFilletPolygon().

Referenced by Chamfer().

1556 {
1557  return chamferFilletPolygon( CORNER_MODE::CHAMFERED, aDistance, aIndex );
1558 }
POLYGON chamferFilletPolygon(CORNER_MODE aMode, unsigned int aDistance, int aIndex, int aSegments=-1)
Function chamferFilletPolygon Returns the camfered or filleted version of the aIndex-th polygon in th...
MD5_HASH SHAPE_POLY_SET::checksum ( ) const
private

Definition at line 2038 of file shape_poly_set.cpp.

References MD5_HASH::Finalize(), MD5_HASH::Hash(), and m_polys.

Referenced by CacheTriangulation(), and IsTriangulationUpToDate().

2039 {
2040  MD5_HASH hash;
2041 
2042  hash.Hash( m_polys.size() );
2043 
2044  for( const auto& outline : m_polys )
2045  {
2046  hash.Hash( outline.size() );
2047 
2048  for( const auto& lc : outline )
2049  {
2050  hash.Hash( lc.PointCount() );
2051 
2052  for( int i = 0; i < lc.PointCount(); i++ )
2053  {
2054  hash.Hash( lc.CPoint( i ).x );
2055  hash.Hash( lc.CPoint( i ).y );
2056  }
2057  }
2058  }
2059 
2060  hash.Finalize();
2061 
2062  return hash;
2063 }
void Hash(uint8_t *data, uint32_t length)
Definition: md5_hash.cpp:66
void Finalize()
Definition: md5_hash.cpp:76
const SHAPE_LINE_CHAIN& SHAPE_POLY_SET::CHole ( int  aOutline,
int  aHole 
) const
inline
CONST_ITERATOR SHAPE_POLY_SET::CIterate ( int  aFirst,
int  aLast,
bool  aIterateHoles = false 
) const
inline

Definition at line 673 of file shape_poly_set.h.

References SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentContour, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentPolygon, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentVertex, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_iterateHoles, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_lastPolygon, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_poly, and OutlineCount().

Referenced by D_PAD::AddPrimitive(), EDGE_MODULE::Draw(), PCB_IO::format(), DRAWSEGMENT::GetBoundingBox(), DRAWSEGMENT::GetPolyPoints(), and BRDITEMS_PLOTTER::PlotFilledAreas().

674  {
675  CONST_ITERATOR iter;
676 
677  iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
678  iter.m_currentPolygon = aFirst;
679  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
680  iter.m_currentContour = 0;
681  iter.m_currentVertex = 0;
682  iter.m_iterateHoles = aIterateHoles;
683 
684  return iter;
685  }
int OutlineCount() const
Returns the number of outlines in the set
Class SHAPE_POLY_SET.
ITERATOR_TEMPLATE< const VECTOR2I > CONST_ITERATOR
CONST_ITERATOR SHAPE_POLY_SET::CIterate ( int  aOutline) const
inline

Definition at line 687 of file shape_poly_set.h.

References CIterate().

688  {
689  return CIterate( aOutline, aOutline );
690  }
CONST_ITERATOR CIterate() const
CONST_ITERATOR SHAPE_POLY_SET::CIterate ( ) const
inline

Definition at line 697 of file shape_poly_set.h.

References OutlineCount().

Referenced by CIterate(), and CIterateWithHoles().

698  {
699  return CIterate( 0, OutlineCount() - 1 );
700  }
CONST_ITERATOR CIterate() const
int OutlineCount() const
Returns the number of outlines in the set
CONST_ITERATOR SHAPE_POLY_SET::CIterateWithHoles ( int  aOutline) const
inline

Definition at line 692 of file shape_poly_set.h.

References CIterate().

Referenced by EDIT_POINTS_FACTORY::buildForPolyOutline(), ZONE_CONTAINER::CIterateWithHoles(), and GRID_HELPER::computeAnchors().

693  {
694  return CIterate( aOutline, aOutline, true );
695  }
CONST_ITERATOR CIterate() const
CONST_ITERATOR SHAPE_POLY_SET::CIterateWithHoles ( ) const
inline

Definition at line 702 of file shape_poly_set.h.

References CIterate(), and OutlineCount().

703  {
704  return CIterate( 0, OutlineCount() - 1, true );
705  }
CONST_ITERATOR CIterate() const
int OutlineCount() const
Returns the number of outlines in the set
SHAPE * SHAPE_POLY_SET::Clone ( ) const
overridevirtual

Function Clone()

Returns a dynamically allocated copy of the shape

Return values
copyof the shape

Reimplemented from SHAPE.

Definition at line 60 of file shape_poly_set.cpp.

References SHAPE_POLY_SET().

61 {
62  return new SHAPE_POLY_SET( *this );
63 }
bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance,
VECTOR2I aMTV 
) const
virtualinherited

Function Collide()

Checks if the boundary of shape (this) lies closer to the shape aShape than aClearance, indicating a collision.

Parameters
aShapeshape to check collision against
aClearanceminimum clearance
aMTVminimum translation vector
Returns
true, if there is a collision.

Definition at line 456 of file shape_collisions.cpp.

References CollideShapes().

457 {
458  return CollideShapes( this, aShape, aClerance, true, aMTV );
459 }
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
bool SHAPE::Collide ( const SHAPE aShape,
int  aClearance = 0 
) const
virtualinherited

Definition at line 462 of file shape_collisions.cpp.

References CollideShapes(), and dummy().

463 {
464  VECTOR2I dummy;
465 
466  return CollideShapes( this, aShape, aClerance, false, dummy );
467 }
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
bool CollideShapes(const SHAPE *aA, const SHAPE *aB, int aClearance, bool aNeedMTV, VECTOR2I &aMTV)
bool SHAPE_POLY_SET::Collide ( const VECTOR2I aP,
int  aClearance = 0 
) const
overridevirtual

Function Collide Checks whether the point aP collides with the inside of the polygon set; if the point lies on an edge or on a corner of any of the polygons, there is no collision: the edges does not belong to the polygon itself.

Parameters
aPis the VECTOR2I point whose collision with respect to the poly set will be tested.
aClearanceis the security distance; if the point lies closer to the polygon than aClearance distance, then there is a collision.
Returns
bool - true if the point aP collides with the polygon; false in any other case.

Reimplemented from SHAPE.

Definition at line 1230 of file shape_poly_set.cpp.

References Contains(), Inflate(), and SHAPE_POLY_SET().

1231 {
1232  SHAPE_POLY_SET polySet = SHAPE_POLY_SET( *this );
1233 
1234  // Inflate the polygon if necessary.
1235  if( aClearance > 0 )
1236  {
1237  // fixme: the number of arc segments should not be hardcoded
1238  polySet.Inflate( aClearance, 8 );
1239  }
1240 
1241  // There is a collision if and only if the point is inside of the polygon.
1242  return polySet.Contains( aP );
1243 }
void Inflate(int aFactor, int aCircleSegmentsCount)
Performs outline inflation/deflation, using round corners.
Class SHAPE_POLY_SET.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1) const
Returns true if a given subpolygon contains the point aP.
bool SHAPE_POLY_SET::Collide ( const SEG aSeg,
int  aClearance = 0 
) const
inlineoverridevirtual

Function Collide()

Checks if the boundary of shape (this) lies closer to the segment aSeg than aClearance, indicating a collision.

Returns
true, if there is a collision.

Implements SHAPE.

Definition at line 874 of file shape_poly_set.h.

874 { return false; }
bool SHAPE_POLY_SET::CollideEdge ( const VECTOR2I aPoint,
SHAPE_POLY_SET::VERTEX_INDEX aClosestVertex,
int  aClearance = 0 
)

Function CollideEdge Checks whether aPoint collides with any edge of any of the contours of the polygon.

Parameters
aPointis the VECTOR2I point whose collision with respect to the polygon will be tested.
aClearanceis the security distance; if aPoint lies closer to a vertex than aClearance distance, then there is a collision.
aClosestVertexis the index of the closes vertex to aPoint.
Returns
bool - true if there is a collision, false in any other case.

Definition at line 1371 of file shape_poly_set.cpp.

References SEG::Distance(), SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::GetIndex(), and IterateSegmentsWithHoles().

Referenced by ZONE_CONTAINER::HitTestForEdge().

1373 {
1374  // Shows whether there was a collision
1375  bool collision = false;
1376 
1377  SEGMENT_ITERATOR iterator;
1378 
1379  for( iterator = IterateSegmentsWithHoles(); iterator; iterator++ )
1380  {
1381  SEG currentSegment = *iterator;
1382  int distance = currentSegment.Distance( aPoint );
1383 
1384  // Check for collisions
1385  if( distance <= aClearance )
1386  {
1387  collision = true;
1388 
1389  // Update aClearance to look for closer edges
1390  aClearance = distance;
1391 
1392  // Store the indices that identify the vertex
1393  aClosestVertex = iterator.GetIndex();
1394  }
1395  }
1396 
1397  return collision;
1398 }
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
Definition: seg.h:36
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
bool SHAPE_POLY_SET::CollideVertex ( const VECTOR2I aPoint,
SHAPE_POLY_SET::VERTEX_INDEX aClosestVertex,
int  aClearance = 0 
)

Function CollideVertex Checks whether aPoint collides with any vertex of any of the contours of the polygon.

Parameters
aPointis the VECTOR2I point whose collision with respect to the polygon will be tested.
aClearanceis the security distance; if aPoint lies closer to a vertex than aClearance distance, then there is a collision.
aClosestVertexis the index of the closes vertex to aPoint.
Returns
bool - true if there is a collision, false in any other case.

Definition at line 1333 of file shape_poly_set.cpp.

References delta, VECTOR2< T >::EuclideanNorm(), and IterateWithHoles().

Referenced by ZONE_CONTAINER::HitTestForCorner().

1335 {
1336  // Shows whether there was a collision
1337  bool collision = false;
1338 
1339  // Difference vector between each vertex and aPoint.
1340  VECTOR2D delta;
1341  double distance, clearance;
1342 
1343  // Convert clearance to double for precission when comparing distances
1344  clearance = aClearance;
1345 
1346  for( ITERATOR iterator = IterateWithHoles(); iterator; iterator++ )
1347  {
1348  // Get the difference vector between current vertex and aPoint
1349  delta = *iterator - aPoint;
1350 
1351  // Compute distance
1352  distance = delta.EuclideanNorm();
1353 
1354  // Check for collisions
1355  if( distance <= clearance )
1356  {
1357  collision = true;
1358 
1359  // Update aClearance to look for closer vertices
1360  clearance = distance;
1361 
1362  // Store the indices that identify the vertex
1363  aClosestVertex = iterator.GetIndex();
1364  }
1365  }
1366 
1367  return collision;
1368 }
static const int delta[8][2]
Definition: solve.cpp:112
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:294
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
ITERATOR IterateWithHoles()
Function IterateWithHoles.
bool SHAPE_POLY_SET::Contains ( const VECTOR2I aP,
int  aSubpolyIndex = -1 
) const

Returns true if a given subpolygon contains the point aP.

If aSubpolyIndex < 0

(default value), checks all polygons in the set

Definition at line 1401 of file shape_poly_set.cpp.

References containsSingle(), m_polys, and OutlineCount().

Referenced by Collide(), DRC::doEdgeZoneDrc(), D_PAD::GetBestAnchorPosition(), GERBER_DRAW_ITEM::HitTest(), ZONE_CONTAINER::HitTestFilledArea(), ZONE_CONTAINER::HitTestInsideZone(), BOARD::TestAreaIntersection(), and DRC::TestZoneToZoneOutline().

1402 {
1403  if( m_polys.size() == 0 ) // empty set?
1404  return false;
1405 
1406  // If there is a polygon specified, check the condition against that polygon
1407  if( aSubpolyIndex >= 0 )
1408  return containsSingle( aP, aSubpolyIndex );
1409 
1410  // In any other case, check it against all polygons in the set
1411  for( int polygonIdx = 0; polygonIdx < OutlineCount(); polygonIdx++ )
1412  {
1413  if( containsSingle( aP, polygonIdx ) )
1414  return true;
1415  }
1416 
1417  return false;
1418 }
int OutlineCount() const
Returns the number of outlines in the set
bool containsSingle(const VECTOR2I &aP, int aSubpolyIndex) const
containsSingle function Checks whether the point aP is inside the aSubpolyIndex-th polygon of the pol...
bool SHAPE_POLY_SET::containsSingle ( const VECTOR2I aP,
int  aSubpolyIndex 
) const
private

containsSingle function Checks whether the point aP is inside the aSubpolyIndex-th polygon of the polyset.

If the points lies on an edge, the polygon is considered to contain it.

Parameters
aPis the VECTOR2I point whose position with respect to the inside of the aSubpolyIndex-th polygon will be tested.
aSubpolyIndexis an integer specifying which polygon in the set has to be checked.
Returns
bool - true if aP is inside aSubpolyIndex-th polygon; false in any other case.

Definition at line 1439 of file shape_poly_set.cpp.

References CHole(), HoleCount(), m_polys, pointInPolygon(), and SHAPE_LINE_CHAIN::PointOnEdge().

Referenced by Contains(), and DistanceToPolygon().

1440 {
1441  // Check that the point is inside the outline
1442  if( pointInPolygon( aP, m_polys[aSubpolyIndex][0] ) )
1443  {
1444  // Check that the point is not in any of the holes
1445  for( int holeIdx = 0; holeIdx < HoleCount( aSubpolyIndex ); holeIdx++ )
1446  {
1447  const SHAPE_LINE_CHAIN hole = CHole( aSubpolyIndex, holeIdx );
1448 
1449  // If the point is inside a hole (and not on its edge),
1450  // it is outside of the polygon
1451  if( pointInPolygon( aP, hole ) && !hole.PointOnEdge( aP ) )
1452  return false;
1453  }
1454 
1455  return true;
1456  }
1457 
1458  return false;
1459 }
bool PointOnEdge(const VECTOR2I &aP) const
Function PointOnEdge()
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
bool pointInPolygon(const VECTOR2I &aP, const SHAPE_LINE_CHAIN &aPath) const
Class SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN SHAPE_POLY_SET::convertFromClipper ( const ClipperLib::Path &  aPath)
private

Definition at line 473 of file shape_poly_set.cpp.

References SHAPE_LINE_CHAIN::Append(), and SHAPE_LINE_CHAIN::SetClosed().

Referenced by importTree().

474 {
475  SHAPE_LINE_CHAIN lc;
476 
477  for( unsigned int i = 0; i < aPath.size(); i++ )
478  lc.Append( aPath[i].X, aPath[i].Y );
479 
480  lc.SetClosed( true );
481 
482  return lc;
483 }
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetClosed(bool aClosed)
Function SetClosed()
Class SHAPE_LINE_CHAIN.
const Path SHAPE_POLY_SET::convertToClipper ( const SHAPE_LINE_CHAIN aPath,
bool  aRequiredOrientation 
)
private

Definition at line 455 of file shape_poly_set.cpp.

References SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::PointCount(), vertex(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by booleanOp(), and Inflate().

457 {
458  Path c_path;
459 
460  for( int i = 0; i < aPath.PointCount(); i++ )
461  {
462  const VECTOR2I& vertex = aPath.CPoint( i );
463  c_path.push_back( IntPoint( vertex.x, vertex.y ) );
464  }
465 
466  if( Orientation( c_path ) != aRequiredOrientation )
467  ReversePath( c_path );
468 
469  return c_path;
470 }
int PointCount() const
Function PointCount()
VECTOR2I & vertex(int aCornerId)
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
const VECTOR2I & SHAPE_POLY_SET::CVertex ( int  aIndex,
int  aOutline,
int  aHole 
) const

Returns the index-th vertex in a given hole outline within a given outline

Definition at line 280 of file shape_poly_set.cpp.

References m_polys.

Referenced by CVertex(), ZONE_CONTAINER::GetCornerPosition(), and POINT_EDITOR::updatePoints().

281 {
282  if( aOutline < 0 )
283  aOutline += m_polys.size();
284 
285  int idx;
286 
287  if( aHole < 0 )
288  idx = 0;
289  else
290  idx = aHole + 1;
291 
292  assert( aOutline < (int) m_polys.size() );
293  assert( idx < (int) m_polys[aOutline].size() );
294 
295  return m_polys[aOutline][idx].CPoint( aIndex );
296 }
const VECTOR2I & SHAPE_POLY_SET::CVertex ( int  aGlobalIndex) const

Returns the aGlobalIndex-th vertex in the poly set

Definition at line 311 of file shape_poly_set.cpp.

References GetRelativeIndices(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, m_polys, and SHAPE_POLY_SET::VERTEX_INDEX::m_vertex.

312 {
314 
315  // Assure the passed index references a legal position; abort otherwise
316  if( !GetRelativeIndices( aGlobalIndex, &index ) )
317  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
318 
319  return m_polys[index.m_polygon][index.m_contour].CPoint( index.m_vertex );
320 }
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
const VECTOR2I & SHAPE_POLY_SET::CVertex ( SHAPE_POLY_SET::VERTEX_INDEX  index) const

Returns the index-th vertex in a given hole outline within a given outline

Definition at line 329 of file shape_poly_set.cpp.

References CVertex(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, and SHAPE_POLY_SET::VERTEX_INDEX::m_vertex.

330 {
331  return CVertex( index.m_vertex, index.m_polygon, index.m_contour - 1 );
332 }
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Returns the index-th vertex in a given hole outline within a given outline
const VECTOR2I& SHAPE_POLY_SET::cvertex ( int  aCornerId) const
private
void SHAPE_POLY_SET::DeletePolygon ( int  aIdx)

Deletes aIdx-th polygon from the set

Definition at line 1315 of file shape_poly_set.cpp.

References m_polys.

Referenced by D_PAD::buildCustomPadPolygon(), and ZONE_FILLER::Fill().

1316 {
1317  m_polys.erase( m_polys.begin() + aIdx );
1318 }
int SHAPE_POLY_SET::Distance ( VECTOR2I  aPoint)

Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the set.

Parameters
aPointis the point whose distance to the set has to be measured.
Returns
int - The minimum distance between aPoint and all the polygons in the set. If the point is contained in any of the polygons, the distance is zero.

Definition at line 1630 of file shape_poly_set.cpp.

References DistanceToPolygon(), and m_polys.

Referenced by DRC::doTrackKeepoutDrc(), and DRC::testKeepoutAreas().

1631 {
1632  int currentDistance;
1633  int minDistance = DistanceToPolygon( aPoint, 0 );
1634 
1635  // Iterate through all the polygons and get the minimum distance.
1636  for( unsigned int polygonIdx = 1; polygonIdx < m_polys.size(); polygonIdx++ )
1637  {
1638  currentDistance = DistanceToPolygon( aPoint, polygonIdx );
1639 
1640  if( currentDistance < minDistance )
1641  minDistance = currentDistance;
1642  }
1643 
1644  return minDistance;
1645 }
int DistanceToPolygon(VECTOR2I aPoint, int aIndex)
Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aPoint...
int SHAPE_POLY_SET::Distance ( SEG  aSegment,
int  aSegmentWidth = 0 
)

Function DistanceToPolygon computes the minimum distance between aSegment and all the polygons in the set.

Parameters
aSegmentis the segment whose distance to the polygon set has to be measured.
aSegmentWidthis the width of the segment; defaults to zero.
Returns
int - The minimum distance between aSegment and all the polygons in the set. If the point is contained in the polygon, the distance is zero.

Definition at line 1648 of file shape_poly_set.cpp.

References DistanceToPolygon(), and m_polys.

1649 {
1650  int currentDistance;
1651  int minDistance = DistanceToPolygon( aSegment, 0 );
1652 
1653  // Iterate through all the polygons and get the minimum distance.
1654  for( unsigned int polygonIdx = 1; polygonIdx < m_polys.size(); polygonIdx++ )
1655  {
1656  currentDistance = DistanceToPolygon( aSegment, polygonIdx, aSegmentWidth );
1657 
1658  if( currentDistance < minDistance )
1659  minDistance = currentDistance;
1660  }
1661 
1662  return minDistance;
1663 }
int DistanceToPolygon(VECTOR2I aPoint, int aIndex)
Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aPoint...
int SHAPE_POLY_SET::DistanceToPolygon ( VECTOR2I  aPoint,
int  aIndex 
)

Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aPoint.

Parameters
aPointis the point whose distance to the aIndex-th polygon has to be measured.
aIndexis the index of the polygon whose distace to aPoint has to be measured.
Returns
int - The minimum distance between aPoint and all the segments of the aIndex-th polygon. If the point is contained in the polygon, the distance is zero.

Definition at line 1569 of file shape_poly_set.cpp.

References containsSingle(), SEG::Distance(), and IterateSegmentsWithHoles().

Referenced by Distance().

1570 {
1571  // We calculate the min dist between the segment and each outline segment
1572  // However, if the segment to test is inside the outline, and does not cross
1573  // any edge, it can be seen outside the polygon.
1574  // Therefore test if a segment end is inside ( testing only one end is enough )
1575  if( containsSingle( aPoint, aPolygonIndex ) )
1576  return 0;
1577 
1578  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
1579 
1580  SEG polygonEdge = *iterator;
1581  int minDistance = polygonEdge.Distance( aPoint );
1582 
1583  for( iterator++; iterator && minDistance > 0; iterator++ )
1584  {
1585  polygonEdge = *iterator;
1586 
1587  int currentDistance = polygonEdge.Distance( aPoint );
1588 
1589  if( currentDistance < minDistance )
1590  minDistance = currentDistance;
1591  }
1592 
1593  return minDistance;
1594 }
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
bool containsSingle(const VECTOR2I &aP, int aSubpolyIndex) const
containsSingle function Checks whether the point aP is inside the aSubpolyIndex-th polygon of the pol...
Definition: seg.h:36
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
int SHAPE_POLY_SET::DistanceToPolygon ( SEG  aSegment,
int  aIndex,
int  aSegmentWidth = 0 
)

Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aSegment with a possible width.

Parameters
aSegmentis the segment whose distance to the aIndex-th polygon has to be measured.
aIndexis the index of the polygon whose distace to aPoint has to be measured.
aSegmentWidthis the width of the segment; defaults to zero.
Returns
int - The minimum distance between aSegment and all the segments of the aIndex-th polygon. If the point is contained in the polygon, the distance is zero.

Definition at line 1597 of file shape_poly_set.cpp.

References SEG::A, containsSingle(), SEG::Distance(), and IterateSegmentsWithHoles().

1598 {
1599  // We calculate the min dist between the segment and each outline segment
1600  // However, if the segment to test is inside the outline, and does not cross
1601  // any edge, it can be seen outside the polygon.
1602  // Therefore test if a segment end is inside ( testing only one end is enough )
1603  if( containsSingle( aSegment.A, aPolygonIndex ) )
1604  return 0;
1605 
1606  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
1607 
1608  SEG polygonEdge = *iterator;
1609  int minDistance = polygonEdge.Distance( aSegment );
1610 
1611  for( iterator++; iterator && minDistance > 0; iterator++ )
1612  {
1613  polygonEdge = *iterator;
1614 
1615  int currentDistance = polygonEdge.Distance( aSegment );
1616 
1617  if( currentDistance < minDistance )
1618  minDistance = currentDistance;
1619  }
1620 
1621  // Take into account the width of the segment
1622  if( aSegmentWidth > 0 )
1623  minDistance -= aSegmentWidth / 2;
1624 
1625  // Return the maximum of minDistance and zero
1626  return minDistance < 0 ? 0 : minDistance;
1627 }
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
bool containsSingle(const VECTOR2I &aP, int aSubpolyIndex) const
containsSingle function Checks whether the point aP is inside the aSubpolyIndex-th polygon of the pol...
Definition: seg.h:36
VECTOR2I A
Definition: seg.h:46
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:195
SHAPE_POLY_SET SHAPE_POLY_SET::Fillet ( int  aRadius,
int  aSegments 
)

Function Fillet returns a filleted version of the polygon set.

Parameters
aRadiusis the fillet radius.
aSegmentsis the number of segments / fillet.
Returns
SHAPE_POLY_SET - A set containing the filleted version of this set.

Definition at line 1690 of file shape_poly_set.cpp.

References FilletPolygon(), and m_polys.

Referenced by ZONE_CONTAINER::BuildSmoothedPoly().

1691 {
1692  SHAPE_POLY_SET filleted;
1693 
1694  for( size_t polygonIdx = 0; polygonIdx < m_polys.size(); polygonIdx++ )
1695  filleted.m_polys.push_back( FilletPolygon( aRadius, aSegments, polygonIdx ) );
1696 
1697  return filleted;
1698 }
Class SHAPE_POLY_SET.
POLYGON FilletPolygon(unsigned int aRadius, unsigned int aSegments, int aIndex=0)
Function Fillet returns a filleted version of the aIndex-th polygon.
SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::FilletPolygon ( unsigned int  aRadius,
unsigned int  aSegments,
int  aIndex = 0 
)

Function Fillet returns a filleted version of the aIndex-th polygon.

Parameters
aRadiusis the fillet radius.
aSegmentsis the number of segments / fillet.
aIndexis the index of the polygon to be filleted
Returns
POLYGON - A polygon containing the filleted version of the aIndex-th polygon.

Definition at line 1561 of file shape_poly_set.cpp.

References chamferFilletPolygon().

Referenced by Fillet().

1564 {
1565  return chamferFilletPolygon( CORNER_MODE::FILLETED, aRadius, aIndex, aSegments );
1566 }
POLYGON chamferFilletPolygon(CORNER_MODE aMode, unsigned int aDistance, int aIndex, int aSegments=-1)
Function chamferFilletPolygon Returns the camfered or filleted version of the aIndex-th polygon in th...
const std::string SHAPE_POLY_SET::Format ( ) const
overridevirtual

Reimplemented from SHAPE.

Definition at line 1112 of file shape_poly_set.cpp.

References m_polys.

1113 {
1114  std::stringstream ss;
1115 
1116  ss << "polyset " << m_polys.size() << "\n";
1117 
1118  for( unsigned i = 0; i < m_polys.size(); i++ )
1119  {
1120  ss << "poly " << m_polys[i].size() << "\n";
1121 
1122  for( unsigned j = 0; j < m_polys[i].size(); j++ )
1123  {
1124  ss << m_polys[i][j].PointCount() << "\n";
1125 
1126  for( int v = 0; v < m_polys[i][j].PointCount(); v++ )
1127  ss << m_polys[i][j].CPoint( v ).x << " " << m_polys[i][j].CPoint( v ).y << "\n";
1128  }
1129 
1130  ss << "\n";
1131  }
1132 
1133  return ss.str();
1134 }
void SHAPE_POLY_SET::Fracture ( POLYGON_MODE  aFastMode)

Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the outer ring to the inner holes For aFastMode meaning, see function booleanOp

Definition at line 871 of file shape_poly_set.cpp.

References fractureSingle(), m_polys, and Simplify().

Referenced by addHoleToPolygon(), D_PAD::buildCustomPadPolygon(), ZONE_FILLER::computeRawFilledAreas(), ZONE_FILLER::fillSingleZone(), APERTURE_MACRO::GetApertureMacroShape(), DXF_PLOTTER::PlotPoly(), PlotSolderMaskLayer(), C3D_RENDER_RAYTRACING::reload(), and ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon().

872 {
873  Simplify( aFastMode ); // remove overlapping holes/degeneracy
874 
875  for( POLYGON& paths : m_polys )
876  {
877  fractureSingle( paths );
878  }
879 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void fractureSingle(POLYGON &paths)
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
void SHAPE_POLY_SET::fractureSingle ( POLYGON paths)
private

Definition at line 769 of file shape_poly_set.cpp.

References SHAPE_LINE_CHAIN::Append(), FractureEdge::m_connected, FractureEdge::m_next, FractureEdge::m_p1, max, processEdge(), SHAPE_LINE_CHAIN::SetClosed(), and VECTOR2< T >::x.

Referenced by Fracture().

770 {
771  FractureEdgeSet edges;
772  FractureEdgeSet border_edges;
773  FractureEdge* root = NULL;
774 
775  bool first = true;
776 
777  if( paths.size() == 1 )
778  return;
779 
780  int num_unconnected = 0;
781 
782  for( SHAPE_LINE_CHAIN& path : paths )
783  {
784  int index = 0;
785 
786  FractureEdge* prev = NULL, * first_edge = NULL;
787 
788  int x_min = std::numeric_limits<int>::max();
789 
790  for( int i = 0; i < path.PointCount(); i++ )
791  {
792  const VECTOR2I& p = path.CPoint( i );
793 
794  if( p.x < x_min )
795  x_min = p.x;
796  }
797 
798  for( int i = 0; i < path.PointCount(); i++ )
799  {
800  FractureEdge* fe = new FractureEdge( first, &path, index++ );
801 
802  if( !root )
803  root = fe;
804 
805  if( !first_edge )
806  first_edge = fe;
807 
808  if( prev )
809  prev->m_next = fe;
810 
811  if( i == path.PointCount() - 1 )
812  fe->m_next = first_edge;
813 
814  prev = fe;
815  edges.push_back( fe );
816 
817  if( !first )
818  {
819  if( fe->m_p1.x == x_min )
820  border_edges.push_back( fe );
821  }
822 
823  if( !fe->m_connected )
824  num_unconnected++;
825  }
826 
827  first = false; // first path is always the outline
828  }
829 
830  // keep connecting holes to the main outline, until there's no holes left...
831  while( num_unconnected > 0 )
832  {
833  int x_min = std::numeric_limits<int>::max();
834 
835  FractureEdge* smallestX = NULL;
836 
837  // find the left-most hole edge and merge with the outline
838  for( FractureEdgeSet::iterator i = border_edges.begin(); i != border_edges.end(); ++i )
839  {
840  int xt = (*i)->m_p1.x;
841 
842  if( ( xt < x_min ) && !(*i)->m_connected )
843  {
844  x_min = xt;
845  smallestX = *i;
846  }
847  }
848 
849  num_unconnected -= processEdge( edges, smallestX );
850  }
851 
852  paths.clear();
853  SHAPE_LINE_CHAIN newPath;
854 
855  newPath.SetClosed( true );
856 
857  FractureEdge* e;
858 
859  for( e = root; e->m_next != root; e = e->m_next )
860  newPath.Append( e->m_p1 );
861 
862  newPath.Append( e->m_p1 );
863 
864  for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i )
865  delete *i;
866 
867  paths.push_back( newPath );
868 }
static int processEdge(FractureEdgeSet &edges, FractureEdge *edge)
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetClosed(bool aClosed)
Function SetClosed()
#define max(a, b)
Definition: auxiliary.h:86
Class SHAPE_LINE_CHAIN.
FractureEdge * m_next
std::vector< FractureEdge * > FractureEdgeSet
SHAPE_LINE_CHAIN& SHAPE_POLY_SET::getContourForCorner ( int  aCornerId,
int &  aIndexWithinContour 
)
private
bool SHAPE_POLY_SET::GetGlobalIndex ( SHAPE_POLY_SET::VERTEX_INDEX  aRelativeIndices,
int &  aGlobalIdx 
)

Function GetGlobalIndex computes the global index of a vertex from the relative indices of polygon, contour and vertex.

Parameters
aRelativeIndicesis the set of relative indices.
aGlobalIdx[out] is the computed global index.
Returns
bool - true if the relative indices are correct; false otherwise. The computed global index is returned in the aGlobalIdx reference.

Definition at line 106 of file shape_poly_set.cpp.

References SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, m_polys, SHAPE_POLY_SET::VERTEX_INDEX::m_vertex, and Polygon().

Referenced by GetNeighbourIndexes(), and ZONE_CONTAINER::GetSelectedCorner().

108 {
109  int selectedVertex = aRelativeIndices.m_vertex;
110  unsigned int selectedContour = aRelativeIndices.m_contour;
111  unsigned int selectedPolygon = aRelativeIndices.m_polygon;
112 
113  // Check whether the vertex indices make sense in this poly set
114  if( selectedPolygon < m_polys.size() && selectedContour < m_polys[selectedPolygon].size()
115  && selectedVertex < m_polys[selectedPolygon][selectedContour].PointCount() )
116  {
117  POLYGON currentPolygon;
118 
119  aGlobalIdx = 0;
120 
121  for( unsigned int polygonIdx = 0; polygonIdx < selectedPolygon; polygonIdx++ )
122  {
123  currentPolygon = Polygon( polygonIdx );
124 
125  for( unsigned int contourIdx = 0; contourIdx < currentPolygon.size(); contourIdx++ )
126  {
127  aGlobalIdx += currentPolygon[contourIdx].PointCount();
128  }
129  }
130 
131  currentPolygon = Polygon( selectedPolygon );
132 
133  for( unsigned int contourIdx = 0; contourIdx < selectedContour; contourIdx++ )
134  {
135  aGlobalIdx += currentPolygon[contourIdx].PointCount();
136  }
137 
138  aGlobalIdx += selectedVertex;
139 
140  return true;
141  }
142  else
143  {
144  return false;
145  }
146 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
bool SHAPE_POLY_SET::GetNeighbourIndexes ( int  aGlobalIndex,
int *  aPrevious,
int *  aNext 
)

Returns the global indexes of the previous and the next corner of the aGlobalIndex-th corner of a contour in the polygon set.

they are often aGlobalIndex-1 and aGlobalIndex+1, but not for the first and last corner of the contour.

Parameters
aGlobalIndexis index of the corner, globally indexed between all edges in all contours
aPrevious- the globalIndex of the previous corner of the same contour.
aNext- the globalIndex of the next corner of the same contour.
Returns
true if OK, false if aGlobalIndex is out of range

Definition at line 335 of file shape_poly_set.cpp.

References GetGlobalIndex(), GetRelativeIndices(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, m_polys, SHAPE_POLY_SET::VERTEX_INDEX::m_vertex, and next().

Referenced by ZONE_CONTAINER::MoveEdge().

336 {
338 
339  // If the edge does not exist, throw an exception, it is an illegal access memory error
340  if( !GetRelativeIndices( aGlobalIndex, &index ) )
341  return false;
342 
343  // Calculate the previous and next index of aGlobalIndex, corresponding to
344  // the same contour;
345  VERTEX_INDEX inext = index;
346  int lastpoint = m_polys[index.m_polygon][index.m_contour].SegmentCount();
347 
348  if( index.m_vertex == 0 )
349  {
350  index.m_vertex = lastpoint;
351  inext.m_vertex = 1;
352  }
353  else if( index.m_vertex == lastpoint )
354  {
355  index.m_vertex--;
356  inext.m_vertex = 0;
357  }
358  else
359  {
360  inext.m_vertex++;
361  index.m_vertex--;
362  }
363 
364  if( aPrevious )
365  {
366  int previous;
367  GetGlobalIndex( index, previous );
368  *aPrevious = previous;
369  }
370 
371  if( aNext )
372  {
373  int next;
374  GetGlobalIndex( inext, next );
375  *aNext = next;
376  }
377 
378  return true;
379 }
CITER next(CITER it)
Definition: ptree.cpp:130
Struct VERTEX_INDEX.
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
bool GetGlobalIndex(VERTEX_INDEX aRelativeIndices, int &aGlobalIdx)
Function GetGlobalIndex computes the global index of a vertex from the relative indices of polygon...
bool SHAPE_POLY_SET::GetRelativeIndices ( int  aGlobalIdx,
SHAPE_POLY_SET::VERTEX_INDEX aRelativeIndices 
) const

Function GetRelativeIndices.

Converts a global vertex index —i.e., a number that globally identifies a vertex in a concatenated list of all vertices in all contours— and get the index of the vertex relative to the contour relative to the polygon in which it is.

Parameters
aGlobalIdxis the global index of the corner whose structured index wants to be found
aRelativeIndicesis a pointer to the set of relative indices to store.
Returns
bool - true if the global index is correct and the information in aRelativeIndices is valid; false otherwise.

Definition at line 66 of file shape_poly_set.cpp.

References CPolygon(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, SHAPE_POLY_SET::VERTEX_INDEX::m_vertex, OutlineCount(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by CVertex(), PCB_EDIT_FRAME::Delete_Zone_Contour(), DRC::doEdgeZoneDrc(), ZONE_CONTAINER::GetCornerPosition(), GetNeighbourIndexes(), InsertVertex(), IsVertexInHole(), IterateFromVertexWithHoles(), RemoveVertex(), ZONE_CONTAINER::SetCornerPosition(), ZONE_CONTAINER::SetSelectedCorner(), and Vertex().

68 {
69  int polygonIdx = 0;
70  unsigned int contourIdx = 0;
71  int vertexIdx = 0;
72 
73  int currentGlobalIdx = 0;
74 
75  for( polygonIdx = 0; polygonIdx < OutlineCount(); polygonIdx++ )
76  {
77  const POLYGON currentPolygon = CPolygon( polygonIdx );
78 
79  for( contourIdx = 0; contourIdx < currentPolygon.size(); contourIdx++ )
80  {
81  SHAPE_LINE_CHAIN currentContour = currentPolygon[contourIdx];
82  int totalPoints = currentContour.PointCount();
83 
84  for( vertexIdx = 0; vertexIdx < totalPoints; vertexIdx++ )
85  {
86  // Check if the current vertex is the globally indexed as aGlobalIdx
87  if( currentGlobalIdx == aGlobalIdx )
88  {
89  aRelativeIndices->m_polygon = polygonIdx;
90  aRelativeIndices->m_contour = contourIdx;
91  aRelativeIndices->m_vertex = vertexIdx;
92 
93  return true;
94  }
95 
96  // Advance
97  currentGlobalIdx++;
98  }
99  }
100  }
101 
102  return false;
103 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
int PointCount() const
Function PointCount()
int OutlineCount() const
Returns the number of outlines in the set
Class SHAPE_LINE_CHAIN.
const POLYGON & CPolygon(int aIndex) const
bool SHAPE_POLY_SET::HasHoles ( ) const

Returns true if the polygon set has any holes.

Definition at line 1045 of file shape_poly_set.cpp.

References m_polys.

1046 {
1047  // Iterate through all the polygons on the set
1048  for( const POLYGON& paths : m_polys )
1049  {
1050  // If any of them has more than one contour, it is a hole.
1051  if( paths.size() > 1 )
1052  return true;
1053  }
1054 
1055  // Return false if and only if every polygon has just one outline, without holes.
1056  return false;
1057 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
SHAPE_LINE_CHAIN& SHAPE_POLY_SET::Hole ( int  aOutline,
int  aHole 
)
inline

Returns the reference to aHole-th hole in the aIndex-th outline

Definition at line 569 of file shape_poly_set.h.

References m_polys.

Referenced by Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), export_vrml_board(), DSN::SPECCTRA_DB::fillBOUNDARY(), and ZONE_CREATE_HELPER::performZoneCutout().

570  {
571  return m_polys[aOutline][aHole + 1];
572  }
int SHAPE_POLY_SET::HoleCount ( int  aOutline) const
inline

Returns the number of holes in a given outline

Definition at line 536 of file shape_poly_set.h.

References m_polys.

Referenced by CINFO3D_VISU::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), ZONE_CONTAINER::AppendCorner(), containsSingle(), Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), Convert_shape_line_polygon_to_triangles(), export_vrml_board(), DSN::SPECCTRA_DB::fillBOUNDARY(), and PlotLayerOutlines().

537  {
538  if( ( aOutline < 0 ) || (aOutline >= (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
539  return 0;
540 
541  // the first polygon in m_polys[aOutline] is the main contour,
542  // only others are holes:
543  return m_polys[aOutline].size() - 1;
544  }
void SHAPE_POLY_SET::importTree ( ClipperLib::PolyTree *  tree)
private

Definition at line 633 of file shape_poly_set.cpp.

References convertFromClipper(), and m_polys.

Referenced by booleanOp(), and Inflate().

634 {
635  m_polys.clear();
636 
637  for( PolyNode* n = tree->GetFirst(); n; n = n->GetNext() )
638  {
639  if( !n->IsHole() )
640  {
641  POLYGON paths;
642  paths.reserve( n->Childs.size() + 1 );
643  paths.push_back( convertFromClipper( n->Contour ) );
644 
645  for( unsigned int i = 0; i < n->Childs.size(); i++ )
646  paths.push_back( convertFromClipper( n->Childs[i]->Contour ) );
647 
648  m_polys.push_back( paths );
649  }
650  }
651 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
const SHAPE_LINE_CHAIN convertFromClipper(const ClipperLib::Path &aPath)
void SHAPE_POLY_SET::Inflate ( int  aFactor,
int  aCircleSegmentsCount 
)

Performs outline inflation/deflation, using round corners.

Definition at line 586 of file shape_poly_set.cpp.

References abs, convertToClipper(), importTree(), m_polys, and SEG_CNT_MAX.

Referenced by D_PAD::buildCustomPadPolygon(), ZONE_FILLER::buildZoneFeatureHoleList(), Collide(), ZONE_FILLER::computeRawFilledAreas(), CINFO3D_VISU::createNewPadWithClearance(), KIGFX::PCB_PAINTER::draw(), D_PAD::DrawShape(), ZONE_FILLER::fillSingleZone(), PlotSolderMaskLayer(), ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(), TransformRoundRectToPolygon(), and D_PAD::TransformShapeWithClearanceToPolygon().

587 {
588  // A static table to avoid repetitive calculations of the coefficient
589  // 1.0 - cos( M_PI/aCircleSegmentsCount)
590  // aCircleSegmentsCount is most of time <= 64 and usually 8, 12, 16, 32
591  #define SEG_CNT_MAX 64
592  static double arc_tolerance_factor[SEG_CNT_MAX + 1];
593 
594  ClipperOffset c;
595 
596  for( const POLYGON& poly : m_polys )
597  {
598  for( unsigned int i = 0; i < poly.size(); i++ )
599  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), jtRound,
600  etClosedPolygon );
601  }
602 
603  PolyTree solution;
604 
605  // Calculate the arc tolerance (arc error) from the seg count by circle.
606  // the seg count is nn = M_PI / acos(1.0 - c.ArcTolerance / abs(aFactor))
607  // see:
608  // www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/ClipperOffset/Properties/ArcTolerance.htm
609 
610  if( aCircleSegmentsCount < 6 ) // avoid incorrect aCircleSegmentsCount values
611  aCircleSegmentsCount = 6;
612 
613  double coeff;
614 
615  if( aCircleSegmentsCount > SEG_CNT_MAX || arc_tolerance_factor[aCircleSegmentsCount] == 0 )
616  {
617  coeff = 1.0 - cos( M_PI / aCircleSegmentsCount );
618 
619  if( aCircleSegmentsCount <= SEG_CNT_MAX )
620  arc_tolerance_factor[aCircleSegmentsCount] = coeff;
621  }
622  else
623  coeff = arc_tolerance_factor[aCircleSegmentsCount];
624 
625  c.ArcTolerance = std::abs( aFactor ) * coeff;
626 
627  c.Execute( solution, aFactor );
628 
629  importTree( &solution );
630 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
const ClipperLib::Path convertToClipper(const SHAPE_LINE_CHAIN &aPath, bool aRequiredOrientation)
#define abs(a)
Definition: auxiliary.h:84
#define SEG_CNT_MAX
void importTree(ClipperLib::PolyTree *tree)
void SHAPE_POLY_SET::InsertVertex ( int  aGlobalIndex,
VECTOR2I  aNewVertex 
)

Function InsertVertex Adds a vertex in the globally indexed position aGlobalIndex.

Parameters
aGlobalIndexis the global index of the position in which teh new vertex will be inserted.
aNewVertexis the new inserted vertex.

Definition at line 199 of file shape_poly_set.cpp.

References Append(), GetRelativeIndices(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, m_polys, SHAPE_POLY_SET::VERTEX_INDEX::m_vertex, and TotalVertices().

Referenced by POINT_EDITOR::addCorner(), PCB_EDIT_FRAME::Process_Special_Functions(), and PCB_EDIT_FRAME::Start_Move_Zone_Corner().

200 {
201  VERTEX_INDEX index;
202 
203  if( aGlobalIndex < 0 )
204  aGlobalIndex = 0;
205 
206  if( aGlobalIndex >= TotalVertices() )
207  {
208  Append( aNewVertex );
209  }
210  else
211  {
212  // Assure the position to be inserted exists; throw an exception otherwise
213  if( GetRelativeIndices( aGlobalIndex, &index ) )
214  m_polys[index.m_polygon][index.m_contour].Insert( index.m_vertex, aNewVertex );
215  else
216  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
217  }
218 }
int TotalVertices() const
Returns total number of vertices stored in the set.
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...
bool SHAPE_POLY_SET::IsPolygonSelfIntersecting ( int  aPolygonIndex)

Function IsPolygonSelfIntersecting.

Checks whether the aPolygonIndex-th polygon in the set is self intersecting.

Parameters
aPolygonIndexindex of the polygon that wants to be checked.
Returns
bool - true if the aPolygonIndex-th polygon is self intersecting, false otherwise.

Definition at line 382 of file shape_poly_set.cpp.

References SEG::Collide(), CPolygon(), SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::IsAdjacent(), and IterateSegmentsWithHoles().

Referenced by IsSelfIntersecting().

383 {
384  // Get polygon
385  const POLYGON poly = CPolygon( aPolygonIndex );
386 
387  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
388  SEGMENT_ITERATOR innerIterator;
389 
390  for( iterator = IterateSegmentsWithHoles( aPolygonIndex ); iterator; iterator++ )
391  {
392  SEG firstSegment = *iterator;
393 
394  // Iterate through all remaining segments.
395  innerIterator = iterator;
396 
397  // Start in the next segment, we don't want to check collision between a segment and itself
398  for( innerIterator++; innerIterator; innerIterator++ )
399  {
400  SEG secondSegment = *innerIterator;
401 
402  // Check whether the two segments built collide, only when they are not adjacent.
403  if( !iterator.IsAdjacent( innerIterator ) && firstSegment.Collide( secondSegment, 0 ) )
404  return true;
405  }
406  }
407 
408  return false;
409 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
Definition: seg.h:36
const POLYGON & CPolygon(int aIndex) const
bool Collide(const SEG &aSeg, int aClearance) const
Definition: seg.cpp:134
bool SHAPE_POLY_SET::IsSelfIntersecting ( )

Function IsSelfIntersecting Checks whether any of the polygons in the set is self intersecting.

Returns
bool - true if any of the polygons is self intersecting, false otherwise.

Definition at line 412 of file shape_poly_set.cpp.

References IsPolygonSelfIntersecting(), and m_polys.

Referenced by BOARD::NormalizeAreaPolygon().

413 {
414  for( unsigned int polygon = 0; polygon < m_polys.size(); polygon++ )
415  {
416  if( IsPolygonSelfIntersecting( polygon ) )
417  return true;
418  }
419 
420  return false;
421 }
bool IsPolygonSelfIntersecting(int aPolygonIndex)
Function IsPolygonSelfIntersecting.
bool SHAPE_POLY_SET::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 844 of file shape_poly_set.h.

845  {
846  return true;
847  }
bool SHAPE_POLY_SET::IsTriangulationUpToDate ( ) const

Definition at line 1986 of file shape_poly_set.cpp.

References checksum(), MD5_HASH::IsValid(), m_hash, and m_triangulationValid.

Referenced by KIGFX::OPENGL_GAL::DrawPolygon().

1987 {
1988  if( !m_triangulationValid )
1989  return false;
1990 
1991  if( !m_hash.IsValid() )
1992  return false;
1993 
1994  auto hash = checksum();
1995 
1996  return hash == m_hash;
1997 }
MD5_HASH checksum() const
bool IsValid() const
Definition: md5_hash.h:23
bool SHAPE_POLY_SET::IsVertexInHole ( int  aGlobalIdx)

Function IsVertexInHole.

checks whether the aGlobalIndex-th vertex belongs to a hole.

Parameters
aGlobalIdxis the index of the vertex.
Returns
bool - true if the globally indexed aGlobalIdx-th vertex belongs to a hole.

Definition at line 1666 of file shape_poly_set.cpp.

References GetRelativeIndices(), and SHAPE_POLY_SET::VERTEX_INDEX::m_contour.

Referenced by PCB_EDIT_FRAME::createPopUpMenuForZones().

1667 {
1668  VERTEX_INDEX index;
1669 
1670  // Get the polygon and contour where the vertex is. If the vertex does not exist, return false
1671  if( !GetRelativeIndices( aGlobalIdx, &index ) )
1672  return false;
1673 
1674  // The contour is a hole if its index is greater than zero
1675  return index.m_contour > 0;
1676 }
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
ITERATOR SHAPE_POLY_SET::Iterate ( int  aFirst,
int  aLast,
bool  aIterateHoles = false 
)
inline

Function Iterate returns an object to iterate through the points of the polygons between aFirst and aLast.

Parameters
aFirstis the first polygon whose points will be iterated.
aLastis the last polygon whose points will be iterated.
aIterateHolesis a flag to indicate whether the points of the holes should be iterated.
Returns
ITERATOR - the iterator object.

Definition at line 616 of file shape_poly_set.h.

References SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentContour, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentPolygon, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentVertex, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_iterateHoles, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_lastPolygon, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_poly, and OutlineCount().

Referenced by POINT_EDITOR::addCorner(), GERBER_DRAW_ITEM::ConvertSegmentToPolygon(), D_CODE::ConvertShapeToPolygon(), KIGFX::GERBVIEW_PAINTER::draw(), KIGFX::GERBVIEW_PAINTER::drawPolygon(), ZONE_CONTAINER::DrawWhileCreateOutline(), EDGE_MODULE::Flip(), ZONE_CONTAINER::Iterate(), EDGE_MODULE::Mirror(), ZONE_CONTAINER::Mirror(), EDGE_MODULE::Move(), GERBER_DRAW_ITEM::MoveAB(), GERBER_DRAW_ITEM::MoveXY(), DIALOG_PAD_PROPERTIES::redraw(), DRAWSEGMENT::Rotate(), and ZONE_CONTAINER::Rotate().

617  {
618  ITERATOR iter;
619 
620  iter.m_poly = this;
621  iter.m_currentPolygon = aFirst;
622  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
623  iter.m_currentContour = 0;
624  iter.m_currentVertex = 0;
625  iter.m_iterateHoles = aIterateHoles;
626 
627  return iter;
628  }
int OutlineCount() const
Returns the number of outlines in the set
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
ITERATOR SHAPE_POLY_SET::Iterate ( int  aOutline)
inline

Function Iterate.

Parameters
aOutlinethe index of the polygon to be iterated.
Returns
ITERATOR - an iterator object to visit all points in the main outline of the aOutline-th polygon, without visiting the points in the holes.

Definition at line 636 of file shape_poly_set.h.

References Iterate().

637  {
638  return Iterate( aOutline, aOutline );
639  }
ITERATOR Iterate()
Function Iterate.
ITERATOR SHAPE_POLY_SET::Iterate ( )
inline

Function Iterate.

Returns
ITERATOR - an iterator object to visit all points in all outlines of the set, without visiting the points in the holes.

Definition at line 657 of file shape_poly_set.h.

References OutlineCount().

Referenced by Iterate(), and IterateWithHoles().

658  {
659  return Iterate( 0, OutlineCount() - 1 );
660  }
ITERATOR Iterate()
Function Iterate.
int OutlineCount() const
Returns the number of outlines in the set
ITERATOR SHAPE_POLY_SET::IterateFromVertexWithHoles ( int  aGlobalIdx)
inline

Definition at line 707 of file shape_poly_set.h.

References GetRelativeIndices(), IterateWithHoles(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentContour, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentPolygon, SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::m_currentVertex, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, and SHAPE_POLY_SET::VERTEX_INDEX::m_vertex.

708  {
709  // Build iterator
710  ITERATOR iter = IterateWithHoles();
711 
712  // Get the relative indices of the globally indexed vertex
713  VERTEX_INDEX indices;
714 
715  if( !GetRelativeIndices( aGlobalIdx, &indices ) )
716  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
717 
718  // Adjust where the iterator is pointing
719  iter.m_currentPolygon = indices.m_polygon;
720  iter.m_currentContour = indices.m_contour;
721  iter.m_currentVertex = indices.m_vertex;
722 
723  return iter;
724  }
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
ITERATOR IterateWithHoles()
Function IterateWithHoles.
SEGMENT_ITERATOR SHAPE_POLY_SET::IterateSegments ( int  aFirst,
int  aLast,
bool  aIterateHoles = false 
)
inline

Returns an iterator object, for iterating between aFirst and aLast outline, with or

without holes (default: without)

Definition at line 728 of file shape_poly_set.h.

References SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentContour, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentPolygon, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentSegment, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_iterateHoles, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_lastPolygon, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_poly, and OutlineCount().

729  {
730  SEGMENT_ITERATOR iter;
731 
732  iter.m_poly = this;
733  iter.m_currentPolygon = aFirst;
734  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
735  iter.m_currentContour = 0;
736  iter.m_currentSegment = 0;
737  iter.m_iterateHoles = aIterateHoles;
738 
739  return iter;
740  }
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
int OutlineCount() const
Returns the number of outlines in the set
SEGMENT_ITERATOR SHAPE_POLY_SET::IterateSegments ( int  aPolygonIdx)
inline

Returns an iterator object, for iterating aPolygonIdx-th polygon edges

Definition at line 743 of file shape_poly_set.h.

References IterateSegments().

744  {
745  return IterateSegments( aPolygonIdx, aPolygonIdx );
746  }
SEGMENT_ITERATOR IterateSegments()
Returns an iterator object, for all outlines in the set (no holes)
SEGMENT_ITERATOR SHAPE_POLY_SET::IterateSegments ( )
inline

Returns an iterator object, for all outlines in the set (no holes)

Definition at line 749 of file shape_poly_set.h.

References OutlineCount().

Referenced by IterateSegments(), and IterateSegmentsWithHoles().

750  {
751  return IterateSegments( 0, OutlineCount() - 1 );
752  }
int OutlineCount() const
Returns the number of outlines in the set
SEGMENT_ITERATOR IterateSegments()
Returns an iterator object, for all outlines in the set (no holes)
SEGMENT_ITERATOR SHAPE_POLY_SET::IterateSegmentsWithHoles ( )
inline

Returns an iterator object, for all outlines in the set (with holes)

Definition at line 755 of file shape_poly_set.h.

References IterateSegments(), and OutlineCount().

Referenced by CollideEdge(), DistanceToPolygon(), DRC::doEdgeZoneDrc(), ZONE_CONTAINER::Draw(), ZONE_CONTAINER::Hatch(), IsPolygonSelfIntersecting(), BOARD::TestAreaIntersection(), and DRC::TestZoneToZoneOutline().

756  {
757  return IterateSegments( 0, OutlineCount() - 1, true );
758  }
int OutlineCount() const
Returns the number of outlines in the set
SEGMENT_ITERATOR IterateSegments()
Returns an iterator object, for all outlines in the set (no holes)
SEGMENT_ITERATOR SHAPE_POLY_SET::IterateSegmentsWithHoles ( int  aOutline)
inline

Returns an iterator object, for the aOutline-th outline in the set (with holes)

Definition at line 761 of file shape_poly_set.h.

References IterateSegments().

762  {
763  return IterateSegments( aOutline, aOutline, true );
764  }
SEGMENT_ITERATOR IterateSegments()
Returns an iterator object, for all outlines in the set (no holes)
ITERATOR SHAPE_POLY_SET::IterateWithHoles ( int  aOutline)
inline

Function IterateWithHoles.

Parameters
aOutlinethe index of the polygon to be iterated.
Returns
ITERATOR - an iterator object to visit all points in the main outline of the aOutline-th polygon, visiting also the points in the holes.

Definition at line 647 of file shape_poly_set.h.

References Iterate().

Referenced by findVertex(), ZONE_CONTAINER::Hatch(), ZONE_CONTAINER::IterateWithHoles(), ZONE_CONTAINER::Mirror(), ZONE_CONTAINER::Rotate(), BOARD::TestAreaIntersection(), and DRC::TestZoneToZoneOutline().

648  {
649  return Iterate( aOutline, aOutline, true );
650  }
ITERATOR Iterate()
Function Iterate.
ITERATOR SHAPE_POLY_SET::IterateWithHoles ( )
inline

Function IterateWithHoles.

Returns
ITERATOR - an iterator object to visit all points in all outlines of the set, visiting also the points in the holes.

Definition at line 667 of file shape_poly_set.h.

References Iterate(), and OutlineCount().

Referenced by CollideVertex(), IterateFromVertexWithHoles(), and RemoveNullSegments().

668  {
669  return Iterate( 0, OutlineCount() - 1, true );
670  }
ITERATOR Iterate()
Function Iterate.
int OutlineCount() const
Returns the number of outlines in the set
void SHAPE_POLY_SET::Move ( const VECTOR2I aVector)
overridevirtual

Implements SHAPE.

Definition at line 1527 of file shape_poly_set.cpp.

References m_polys.

Referenced by KIGFX::GERBVIEW_PAINTER::drawFlashedShape(), GERBER_DRAW_ITEM::HitTest(), and ZONE_CONTAINER::Move().

1528 {
1529  for( POLYGON& poly : m_polys )
1530  {
1531  for( SHAPE_LINE_CHAIN& path : poly )
1532  {
1533  path.Move( aVector );
1534  }
1535  }
1536 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
Class SHAPE_LINE_CHAIN.
int SHAPE_POLY_SET::NewHole ( int  aOutline = -1)

Creates a new hole in a given outline

Definition at line 161 of file shape_poly_set.cpp.

References m_polys, and SHAPE_LINE_CHAIN::SetClosed().

Referenced by ConvertOutlineToPolygon(), ConvertPolyListToPolySet(), ZONE_CONTAINER::NewHole(), and ZONE_CREATE_HELPER::performZoneCutout().

162 {
163  SHAPE_LINE_CHAIN empty_path;
164 
165  empty_path.SetClosed( true );
166 
167  // Default outline is the last one
168  if( aOutline < 0 )
169  aOutline += m_polys.size();
170 
171  // Add hole to the selected outline
172  m_polys[aOutline].push_back( empty_path );
173 
174  return m_polys.back().size() - 2;
175 }
void SetClosed(bool aClosed)
Function SetClosed()
Class SHAPE_LINE_CHAIN.
int SHAPE_POLY_SET::NewOutline ( )

Creates a new empty polygon in the set and returns its index

Definition at line 149 of file shape_poly_set.cpp.

References m_polys, and SHAPE_LINE_CHAIN::SetClosed().

Referenced by addHoleToPolygon(), ZONE_CONTAINER::AppendCorner(), BuildBoardPolygonOutlines(), D_PAD::buildCustomPadPolygon(), D_PAD::BuildPadShapePolygon(), BuildUnconnectedThermalStubsPolygonList(), ZONE_FILLER::buildZoneFeatureHoleList(), ConvertOutlineToPolygon(), ConvertPolyListToPolySet(), GERBER_DRAW_ITEM::ConvertSegmentToPolygon(), D_CODE::ConvertShapeToPolygon(), CreateThermalReliefPadPolygon(), KIGFX::PCB_PAINTER::draw(), GERBER_FILE_IMAGE::Execute_DCODE_Command(), fillArcPOLY(), getRectangleAlongCentreLine(), LEGACY_PLUGIN::loadZONE_CONTAINER(), CPolyLine::NormalizeAreaOutlines(), PCB_PARSER::parseZONE_CONTAINER(), DXF_PLOTTER::PlotPoly(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), DRAWSEGMENT::SetPolyPoints(), TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(), TransformCircleToPolygon(), TransformRingToPolygon(), TransformRoundedEndsSegmentToPolygon(), TransformRoundRectToPolygon(), DRAWSEGMENT::TransformShapeWithClearanceToPolygon(), and D_PAD::TransformShapeWithClearanceToPolygon().

150 {
151  SHAPE_LINE_CHAIN empty_path;
152  POLYGON poly;
153 
154  empty_path.SetClosed( true );
155  poly.push_back( empty_path );
156  m_polys.push_back( poly );
157  return m_polys.size() - 1;
158 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void SetClosed(bool aClosed)
Function SetClosed()
Class SHAPE_LINE_CHAIN.
int SHAPE_POLY_SET::NormalizeAreaOutlines ( )

Function NormalizeAreaOutlines Convert a self-intersecting polygon to one (or more) non self-intersecting polygon(s) Removes null segments.

Returns
int - the polygon count (always >= 1, because there is at least one polygon) There are new polygons only if the polygon count is > 1.

Definition at line 1079 of file shape_poly_set.cpp.

References AddOutline(), BooleanSubtract(), OutlineCount(), PM_FAST, PM_STRICTLY_SIMPLE, Polygon(), RemoveNullSegments(), and Simplify().

Referenced by BOARD::NormalizeAreaPolygon().

1080 {
1081  // We are expecting only one main outline, but this main outline can have holes
1082  // if holes: combine holes and remove them from the main outline.
1083  // Note also we are using SHAPE_POLY_SET::PM_STRICTLY_SIMPLE in polygon
1084  // calculations, but it is not mandatory. It is used mainly
1085  // because there is usually only very few vertices in area outlines
1086  SHAPE_POLY_SET::POLYGON& outline = Polygon( 0 );
1087  SHAPE_POLY_SET holesBuffer;
1088 
1089  // Move holes stored in outline to holesBuffer:
1090  // The first SHAPE_LINE_CHAIN is the main outline, others are holes
1091  while( outline.size() > 1 )
1092  {
1093  holesBuffer.AddOutline( outline.back() );
1094  outline.pop_back();
1095  }
1096 
1098 
1099  // If any hole, substract it to main outline
1100  if( holesBuffer.OutlineCount() )
1101  {
1102  holesBuffer.Simplify( SHAPE_POLY_SET::PM_FAST );
1104  }
1105 
1107 
1108  return OutlineCount();
1109 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
int OutlineCount() const
Returns the number of outlines in the set
Class SHAPE_POLY_SET.
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
int RemoveNullSegments()
Function RemoveNullSegments looks for null segments; ie, segments whose ends are exactly the same and...
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset difference For aFastMode meaning, see function booleanOp ...
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
SHAPE_POLY_SET & SHAPE_POLY_SET::operator= ( const SHAPE_POLY_SET aOther)

Definition at line 1865 of file shape_poly_set.cpp.

References m_hash, m_polys, m_triangulatedPolys, and m_triangulationValid.

1866 {
1867  static_cast<SHAPE&>(*this) = aOther;
1868  m_polys = aOther.m_polys;
1869 
1870  // reset poly cache:
1871  m_hash = MD5_HASH{};
1872  m_triangulationValid = false;
1873  m_triangulatedPolys.clear();
1874  return *this;
1875 }
std::vector< std::unique_ptr< TRIANGULATED_POLYGON > > m_triangulatedPolys
Class SHAPE.
Definition: shape.h:57
int SHAPE_POLY_SET::OutlineCount ( ) const
inline

Returns the number of outlines in the set

Definition at line 530 of file shape_poly_set.h.

References m_polys.

Referenced by POINT_EDITOR::addCorner(), ZONE_CONTAINER::AddPolygon(), CINFO3D_VISU::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), ZONE_CONTAINER::AppendCorner(), D_PAD::boundingRadius(), BuildBoardPolygonOutlines(), BuildConvexHull(), D_PAD::buildCustomPadPolygon(), CacheTriangulation(), DRC::checkClearancePadToPad(), CIterate(), CIterateWithHoles(), BOARD::CombineAreas(), Contains(), Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), Convert_shape_line_polygon_to_triangles(), D_PAD::CustomShapeAsPolygonToBoardPosition(), DRC::doFootprintOverlappingDrc(), KIGFX::GERBVIEW_PAINTER::draw(), DRAWSEGMENT::Draw(), KIGFX::PCB_PAINTER::draw(), GERBER_DRAW_ITEM::Draw(), KIGFX::GERBVIEW_PAINTER::drawApertureMacro(), APERTURE_MACRO::DrawApertureMacroShape(), ZONE_CONTAINER::DrawFilledArea(), D_CODE::DrawFlashedPolygon(), D_CODE::DrawFlashedShape(), KIGFX::GERBVIEW_PAINTER::drawFlashedShape(), KIGFX::CAIRO_GAL::DrawPolygon(), KIGFX::OPENGL_GAL::DrawPolygon(), KIGFX::GERBVIEW_PAINTER::drawPolygon(), D_PAD::DrawShape(), KIGFX::OPENGL_GAL::drawTriangulatedPolyset(), GERBER_FILE_IMAGE::Execute_DCODE_Command(), export_vrml_board(), export_vrml_zones(), fillArcPOLY(), DSN::SPECCTRA_DB::fillBOUNDARY(), ZONE_FILLER::fillZoneWithSegments(), HPGL_PLOTTER::FlashPadCustom(), PSLIKE_PLOTTER::FlashPadCustom(), GERBER_PLOTTER::FlashPadCustom(), DXF_PLOTTER::FlashPadCustom(), D_PAD::FlipPrimitives(), C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads(), C3D_RENDER_OGL_LEGACY::generate_holes_display_list(), APERTURE_MACRO::GetApertureMacroShape(), GERBER_DRAW_ITEM::GetBoundingBox(), D_PAD::GetBoundingBox(), GetRelativeIndices(), D_PAD::HitTest(), Iterate(), IterateSegments(), IterateSegmentsWithHoles(), IterateWithHoles(), D_PAD::MergePrimitivesAsPolygon(), GERBER_DRAW_ITEM::MoveAB(), GERBER_DRAW_ITEM::MoveXY(), CPolyLine::NormalizeAreaOutlines(), NormalizeAreaOutlines(), BRDITEMS_PLOTTER::PlotDrawSegment(), PlotLayerOutlines(), BRDITEMS_PLOTTER::PlotPad(), DXF_PLOTTER::PlotPoly(), Polygon_Calc_BBox_3DU(), C3D_RENDER_OGL_LEGACY::reload(), Subset(), PNS_KICAD_IFACE::syncPad(), and ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet().

530 { return m_polys.size(); }
bool SHAPE_POLY_SET::Parse ( std::stringstream &  aStream)
overridevirtual

Reimplemented from SHAPE.

Definition at line 1137 of file shape_poly_set.cpp.

References SHAPE_LINE_CHAIN::Append(), m_polys, SHAPE_LINE_CHAIN::SetClosed(), VECTOR2< T >::x, and VECTOR2< T >::y.

1138 {
1139  std::string tmp;
1140 
1141  aStream >> tmp;
1142 
1143  if( tmp != "polyset" )
1144  return false;
1145 
1146  aStream >> tmp;
1147 
1148  int n_polys = atoi( tmp.c_str() );
1149 
1150  if( n_polys < 0 )
1151  return false;
1152 
1153  for( int i = 0; i < n_polys; i++ )
1154  {
1155  POLYGON paths;
1156 
1157  aStream >> tmp;
1158 
1159  if( tmp != "poly" )
1160  return false;
1161 
1162  aStream >> tmp;
1163  int n_outlines = atoi( tmp.c_str() );
1164 
1165  if( n_outlines < 0 )
1166  return false;
1167 
1168  for( int j = 0; j < n_outlines; j++ )
1169  {
1170  SHAPE_LINE_CHAIN outline;
1171 
1172  outline.SetClosed( true );
1173 
1174  aStream >> tmp;
1175  int n_vertices = atoi( tmp.c_str() );
1176 
1177  for( int v = 0; v < n_vertices; v++ )
1178  {
1179  VECTOR2I p;
1180 
1181  aStream >> tmp; p.x = atoi( tmp.c_str() );
1182  aStream >> tmp; p.y = atoi( tmp.c_str() );
1183  outline.Append( p );
1184  }
1185 
1186  paths.push_back( outline );
1187  }
1188 
1189  m_polys.push_back( paths );
1190  }
1191 
1192  return true;
1193 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
void SetClosed(bool aClosed)
Function SetClosed()
Class SHAPE_LINE_CHAIN.
bool SHAPE_POLY_SET::pointInPolygon ( const VECTOR2I aP,
const SHAPE_LINE_CHAIN aPath 
) const
private

Definition at line 1462 of file shape_poly_set.cpp.

References SHAPE_LINE_CHAIN::BBox(), BOX2< Vec >::Contains(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::PointCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by containsSingle().

1463 {
1464  int result = 0;
1465  int cnt = aPath.PointCount();
1466 
1467  if( !aPath.BBox().Contains( aP ) ) // test with bounding box first
1468  return false;
1469 
1470  if( cnt < 3 )
1471  return false;
1472 
1473  VECTOR2I ip = aPath.CPoint( 0 );
1474 
1475  for( int i = 1; i <= cnt; ++i )
1476  {
1477  VECTOR2I ipNext = ( i == cnt ? aPath.CPoint( 0 ) : aPath.CPoint( i ) );
1478 
1479  if( ipNext.y == aP.y )
1480  {
1481  if( ( ipNext.x == aP.x ) || ( ip.y == aP.y
1482  && ( ( ipNext.x > aP.x ) == ( ip.x < aP.x ) ) ) )
1483  return true;
1484  }
1485 
1486  if( ( ip.y < aP.y ) != ( ipNext.y < aP.y ) )
1487  {
1488  if( ip.x >= aP.x )
1489  {
1490  if( ipNext.x > aP.x )
1491  result = 1 - result;
1492  else
1493  {
1494  int64_t d = (int64_t) ( ip.x - aP.x ) * (int64_t) ( ipNext.y - aP.y ) -
1495  (int64_t) ( ipNext.x - aP.x ) * (int64_t) ( ip.y - aP.y );
1496 
1497  if( !d )
1498  return true;
1499 
1500  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1501  result = 1 - result;
1502  }
1503  }
1504  else
1505  {
1506  if( ipNext.x > aP.x )
1507  {
1508  int64_t d = (int64_t) ( ip.x - aP.x ) * (int64_t) ( ipNext.y - aP.y ) -
1509  (int64_t) ( ipNext.x - aP.x ) * (int64_t) ( ip.y - aP.y );
1510 
1511  if( !d )
1512  return true;
1513 
1514  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1515  result = 1 - result;
1516  }
1517  }
1518  }
1519 
1520  ip = ipNext;
1521  }
1522 
1523  return result ? true : false;
1524 }
int PointCount() const
Function PointCount()
bool Contains(const Vec &aPoint) const
Function Contains.
Definition: box2.h:139
const BOX2I BBox(int aClearance=0) const override
Function BBox()
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool SHAPE_POLY_SET::PointOnEdge ( const VECTOR2I aP) const

Function PointOnEdge()

Checks if point aP lies on an edge or vertex of some of the outlines or holes.

Parameters
aPis the point to check.
Returns
bool - true if the point lies on the edge of any polygon.

Definition at line 1213 of file shape_poly_set.cpp.

References m_polys.

1214 {
1215  // Iterate through all the polygons in the set
1216  for( const POLYGON& polygon : m_polys )
1217  {
1218  // Iterate through all the line chains in the polygon
1219  for( const SHAPE_LINE_CHAIN& lineChain : polygon )
1220  {
1221  if( lineChain.PointOnEdge( aP ) )
1222  return true;
1223  }
1224  }
1225 
1226  return false;
1227 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
Class SHAPE_LINE_CHAIN.
const POLYGON& SHAPE_POLY_SET::Polygon ( int  aIndex) const
inline

Definition at line 580 of file shape_poly_set.h.

References m_polys.

581  {
582  return m_polys[aIndex];
583  }
void SHAPE_POLY_SET::RemoveContour ( int  aContourIdx,
int  aPolygonIdx = -1 
)

Function RemoveContour deletes the aContourIdx-th contour of the aPolygonIdx-th polygon in the set.

Parameters
aContourIdxis the index of the contour in the aPolygonIdx-th polygon to be removed.
aPolygonIdxis the index of the polygon in which the to-be-removed contour is. Defaults to the last polygon in the set.

Definition at line 1252 of file shape_poly_set.cpp.

References m_polys.

Referenced by PCB_EDIT_FRAME::Delete_Zone_Contour(), and POINT_EDITOR::removeCorner().

1253 {
1254  // Default polygon is the last one
1255  if( aPolygonIdx < 0 )
1256  aPolygonIdx += m_polys.size();
1257 
1258  m_polys[aPolygonIdx].erase( m_polys[aPolygonIdx].begin() + aContourIdx );
1259 }
int SHAPE_POLY_SET::RemoveNullSegments ( )

Function RemoveNullSegments looks for null segments; ie, segments whose ends are exactly the same and deletes them.

Returns
int - the number of deleted segments.

Definition at line 1262 of file shape_poly_set.cpp.

References SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::GetIndex(), SHAPE_POLY_SET::ITERATOR_TEMPLATE< T >::IsEndContour(), IterateWithHoles(), and RemoveVertex().

Referenced by chamferFilletPolygon(), PCB_EDIT_FRAME::End_Zone(), and NormalizeAreaOutlines().

1263 {
1264  int removed = 0;
1265 
1266  ITERATOR iterator = IterateWithHoles();
1267 
1268  VECTOR2I contourStart = *iterator;
1269  VECTOR2I segmentStart, segmentEnd;
1270 
1271  VERTEX_INDEX indexStart;
1272 
1273  while( iterator )
1274  {
1275  // Obtain first point and its index
1276  segmentStart = *iterator;
1277  indexStart = iterator.GetIndex();
1278 
1279  // Obtain last point
1280  if( iterator.IsEndContour() )
1281  {
1282  segmentEnd = contourStart;
1283 
1284  // Advance
1285  iterator++;
1286 
1287  if( iterator )
1288  contourStart = *iterator;
1289  }
1290  else
1291  {
1292  // Advance
1293  iterator++;
1294 
1295  if( iterator )
1296  segmentEnd = *iterator;
1297  }
1298 
1299  // Remove segment start if both points are equal
1300  if( segmentStart == segmentEnd )
1301  {
1302  RemoveVertex( indexStart );
1303  removed++;
1304 
1305  // Advance the iterator one position, as there is one vertex less.
1306  if( iterator )
1307  iterator++;
1308  }
1309  }
1310 
1311  return removed;
1312 }
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
ITERATOR IterateWithHoles()
Function IterateWithHoles.
void RemoveVertex(int aGlobalIndex)
Function RemoveVertex deletes the aGlobalIndex-th vertex.
void SHAPE_POLY_SET::RemoveVertex ( int  aGlobalIndex)

Function RemoveVertex deletes the aGlobalIndex-th vertex.

Parameters
aGlobalIndexis the global index of the to-be-removed vertex.

Definition at line 1421 of file shape_poly_set.cpp.

References GetRelativeIndices().

Referenced by Abort_Zone_Move_Corner_Or_Outlines(), PCB_EDIT_FRAME::Delete_LastCreatedCorner(), PCB_EDIT_FRAME::Remove_Zone_Corner(), POINT_EDITOR::removeCorner(), RemoveNullSegments(), and PCB_EDIT_FRAME::Start_Move_Zone_Corner().

1422 {
1423  VERTEX_INDEX index;
1424 
1425  // Assure the to be removed vertex exists, abort otherwise
1426  if( GetRelativeIndices( aGlobalIndex, &index ) )
1427  RemoveVertex( index );
1428  else
1429  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
1430 }
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
void RemoveVertex(int aGlobalIndex)
Function RemoveVertex deletes the aGlobalIndex-th vertex.
void SHAPE_POLY_SET::RemoveVertex ( VERTEX_INDEX  aRelativeIndices)

Function RemoveVertex deletes the vertex indexed by aIndex (index of polygon, contour and vertex).

Parameters
aRelativeIndicesis the set of relative indices of the to-be-removed vertex.

Definition at line 1433 of file shape_poly_set.cpp.

References SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, m_polys, and SHAPE_POLY_SET::VERTEX_INDEX::m_vertex.

1434 {
1435  m_polys[aIndex.m_polygon][aIndex.m_contour].Remove( aIndex.m_vertex );
1436 }
void SHAPE_POLY_SET::Simplify ( POLYGON_MODE  aFastMode)

Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMode meaning, see function booleanOp

Definition at line 1071 of file shape_poly_set.cpp.

References booleanOp(), and empty().

Referenced by CINFO3D_VISU::AddShapeWithClearanceToContainer(), CINFO3D_VISU::AddSolidAreasShapesToContainer(), D_PAD::buildCustomPadPolygon(), BOARD::CombineAreas(), ZONE_FILLER::computeRawFilledAreas(), CINFO3D_VISU::createBoardPolygon(), CINFO3D_VISU::createLayers(), CINFO3D_VISU::createNewPadWithClearance(), CreateThermalReliefPadPolygon(), Fracture(), BOARD::GetBoardPolygonOutlines(), CPolyLine::NormalizeAreaOutlines(), NormalizeAreaOutlines(), PlotLayerOutlines(), ZONE_CONTAINER::TransformShapeWithClearanceToPolygon(), and Unfracture().

1072 {
1074 
1075  booleanOp( ctUnion, empty, aFastMode );
1076 }
void booleanOp(ClipperLib::ClipType aType, const SHAPE_POLY_SET &aOtherShape, POLYGON_MODE aFastMode)
Function booleanOp this is the engine to execute all polygon boolean transforms (AND, OR, ...
Class SHAPE_POLY_SET.
static bool empty(const wxTextEntryBase *aCtrl)
SHAPE_POLY_SET SHAPE_POLY_SET::Subset ( int  aFirstPolygon,
int  aLastPolygon 
)

Function Subset returns a subset of the polygons in this set, the ones between aFirstPolygon and aLastPolygon.

Parameters
aFirstPolygonis the first polygon to be included in the returned set.
aLastPolygonis the first polygon to be excluded of the returned set.
Returns
SHAPE_POLY_SET - a set containing the polygons between aFirstPolygon (included) and aLastPolygon (excluded).

Definition at line 246 of file shape_poly_set.cpp.

References m_polys, OutlineCount(), and Polygon().

Referenced by UnitSet().

247 {
248  assert( aFirstPolygon >= 0 && aLastPolygon <= OutlineCount() );
249 
250  SHAPE_POLY_SET newPolySet;
251 
252  for( int index = aFirstPolygon; index < aLastPolygon; index++ )
253  {
254  newPolySet.m_polys.push_back( Polygon( index ) );
255  }
256 
257  return newPolySet;
258 }
int OutlineCount() const
Returns the number of outlines in the set
Class SHAPE_POLY_SET.
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
int SHAPE_POLY_SET::TotalVertices ( ) const

Returns total number of vertices stored in the set.

Definition at line 1539 of file shape_poly_set.cpp.

References m_polys.

Referenced by EDIT_POINTS_FACTORY::buildForPolyOutline(), ZONE_CONTAINER::GetMsgPanelInfo(), ZONE_CONTAINER::GetNumCorners(), ZONE_CONTAINER::HitTest(), InsertVertex(), PCB_EDIT_FRAME::Remove_Zone_Corner(), POINT_EDITOR::updateItem(), and POINT_EDITOR::updatePoints().

1540 {
1541  int c = 0;
1542 
1543  for( const POLYGON& poly : m_polys )
1544  {
1545  for( const SHAPE_LINE_CHAIN& path : poly )
1546  {
1547  c += path.PointCount();
1548  }
1549  }
1550 
1551  return c;
1552 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
Class SHAPE_LINE_CHAIN.
const TRIANGULATED_POLYGON* SHAPE_POLY_SET::TriangulatedPolygon ( int  aIndex) const
inline

Definition at line 585 of file shape_poly_set.h.

References m_triangulatedPolys.

Referenced by KIGFX::OPENGL_GAL::drawTriangulatedPolyset().

586  {
587  return m_triangulatedPolys[aIndex].get();
588  }
std::vector< std::unique_ptr< TRIANGULATED_POLYGON > > m_triangulatedPolys
void SHAPE_POLY_SET::triangulateSingle ( const POLYGON aPoly,
SHAPE_POLY_SET::TRIANGULATED_POLYGON aResult 
)
private

Definition at line 1940 of file shape_poly_set.cpp.

References SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::a, SHAPE_POLY_SET::TRIANGULATED_POLYGON::AllocateTriangles(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::AllocateVertices(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::b, SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::c, convert(), SHAPE_POLY_SET::TRIANGULATED_POLYGON::m_triangles, and totalVertexCount().

Referenced by CacheTriangulation().

1942 {
1943  assert( aPoly.size() >= 1 );
1944 
1945  P2T_MAP pointMap;
1946  P2T_VEC outline;
1947 
1948  aResult.AllocateVertices( totalVertexCount( aPoly ) );
1949 
1950  convert( aPoly[0], outline, pointMap, aResult );
1951 
1952  std::unique_ptr<p2t::CDT> cdt( new p2t::CDT( outline ) );
1953 
1954  for( unsigned i = 1; i < aPoly.size(); i++ )
1955  {
1956  std::vector<p2t::Point*> hole;
1957 
1958  convert( aPoly[i], hole, pointMap, aResult );
1959 
1960  cdt->AddHole( hole );
1961  }
1962 
1963  cdt->Triangulate();
1964 
1965  aResult.AllocateTriangles( cdt->GetTriangles().size() );
1966 
1967  int i = 0;
1968 
1969  for( auto tri : cdt->GetTriangles() )
1970  {
1971  TRIANGULATED_POLYGON::TRI t;
1972 
1973  t.a = pointMap[ tri->GetPoint( 0 ) ];
1974  t.b = pointMap[ tri->GetPoint( 1 ) ];
1975  t.c = pointMap[ tri->GetPoint( 2 ) ];
1976 
1977  aResult.m_triangles[ i ] = t;
1978  i++;
1979  }
1980 
1981  for( auto iter = pointMap.begin(); iter!=pointMap.end(); ++iter )
1982  delete iter->first;
1983 }
static void convert(const SHAPE_LINE_CHAIN &outl, P2T_VEC &buffer, P2T_MAP &pointMap, SHAPE_POLY_SET::TRIANGULATED_POLYGON &aPoly)
static int totalVertexCount(const SHAPE_POLY_SET::POLYGON &aPoly)
std::vector< p2t::Point * > P2T_VEC
Definition: cdt.h:47
std::map< p2t::Point *, int > P2T_MAP
SHAPE_TYPE SHAPE::Type ( ) const
inlineinherited

Function Type()

Returns the type of the shape.

Return values
thetype

Definition at line 82 of file shape.h.

References SHAPE::m_type.

Referenced by PNS::DP_GATEWAYS::BuildFromPrimitivePair(), CollideShapes(), PNS::OPTIMIZER::computeBreakouts(), PNS::LOGGER::dumpShape(), PNS::SOLID::Hull(), ROUTER_PREVIEW_ITEM::ViewDraw(), and SHAPE_FILE_IO::Write().

83  {
84  return m_type;
85  }
SHAPE_TYPE m_type
type of our shape
Definition: shape.h:165
void SHAPE_POLY_SET::Unfracture ( POLYGON_MODE  aFastMode)

Converts a single outline slitted ("fractured") polygon into a set ouf outlines with holes.

Definition at line 1060 of file shape_poly_set.cpp.

References m_polys, Simplify(), and unfractureSingle().

Referenced by CacheTriangulation().

1061 {
1062  for( POLYGON& path : m_polys )
1063  {
1064  unfractureSingle( path );
1065  }
1066 
1067  Simplify( aFastMode ); // remove overlapping holes/degeneracy
1068 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
void unfractureSingle(POLYGON &path)
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
void SHAPE_POLY_SET::unfractureSingle ( SHAPE_POLY_SET::POLYGON aPoly)
private

Definition at line 882 of file shape_poly_set.cpp.

References SEG::A, SHAPE_LINE_CHAIN::Append(), SHAPE_LINE_CHAIN::Area(), SEG::B, SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::CSegment(), next(), operator!=(), operator==(), and SHAPE_LINE_CHAIN::SetClosed().

Referenced by Unfracture().

883 {
884  assert( aPoly.size() == 1 );
885 
886  struct EDGE
887  {
888  int m_index = 0;
889  SHAPE_LINE_CHAIN* m_poly = nullptr;
890  bool m_duplicate = false;
891 
892  EDGE( SHAPE_LINE_CHAIN* aPolygon, int aIndex ) :
893  m_index( aIndex ),
894  m_poly( aPolygon )
895  {}
896 
897  bool compareSegs( const SEG& s1, const SEG& s2 ) const
898  {
899  return (s1.A == s2.A && s1.B == s2.B) || (s1.A == s2.B && s1.B == s2.A);
900  }
901 
902  bool operator==( const EDGE& aOther ) const
903  {
904  return compareSegs( m_poly->CSegment( m_index ),
905  aOther.m_poly->CSegment( aOther.m_index ) );
906  }
907 
908  bool operator!=( const EDGE& aOther ) const
909  {
910  return !compareSegs( m_poly->CSegment( m_index ),
911  aOther.m_poly->CSegment( aOther.m_index ) );
912  }
913 
914  struct HASH
915  {
916  std::size_t operator()( const EDGE& aEdge ) const
917  {
918  const auto& a = aEdge.m_poly->CSegment( aEdge.m_index );
919 
920  return (std::size_t) ( a.A.x + a.B.x + a.A.y + a.B.y );
921  }
922  };
923  };
924 
925  struct EDGE_LIST_ENTRY
926  {
927  int index;
928  EDGE_LIST_ENTRY* next;
929  };
930 
931  std::unordered_set<EDGE, EDGE::HASH> uniqueEdges;
932 
933  auto lc = aPoly[0];
934  lc.Simplify();
935 
936  auto edgeList = std::make_unique<EDGE_LIST_ENTRY []>( lc.SegmentCount() );
937 
938  for( int i = 0; i < lc.SegmentCount(); i++ )
939  {
940  edgeList[i].index = i;
941  edgeList[i].next = &edgeList[ (i != lc.SegmentCount() - 1) ? i + 1 : 0 ];
942  }
943 
944  std::unordered_set<EDGE_LIST_ENTRY*> queue;
945 
946  for( int i = 0; i < lc.SegmentCount(); i++ )
947  {
948  EDGE e( &lc, i );
949  uniqueEdges.insert( e );
950  }
951 
952  for( int i = 0; i < lc.SegmentCount(); i++ )
953  {
954  EDGE e( &lc, i );
955  auto it = uniqueEdges.find( e );
956 
957  if( it != uniqueEdges.end() && it->m_index != i )
958  {
959  int e1 = it->m_index;
960  int e2 = i;
961 
962  if( e1 > e2 )
963  std::swap( e1, e2 );
964 
965  int e1_prev = e1 - 1;
966 
967  if( e1_prev < 0 )
968  e1_prev = lc.SegmentCount() - 1;
969 
970  int e2_prev = e2 - 1;
971 
972  if( e2_prev < 0 )
973  e2_prev = lc.SegmentCount() - 1;
974 
975  int e1_next = e1 + 1;
976 
977  if( e1_next == lc.SegmentCount() )
978  e1_next = 0;
979 
980  int e2_next = e2 + 1;
981 
982  if( e2_next == lc.SegmentCount() )
983  e2_next = 0;
984 
985  edgeList[e1_prev].next = &edgeList[ e2_next ];
986  edgeList[e2_prev].next = &edgeList[ e1_next ];
987  edgeList[i].next = nullptr;
988  edgeList[it->m_index].next = nullptr;
989  }
990  }
991 
992  for( int i = 0; i < lc.SegmentCount(); i++ )
993  {
994  if( edgeList[i].next )
995  queue.insert( &edgeList[i] );
996  }
997 
998  auto edgeBuf = std::make_unique<EDGE_LIST_ENTRY* []>( lc.SegmentCount() );
999 
1000  int n = 0;
1001  int outline = -1;
1002 
1003  POLYGON result;
1004 
1005  while( queue.size() )
1006  {
1007  auto e_first = (*queue.begin() );
1008  auto e = e_first;
1009  int cnt = 0;
1010 
1011  do {
1012  edgeBuf[cnt++] = e;
1013  e = e->next;
1014  } while( e != e_first );
1015 
1016  SHAPE_LINE_CHAIN outl;
1017 
1018  for( int i = 0; i < cnt; i++ )
1019  {
1020  auto p = lc.CPoint( edgeBuf[i]->index );
1021  outl.Append( p );
1022  queue.erase( edgeBuf[i] );
1023  }
1024 
1025  outl.SetClosed( true );
1026 
1027  bool cw = outl.Area() > 0.0;
1028 
1029  if( cw )
1030  outline = n;
1031 
1032  result.push_back( outl );
1033  n++;
1034  }
1035 
1036  assert( outline >= 0 );
1037 
1038  if( outline !=0 )
1039  std::swap( result[0], result[outline] );
1040 
1041  aPoly = result;
1042 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
CITER next(CITER it)
Definition: ptree.cpp:130
bool operator==(const PART_LIB &aLibrary, const wxString &aName)
Case insensitive library name comparison.
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
const SEG CSegment(int aIndex) const
Function CSegment()
void SetClosed(bool aClosed)
Function SetClosed()
Definition: seg.h:36
Class SHAPE_LINE_CHAIN.
double Area() const
VECTOR2I A
Definition: seg.h:46
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
bool operator!=(const PART_LIB &aLibrary, const wxString &aName)
VECTOR2I B
Definition: seg.h:47
SHAPE_POLY_SET SHAPE_POLY_SET::UnitSet ( int  aPolygonIndex)
inline

Definition at line 563 of file shape_poly_set.h.

References Subset().

Referenced by BOARD::NormalizeAreaPolygon().

564  {
565  return Subset( aPolygonIndex, aPolygonIndex + 1 );
566  }
SHAPE_POLY_SET Subset(int aFirstPolygon, int aLastPolygon)
Function Subset returns a subset of the polygons in this set, the ones between aFirstPolygon and aLas...
VECTOR2I & SHAPE_POLY_SET::Vertex ( int  aIndex,
int  aOutline,
int  aHole 
)

Returns the index-th vertex in a given hole outline within a given outline

Definition at line 261 of file shape_poly_set.cpp.

References m_polys.

Referenced by Abort_Zone_Move_Corner_Or_Outlines(), POINT_EDITOR::addCorner(), DRC::doFootprintOverlappingDrc(), D_CODE::DrawFlashedPolygon(), GERBER_FILE_IMAGE::Execute_DCODE_Command(), GERBER_FILE_IMAGE::Execute_G_Command(), findVertex(), ZONE_CONTAINER::Hatch(), ZONE_CONTAINER::HitTest(), ZONE_CONTAINER::MoveEdge(), ZONE_CONTAINER::SetCornerPosition(), Show_Zone_Corner_Or_Outline_While_Move_Mouse(), PCB_EDIT_FRAME::Start_Move_Zone_Corner(), POINT_EDITOR::updateItem(), and Vertex().

262 {
263  if( aOutline < 0 )
264  aOutline += m_polys.size();
265 
266  int idx;
267 
268  if( aHole < 0 )
269  idx = 0;
270  else
271  idx = aHole + 1;
272 
273  assert( aOutline < (int) m_polys.size() );
274  assert( idx < (int) m_polys[aOutline].size() );
275 
276  return m_polys[aOutline][idx].Point( aIndex );
277 }
VECTOR2I & SHAPE_POLY_SET::Vertex ( int  aGlobalIndex)

Returns the aGlobalIndex-th vertex in the poly set

Definition at line 299 of file shape_poly_set.cpp.

References GetRelativeIndices(), SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, m_polys, and SHAPE_POLY_SET::VERTEX_INDEX::m_vertex.

300 {
302 
303  // Assure the passed index references a legal position; abort otherwise
304  if( !GetRelativeIndices( aGlobalIndex, &index ) )
305  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
306 
307  return m_polys[index.m_polygon][index.m_contour].Point( index.m_vertex );
308 }
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
VECTOR2I & SHAPE_POLY_SET::Vertex ( SHAPE_POLY_SET::VERTEX_INDEX  index)

Returns the index-th vertex in a given hole outline within a given outline

Definition at line 323 of file shape_poly_set.cpp.

References SHAPE_POLY_SET::VERTEX_INDEX::m_contour, SHAPE_POLY_SET::VERTEX_INDEX::m_polygon, SHAPE_POLY_SET::VERTEX_INDEX::m_vertex, and Vertex().

324 {
325  return Vertex( index.m_vertex, index.m_polygon, index.m_contour - 1 );
326 }
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
VECTOR2I& SHAPE_POLY_SET::vertex ( int  aCornerId)
private

Referenced by convertToClipper().

int SHAPE_POLY_SET::VertexCount ( int  aOutline = -1,
int  aHole = -1 
) const

Returns the number of vertices in a given outline/hole

Definition at line 221 of file shape_poly_set.cpp.

References m_polys.

Referenced by D_CODE::DrawFlashedPolygon().

222 {
223  if( m_polys.size() == 0 ) // Empty poly set
224  return 0;
225 
226  if( aOutline < 0 ) // Use last outline
227  aOutline += m_polys.size();
228 
229  int idx;
230 
231  if( aHole < 0 )
232  idx = 0;
233  else
234  idx = aHole + 1;
235 
236  if( aOutline >= (int) m_polys.size() ) // not existing outline
237  return 0;
238 
239  if( idx >= (int) m_polys[aOutline].size() ) // not existing hole
240  return 0;
241 
242  return m_polys[aOutline][idx].PointCount();
243 }

Member Data Documentation

MD5_HASH SHAPE_POLY_SET::m_hash
private

Definition at line 1134 of file shape_poly_set.h.

Referenced by CacheTriangulation(), IsTriangulationUpToDate(), and operator=().

std::vector<std::unique_ptr<TRIANGULATED_POLYGON> > SHAPE_POLY_SET::m_triangulatedPolys
private

Definition at line 1132 of file shape_poly_set.h.

Referenced by CacheTriangulation(), operator=(), and TriangulatedPolygon().

bool SHAPE_POLY_SET::m_triangulationValid = false
private

Definition at line 1133 of file shape_poly_set.h.

Referenced by CacheTriangulation(), IsTriangulationUpToDate(), and operator=().

SHAPE_TYPE SHAPE::m_type
protectedinherited

type of our shape

Definition at line 165 of file shape.h.

Referenced by SHAPE::Type().


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