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  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...
 
 ~SHAPE_POLY_SET ()
 
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 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...
 
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 point)
 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_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 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...
 

Private Attributes

Polyset m_polys
 

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 53 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 58 of file shape_poly_set.h.

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

Definition at line 1060 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 1037 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 724 of file shape_poly_set.h.

Constructor & Destructor Documentation

SHAPE_POLY_SET::SHAPE_POLY_SET ( )

Definition at line 44 of file shape_poly_set.cpp.

Referenced by Clone(), and Collide().

44  :
46 {
47 }
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 50 of file shape_poly_set.cpp.

50  :
51  SHAPE( SH_POLY_SET ), m_polys( aOther.m_polys )
52 {
53 }
SHAPE(SHAPE_TYPE aType)
Constructor.
Definition: shape.h:69
convex polygon
Definition: shape.h:48
SHAPE_POLY_SET::~SHAPE_POLY_SET ( )

Definition at line 56 of file shape_poly_set.cpp.

57 {
58 }

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 431 of file shape_poly_set.cpp.

References m_polys.

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

432 {
433  assert ( m_polys.size() );
434 
435  if( aOutline < 0 )
436  aOutline += m_polys.size();
437 
438  POLYGON& poly = m_polys[aOutline];
439 
440  assert( poly.size() );
441 
442  poly.push_back( aHole );
443 
444  return poly.size() - 1;
445 }
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 417 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(), CPolyLine::NormalizeAreaOutlines(), and NormalizeAreaOutlines().

418 {
419  assert( aOutline.IsClosed() );
420 
421  POLYGON poly;
422 
423  poly.push_back( aOutline );
424 
425  m_polys.push_back( poly );
426 
427  return m_polys.size() - 1;
428 }
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 177 of file shape_poly_set.cpp.

References m_polys.

Referenced by ZONE_CONTAINER::AddFilledPolygon(), Append(), ZONE_CONTAINER::AppendCorner(), BuildBoardPolygonOutlines(), ZONE_CONTAINER::BuildFilledSolidAreasPolygons(), D_PAD::BuildPadShapePolygon(), BuildUnconnectedThermalStubsPolygonList(), ConvertOutlineToPolygon(), ConvertPolyListToPolySet(), CreateThermalReliefPadPolygon(), DRC::doFootprintOverlappingDrc(), KIGFX::PCB_PAINTER::draw(), 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(), TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(), TransformCircleToPolygon(), ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(), TransformRingToPolygon(), TransformRoundedEndsSegmentToPolygon(), TransformRoundRectToPolygon(), DRAWSEGMENT::TransformShapeWithClearanceToPolygon(), D_PAD::TransformShapeWithClearanceToPolygon(), ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet(), and ZONE_CONTAINER::ZONE_CONTAINER().

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

Merges polygons from two sets.

Definition at line 1122 of file shape_poly_set.cpp.

References m_polys.

1123 {
1124  m_polys.insert( m_polys.end(), aSet.m_polys.begin(), aSet.m_polys.end() );
1125 }
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 1128 of file shape_poly_set.cpp.

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

1129 {
1130  Append( aP.x, aP.y, aOutline, aHole );
1131 }
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 997 of file shape_poly_set.cpp.

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

Referenced by BOARD::CombineAllAreasInNet(), Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), BOARD::TestAreaIntersection(), KIGFX::PREVIEW::POLYGON_ITEM::ViewBBox(), and KIGFX::PREVIEW::CENTRELINE_RECT_ITEM::ViewBBox().

998 {
999  BOX2I bb;
1000 
1001  for( unsigned i = 0; i < m_polys.size(); i++ )
1002  {
1003  if( i == 0 )
1004  bb = m_polys[i][0].BBox();
1005  else
1006  bb.Merge( m_polys[i][0].BBox() );
1007  }
1008 
1009  bb.Inflate( aClearance );
1010  return bb;
1011 }
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 536 of file shape_poly_set.cpp.

References booleanOp().

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

537 {
538  booleanOp( ctUnion, b, aFastMode );
539 }
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 554 of file shape_poly_set.cpp.

References booleanOp().

555 {
556  booleanOp( ctUnion, a, b, aFastMode );
557 }
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 548 of file shape_poly_set.cpp.

References booleanOp().

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

549 {
550  booleanOp( ctIntersection, b, aFastMode );
551 }
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 566 of file shape_poly_set.cpp.

References booleanOp().

567 {
568  booleanOp( ctIntersection, a, b, aFastMode );
569 }
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

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

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 506 of file shape_poly_set.cpp.

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

510 {
511  Clipper c;
512 
513  if( aFastMode == PM_STRICTLY_SIMPLE )
514  c.StrictlySimple( true );
515 
516  for( const POLYGON& poly : aShape.m_polys )
517  {
518  for( unsigned int i = 0; i < poly.size(); i++ )
519  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptSubject, true );
520  }
521 
522  for( const POLYGON& poly : aOtherShape.m_polys )
523  {
524  for( unsigned int i = 0; i < poly.size(); i++ )
525  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptClip, true );
526  }
527 
528  PolyTree solution;
529 
530  c.Execute( aType, solution, pftNonZero, pftNonZero );
531 
532  importTree( &solution );
533 }
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 542 of file shape_poly_set.cpp.

References booleanOp().

Referenced by ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList_NG(), CreateThermalReliefPadPolygon(), APERTURE_MACRO::DrawApertureMacroShape(), C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads(), CPolyLine::NormalizeAreaOutlines(), and NormalizeAreaOutlines().

543 {
544  booleanOp( ctDifference, b, aFastMode );
545 }
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 560 of file shape_poly_set.cpp.

References booleanOp().

561 {
562  booleanOp( ctDifference, a, b, aFastMode );
563 }
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, ...
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 1480 of file shape_poly_set.cpp.

References ChamferPolygon(), and m_polys.

Referenced by ZONE_CONTAINER::BuildFilledSolidAreasPolygons().

1481 {
1482  SHAPE_POLY_SET chamfered;
1483 
1484  for( unsigned int polygonIdx = 0; polygonIdx < m_polys.size(); polygonIdx++ )
1485  chamfered.m_polys.push_back( ChamferPolygon( aDistance, polygonIdx ) );
1486 
1487  return chamfered;
1488 }
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 1502 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().

1506 {
1507  // Null segments create serious issues in calculations. Remove them:
1509 
1510  SHAPE_POLY_SET::POLYGON currentPoly = Polygon( aIndex );
1511  SHAPE_POLY_SET::POLYGON newPoly;
1512 
1513  // If the chamfering distance is zero, then the polygon remain intact.
1514  if( aDistance == 0 )
1515  {
1516  return currentPoly;
1517  }
1518 
1519  // Iterate through all the contours (outline and holes) of the polygon.
1520  for( SHAPE_LINE_CHAIN &currContour : currentPoly )
1521  {
1522  // Generate a new contour in the new polygon
1523  SHAPE_LINE_CHAIN newContour;
1524 
1525  // Iterate through the vertices of the contour
1526  for( int currVertex = 0; currVertex < currContour.PointCount(); currVertex++ )
1527  {
1528  // Current vertex
1529  int x1 = currContour.Point( currVertex ).x;
1530  int y1 = currContour.Point( currVertex ).y;
1531 
1532  // Indices for previous and next vertices.
1533  int prevVertex;
1534  int nextVertex;
1535 
1536  // Previous and next vertices indices computation. Necessary to manage the edge cases.
1537 
1538  // Previous vertex is the last one if the current vertex is the first one
1539  prevVertex = currVertex == 0 ? currContour.PointCount() - 1 : currVertex - 1;
1540 
1541  // next vertex is the first one if the current vertex is the last one.
1542  nextVertex = currVertex == currContour.PointCount() - 1 ? 0 : currVertex + 1;
1543 
1544  // Previous vertex computation
1545  double xa = currContour.Point( prevVertex ).x - x1;
1546  double ya = currContour.Point( prevVertex ).y - y1;
1547 
1548  // Next vertex computation
1549  double xb = currContour.Point( nextVertex ).x - x1;
1550  double yb = currContour.Point( nextVertex ).y - y1;
1551 
1552  // Compute the new distances
1553  double lena = hypot( xa, ya );
1554  double lenb = hypot( xb, yb );
1555 
1556  // Make the final computations depending on the mode selected, chamfered or filleted.
1557  if( aMode == CORNER_MODE::CHAMFERED )
1558  {
1559  double distance = aDistance;
1560 
1561  // Chamfer one half of an edge at most
1562  if( 0.5 * lena < distance )
1563  distance = 0.5 * lena;
1564 
1565  if( 0.5 * lenb < distance )
1566  distance = 0.5 * lenb;
1567 
1568  int nx1 = KiROUND( distance * xa / lena );
1569  int ny1 = KiROUND( distance * ya / lena );
1570 
1571  newContour.Append( x1 + nx1, y1 + ny1 );
1572 
1573  int nx2 = KiROUND( distance * xb / lenb );
1574  int ny2 = KiROUND( distance * yb / lenb );
1575 
1576  newContour.Append( x1 + nx2, y1 + ny2 );
1577  }
1578  else // CORNER_MODE = FILLETED
1579  {
1580  double cosine = ( xa * xb + ya * yb ) / ( lena * lenb );
1581 
1582  double radius = aDistance;
1583  double denom = sqrt( 2.0 / ( 1 + cosine ) - 1 );
1584 
1585  // Do nothing in case of parallel edges
1586  if( std::isinf( denom ) )
1587  continue;
1588 
1589  // Limit rounding distance to one half of an edge
1590  if( 0.5 * lena * denom < radius )
1591  radius = 0.5 * lena * denom;
1592 
1593  if( 0.5 * lenb * denom < radius )
1594  radius = 0.5 * lenb * denom;
1595 
1596  // Calculate fillet arc absolute center point (xc, yx)
1597  double k = radius / sqrt( .5 * ( 1 - cosine ) );
1598  double lenab = sqrt( ( xa / lena + xb / lenb ) * ( xa / lena + xb / lenb ) +
1599  ( ya / lena + yb / lenb ) * ( ya / lena + yb / lenb ) );
1600  double xc = x1 + k * ( xa / lena + xb / lenb ) / lenab;
1601  double yc = y1 + k * ( ya / lena + yb / lenb ) / lenab;
1602 
1603  // Calculate arc start and end vectors
1604  k = radius / sqrt( 2 / ( 1 + cosine ) - 1 );
1605  double xs = x1 + k * xa / lena - xc;
1606  double ys = y1 + k * ya / lena - yc;
1607  double xe = x1 + k * xb / lenb - xc;
1608  double ye = y1 + k * yb / lenb - yc;
1609 
1610  // Cosine of arc angle
1611  double argument = ( xs * xe + ys * ye ) / ( radius * radius );
1612 
1613  // Make sure the argument is in [-1,1], interval in which the acos function is
1614  // defined
1615  if( argument < -1 )
1616  argument = -1;
1617  else if( argument > 1 )
1618  argument = 1;
1619 
1620  double arcAngle = acos( argument );
1621 
1622  // Calculate the number of segments
1623  unsigned int segments = ceil( (double) aSegments * ( arcAngle / ( 2 * M_PI ) ) );
1624 
1625  double deltaAngle = arcAngle / segments;
1626  double startAngle = atan2( -ys, xs );
1627 
1628  // Flip arc for inner corners
1629  if( xa * yb - ya * xb <= 0 )
1630  deltaAngle *= -1;
1631 
1632  double nx = xc + xs;
1633  double ny = yc + ys;
1634 
1635  newContour.Append( KiROUND( nx ), KiROUND( ny ) );
1636 
1637  // Store the previous added corner to make a sanity check
1638  int prevX = KiROUND( nx );
1639  int prevY = KiROUND( ny );
1640 
1641  for( unsigned int j = 0; j < segments; j++ )
1642  {
1643  nx = xc + cos( startAngle + (j + 1) * deltaAngle ) * radius;
1644  ny = yc - sin( startAngle + (j + 1) * deltaAngle ) * radius;
1645 
1646  // Sanity check: the rounding can produce repeated corners; do not add them.
1647  if( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY )
1648  {
1649  newContour.Append( KiROUND( nx ), KiROUND( ny ) );
1650  prevX = KiROUND( nx );
1651  prevY = KiROUND( ny );
1652  }
1653  }
1654  }
1655  }
1656 
1657  // Close the current contour and add it the new polygon
1658  newContour.SetClosed( true );
1659  newPoly.push_back( newContour );
1660  }
1661 
1662  return newPoly;
1663 }
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 1356 of file shape_poly_set.cpp.

References chamferFilletPolygon().

Referenced by Chamfer().

1357 {
1358  return chamferFilletPolygon( CORNER_MODE::CHAMFERED, aDistance, aIndex );
1359 }
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 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 624 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 PCB_IO::format(), and BRDITEMS_PLOTTER::PlotFilledAreas().

625  {
626  CONST_ITERATOR iter;
627 
628  iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
629  iter.m_currentPolygon = aFirst;
630  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
631  iter.m_currentContour = 0;
632  iter.m_currentVertex = 0;
633  iter.m_iterateHoles = aIterateHoles;
634 
635  return iter;
636  }
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 638 of file shape_poly_set.h.

References CIterate().

639  {
640  return CIterate( aOutline, aOutline );
641  }
CONST_ITERATOR CIterate() const
CONST_ITERATOR SHAPE_POLY_SET::CIterate ( ) const
inline

Definition at line 648 of file shape_poly_set.h.

References OutlineCount().

Referenced by CIterate(), and CIterateWithHoles().

649  {
650  return CIterate( 0, OutlineCount() - 1 );
651  }
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 643 of file shape_poly_set.h.

References CIterate().

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

644  {
645  return CIterate( aOutline, aOutline, true );
646  }
CONST_ITERATOR CIterate() const
CONST_ITERATOR SHAPE_POLY_SET::CIterateWithHoles ( ) const
inline

Definition at line 653 of file shape_poly_set.h.

References CIterate(), and OutlineCount().

654  {
655  return CIterate( 0, OutlineCount() - 1, true );
656  }
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 61 of file shape_poly_set.cpp.

References SHAPE_POLY_SET().

62 {
63  return new SHAPE_POLY_SET( *this );
64 }
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 1031 of file shape_poly_set.cpp.

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

1032 {
1033  SHAPE_POLY_SET polySet = SHAPE_POLY_SET( *this );
1034 
1035  // Inflate the polygon if necessary.
1036  if( aClearance > 0 )
1037  {
1038  // fixme: the number of arc segments should not be hardcoded
1039  polySet.Inflate( aClearance, 8 );
1040  }
1041 
1042  // There is a collision if and only if the point is inside of the polygon.
1043  return polySet.Contains( aP );
1044 }
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 821 of file shape_poly_set.h.

821 { 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 1172 of file shape_poly_set.cpp.

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

Referenced by ZONE_CONTAINER::HitTestForEdge().

1174 {
1175  // Shows whether there was a collision
1176  bool collision = false;
1177 
1178  SEGMENT_ITERATOR iterator;
1179 
1180  for( iterator = IterateSegmentsWithHoles(); iterator; iterator++ )
1181  {
1182  SEG currentSegment = *iterator;
1183  int distance = currentSegment.Distance( aPoint );
1184 
1185  // Check for collisions
1186  if( distance <= aClearance )
1187  {
1188  collision = true;
1189 
1190  // Update aClearance to look for closer edges
1191  aClearance = distance;
1192 
1193  // Store the indices that identify the vertex
1194  aClosestVertex = iterator.GetIndex();
1195  }
1196  }
1197 
1198  return collision;
1199 }
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
Definition: seg.h:37
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:185
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 1134 of file shape_poly_set.cpp.

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

Referenced by ZONE_CONTAINER::HitTestForCorner().

1136 {
1137  // Shows whether there was a collision
1138  bool collision = false;
1139 
1140  // Difference vector between each vertex and aPoint.
1141  VECTOR2D delta;
1142  double distance, clearance;
1143 
1144  // Convert clearance to double for precission when comparing distances
1145  clearance = aClearance;
1146 
1147  for( ITERATOR iterator = IterateWithHoles(); iterator; iterator++ )
1148  {
1149  // Get the difference vector between current vertex and aPoint
1150  delta = *iterator - aPoint;
1151 
1152  // Compute distance
1153  distance = delta.EuclideanNorm();
1154 
1155  // Check for collisions
1156  if( distance <= clearance )
1157  {
1158  collision = true;
1159 
1160  // Update aClearance to look for closer vertices
1161  clearance = distance;
1162 
1163  // Store the indices that identify the vertex
1164  aClosestVertex = iterator.GetIndex();
1165  }
1166  }
1167 
1168  return collision;
1169 }
static const int delta[8][2]
Definition: solve.cpp:112
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:295
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 1202 of file shape_poly_set.cpp.

References containsSingle(), and OutlineCount().

Referenced by Collide(), DRC::doEdgeZoneDrc(), RN_POLY::HitTest(), ZONE_CONTAINER::HitTestFilledArea(), ZONE_CONTAINER::HitTestInsideZone(), BOARD::Test_Connections_To_Copper_Areas(), BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines(), BOARD::TestAreaIntersection(), and ZONE_CONTAINER::TestForCopperIslandAndRemoveInsulatedIslands().

1203 {
1204  if( m_polys.size() == 0 ) // empty set?
1205  return false;
1206 
1207  // If there is a polygon specified, check the condition against that polygon
1208  if( aSubpolyIndex >= 0 )
1209  return containsSingle( aP, aSubpolyIndex );
1210 
1211  // In any other case, check it against all polygons in the set
1212  for( int polygonIdx = 0; polygonIdx < OutlineCount(); polygonIdx++ )
1213  {
1214  if( containsSingle( aP, polygonIdx ) )
1215  return true;
1216  }
1217 
1218  return false;
1219 
1220 }
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 1241 of file shape_poly_set.cpp.

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

Referenced by Contains(), and DistanceToPolygon().

1242 {
1243  // Check that the point is inside the outline
1244  if( pointInPolygon( aP, m_polys[aSubpolyIndex][0] ) )
1245  {
1246  // Check that the point is not in any of the holes
1247  for( int holeIdx = 0; holeIdx < HoleCount( aSubpolyIndex ); holeIdx++ )
1248  {
1249  const SHAPE_LINE_CHAIN hole = CHole( aSubpolyIndex, holeIdx );
1250  // If the point is inside a hole (and not on its edge),
1251  // it is outside of the polygon
1252  if( pointInPolygon( aP, hole ) && !hole.PointOnEdge( aP ) )
1253  return false;
1254  }
1255 
1256  return true;
1257  }
1258 
1259  return false;
1260 }
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 465 of file shape_poly_set.cpp.

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

Referenced by importTree().

466 {
467  SHAPE_LINE_CHAIN lc;
468 
469  for( unsigned int i = 0; i < aPath.size(); i++ )
470  lc.Append( aPath[i].X, aPath[i].Y );
471 
472  lc.SetClosed( true );
473 
474  return lc;
475 }
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 448 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().

449 {
450  Path c_path;
451 
452  for( int i = 0; i < aPath.PointCount(); i++ )
453  {
454  const VECTOR2I& vertex = aPath.CPoint( i );
455  c_path.push_back( IntPoint( vertex.x, vertex.y ) );
456  }
457 
458  if( Orientation( c_path ) != aRequiredOrientation )
459  ReversePath( c_path );
460 
461  return c_path;
462 }
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 274 of file shape_poly_set.cpp.

References m_polys.

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

275 {
276  if( aOutline < 0 )
277  aOutline += m_polys.size();
278 
279  int idx;
280 
281  if( aHole < 0 )
282  idx = 0;
283  else
284  idx = aHole + 1;
285 
286  assert( aOutline < (int)m_polys.size() );
287  assert( idx < (int)m_polys[aOutline].size() );
288 
289  return m_polys[aOutline][idx].CPoint( aIndex );
290 }
const VECTOR2I & SHAPE_POLY_SET::CVertex ( int  aGlobalIndex) const

Returns the aGlobalIndex-th vertex in the poly set

Definition at line 305 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.

306 {
308 
309  // Assure the passed index references a legal position; abort otherwise
310  if( !GetRelativeIndices( aGlobalIndex, &index ) )
311  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
312 
313  return m_polys[index.m_polygon][index.m_contour].CPoint( index.m_vertex );
314 }
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 323 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.

324 {
325  return CVertex( index.m_vertex, index.m_polygon, index.m_contour - 1 );
326 }
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 1116 of file shape_poly_set.cpp.

Referenced by ZONE_CONTAINER::TestForCopperIslandAndRemoveInsulatedIslands().

1117 {
1118  m_polys.erase( m_polys.begin() + aIdx );
1119 }
int SHAPE_POLY_SET::Distance ( VECTOR2I  point)

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 1431 of file shape_poly_set.cpp.

References DistanceToPolygon().

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

1432 {
1433  int currentDistance;
1434  int minDistance = DistanceToPolygon( aPoint, 0 );
1435 
1436  // Iterate through all the polygons and get the minimum distance.
1437  for( unsigned int polygonIdx = 1; polygonIdx < m_polys.size(); polygonIdx++ )
1438  {
1439  currentDistance = DistanceToPolygon( aPoint, polygonIdx );
1440 
1441  if( currentDistance < minDistance )
1442  minDistance = currentDistance;
1443  }
1444 
1445  return minDistance;
1446 }
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 1449 of file shape_poly_set.cpp.

References DistanceToPolygon().

1450 {
1451  int currentDistance;
1452  int minDistance = DistanceToPolygon( aSegment, 0 );
1453 
1454  // Iterate through all the polygons and get the minimum distance.
1455  for( unsigned int polygonIdx = 1; polygonIdx < m_polys.size(); polygonIdx++ )
1456  {
1457  currentDistance = DistanceToPolygon( aSegment, polygonIdx, aSegmentWidth );
1458 
1459  if( currentDistance < minDistance )
1460  minDistance = currentDistance;
1461  }
1462 
1463  return minDistance;
1464 }
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 1370 of file shape_poly_set.cpp.

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

Referenced by Distance().

1371 {
1372  // We calculate the min dist between the segment and each outline segment
1373  // However, if the segment to test is inside the outline, and does not cross
1374  // any edge, it can be seen outside the polygon.
1375  // Therefore test if a segment end is inside ( testing only one end is enough )
1376  if( containsSingle( aPoint, aPolygonIndex ) )
1377  return 0;
1378 
1379  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
1380 
1381  SEG polygonEdge = *iterator;
1382  int minDistance = polygonEdge.Distance( aPoint );
1383 
1384  for( iterator++; iterator && minDistance > 0; iterator++ )
1385  {
1386  polygonEdge = *iterator;
1387 
1388  int currentDistance = polygonEdge.Distance( aPoint );
1389 
1390  if( currentDistance < minDistance )
1391  minDistance = currentDistance;
1392  }
1393 
1394  return minDistance;
1395 }
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:37
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:185
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 1398 of file shape_poly_set.cpp.

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

1399 {
1400  // We calculate the min dist between the segment and each outline segment
1401  // However, if the segment to test is inside the outline, and does not cross
1402  // any edge, it can be seen outside the polygon.
1403  // Therefore test if a segment end is inside ( testing only one end is enough )
1404  if( containsSingle( aSegment.A, aPolygonIndex ) )
1405  return 0;
1406 
1407  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
1408 
1409  SEG polygonEdge = *iterator;
1410  int minDistance = polygonEdge.Distance( aSegment );
1411 
1412  for( iterator++; iterator && minDistance > 0; iterator++ )
1413  {
1414  polygonEdge = *iterator;
1415 
1416  int currentDistance = polygonEdge.Distance( aSegment );
1417 
1418  if( currentDistance < minDistance )
1419  minDistance = currentDistance;
1420  }
1421 
1422  // Take into account the width of the segment
1423  if( aSegmentWidth > 0 )
1424  minDistance -= aSegmentWidth/2;
1425 
1426  // Return the maximum of minDistance and zero
1427  return minDistance < 0 ? 0 : minDistance;
1428 }
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:37
VECTOR2I A
Definition: seg.h:47
int Distance(const SEG &aSeg) const
Function Distance()
Definition: seg.h:185
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 1491 of file shape_poly_set.cpp.

References FilletPolygon(), and m_polys.

Referenced by ZONE_CONTAINER::BuildFilledSolidAreasPolygons().

1492 {
1493  SHAPE_POLY_SET filleted;
1494 
1495  for( size_t polygonIdx = 0; polygonIdx < m_polys.size(); polygonIdx++ )
1496  filleted.m_polys.push_back( FilletPolygon( aRadius, aSegments, polygonIdx ) );
1497 
1498  return filleted;
1499 }
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 1362 of file shape_poly_set.cpp.

References chamferFilletPolygon().

Referenced by Fillet().

1365 {
1366  return chamferFilletPolygon(CORNER_MODE::FILLETED, aRadius, aIndex, aSegments );
1367 }
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 918 of file shape_poly_set.cpp.

919 {
920  std::stringstream ss;
921 
922  ss << "polyset " << m_polys.size() << "\n";
923 
924  for( unsigned i = 0; i < m_polys.size(); i++ )
925  {
926  ss << "poly " << m_polys[i].size() << "\n";
927  for( unsigned j = 0; j < m_polys[i].size(); j++ )
928  {
929  ss << m_polys[i][j].PointCount() << "\n";
930  for( int v = 0; v < m_polys[i][j].PointCount(); v++ )
931  ss << m_polys[i][j].CPoint( v ).x << " " << m_polys[i][j].CPoint( v ).y << "\n";
932  }
933  ss << "\n";
934  }
935 
936  return ss.str();
937 }
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 851 of file shape_poly_set.cpp.

References fractureSingle(), and Simplify().

Referenced by ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList_NG(), ZONE_CONTAINER::BuildFilledSolidAreasPolygons(), APERTURE_MACRO::DrawApertureMacroShape(), DXF_PLOTTER::PlotPoly(), PlotSolderMaskLayer(), C3D_RENDER_RAYTRACING::reload(), and ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon().

852 {
853  Simplify( aFastMode ); // remove overlapping holes/degeneracy
854 
855  for( POLYGON& paths : m_polys )
856  {
857  fractureSingle( paths );
858  }
859 }
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 750 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().

751 {
752  FractureEdgeSet edges;
753  FractureEdgeSet border_edges;
754  FractureEdge* root = NULL;
755 
756  bool first = true;
757 
758  if( paths.size() == 1 )
759  return;
760 
761  int num_unconnected = 0;
762 
763  for( SHAPE_LINE_CHAIN& path : paths )
764  {
765  int index = 0;
766 
767  FractureEdge *prev = NULL, *first_edge = NULL;
768 
769  int x_min = std::numeric_limits<int>::max();
770 
771  for( int i = 0; i < path.PointCount(); i++ )
772  {
773  const VECTOR2I& p = path.CPoint( i );
774 
775  if( p.x < x_min )
776  x_min = p.x;
777  }
778 
779  for( int i = 0; i < path.PointCount(); i++ )
780  {
781  FractureEdge* fe = new FractureEdge( first, &path, index++ );
782 
783  if( !root )
784  root = fe;
785 
786  if( !first_edge )
787  first_edge = fe;
788 
789  if( prev )
790  prev->m_next = fe;
791 
792  if( i == path.PointCount() - 1 )
793  fe->m_next = first_edge;
794 
795  prev = fe;
796  edges.push_back( fe );
797 
798  if( !first )
799  {
800  if( fe->m_p1.x == x_min )
801  border_edges.push_back( fe );
802  }
803 
804  if( !fe->m_connected )
805  num_unconnected++;
806  }
807  first = false; // first path is always the outline
808  }
809 
810  // keep connecting holes to the main outline, until there's no holes left...
811  while( num_unconnected > 0 )
812  {
813  int x_min = std::numeric_limits<int>::max();
814 
815  FractureEdge* smallestX = NULL;
816 
817  // find the left-most hole edge and merge with the outline
818  for( FractureEdgeSet::iterator i = border_edges.begin(); i != border_edges.end(); ++i )
819  {
820  int xt = (*i)->m_p1.x;
821 
822  if( ( xt < x_min ) && ! (*i)->m_connected )
823  {
824  x_min = xt;
825  smallestX = *i;
826  }
827  }
828 
829  num_unconnected -= processEdge( edges, smallestX );
830  }
831 
832  paths.clear();
833  SHAPE_LINE_CHAIN newPath;
834 
835  newPath.SetClosed( true );
836 
837  FractureEdge* e;
838 
839  for( e = root; e->m_next != root; e = e->m_next )
840  newPath.Append( e->m_p1 );
841 
842  newPath.Append( e->m_p1 );
843 
844  for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i )
845  delete *i;
846 
847  paths.push_back( newPath );
848 }
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 107 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().

109 {
110  int selectedVertex = aRelativeIndices.m_vertex;
111  unsigned int selectedContour = aRelativeIndices.m_contour;
112  unsigned int selectedPolygon = aRelativeIndices.m_polygon;
113 
114  // Check whether the vertex indices make sense in this poly set
115  if( selectedPolygon < m_polys.size() && selectedContour < m_polys[selectedPolygon].size() &&
116  selectedVertex < m_polys[selectedPolygon][selectedContour].PointCount() )
117  {
118  POLYGON currentPolygon;
119 
120  aGlobalIdx = 0;
121 
122  for( unsigned int polygonIdx = 0; polygonIdx < selectedPolygon; polygonIdx++ )
123  {
124  currentPolygon = Polygon( polygonIdx );
125 
126  for( unsigned int contourIdx = 0; contourIdx < currentPolygon.size(); contourIdx++ )
127  {
128  aGlobalIdx += currentPolygon[contourIdx].PointCount();
129  }
130  }
131 
132  currentPolygon = Polygon( selectedPolygon );
133 
134  for( unsigned int contourIdx = 0; contourIdx < selectedContour; contourIdx ++ )
135  {
136  aGlobalIdx += currentPolygon[contourIdx].PointCount();
137  }
138 
139  aGlobalIdx += selectedVertex;
140 
141  return true;
142  }
143  else
144  {
145  return false;
146  }
147 }
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 328 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().

329 {
331 
332  // If the edge does not exist, throw an exception, it is an illegal access memory error
333  if( !GetRelativeIndices( aGlobalIndex, &index ) )
334  return false;
335 
336  // Calculate the previous and next index of aGlobalIndex, corresponding to
337  // the same contour;
338  VERTEX_INDEX inext = index;
339  int lastpoint = m_polys[index.m_polygon][index.m_contour].SegmentCount();
340 
341  if( index.m_vertex == 0 )
342  {
343  index.m_vertex = lastpoint;
344  inext.m_vertex = 1;
345  }
346  else if( index.m_vertex == lastpoint )
347  {
348  index.m_vertex--;
349  inext.m_vertex = 0;
350  }
351  else
352  {
353  inext.m_vertex++;
354  index.m_vertex--;
355  }
356 
357  if( aPrevious )
358  {
359  int previous;
360  GetGlobalIndex( index, previous );
361  *aPrevious = previous;
362  }
363 
364  if( aNext )
365  {
366  int next;
367  GetGlobalIndex( inext, next );
368  *aNext = next;
369  }
370 
371  return true;
372 }
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
aPolygonIdxis the index of the polygon in which the expected vertex is.
aContourIdxis the index of the contour in the aPolygonIdx-th polygon in which the expected vertex is.
aVertexIdxis the index of the vertex in the aContourIdx-th contour in which the expected vertex is.
Returns
bool - true if the global index is correct and the information in aRelativeIndices is valid; false otherwise.

Definition at line 67 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().

69 {
70  int polygonIdx = 0;
71  unsigned int contourIdx = 0;
72  int vertexIdx = 0;
73 
74  int currentGlobalIdx = 0;
75 
76  for( polygonIdx = 0; polygonIdx < OutlineCount(); polygonIdx++ )
77  {
78  const POLYGON currentPolygon = CPolygon( polygonIdx );
79 
80  for( contourIdx = 0; contourIdx < currentPolygon.size(); contourIdx++ )
81  {
82  SHAPE_LINE_CHAIN currentContour = currentPolygon[contourIdx];
83  int totalPoints = currentContour.PointCount();
84 
85  for( vertexIdx = 0; vertexIdx < totalPoints; vertexIdx++ )
86  {
87  // Check if the current vertex is the globally indexed as aGlobalIdx
88  if( currentGlobalIdx == aGlobalIdx )
89  {
90  aRelativeIndices->m_polygon = polygonIdx;
91  aRelativeIndices->m_contour = contourIdx;
92  aRelativeIndices->m_vertex = vertexIdx;
93 
94  return true;
95  }
96 
97  // Advance
98  currentGlobalIdx++;
99  }
100  }
101  }
102 
103  return false;
104 }
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 862 of file shape_poly_set.cpp.

863 {
864  // Iterate through all the polygons on the set
865  for( const POLYGON& paths : m_polys )
866  {
867  // If any of them has more than one contour, it is a hole.
868  if( paths.size() > 1 )
869  return true;
870  }
871 
872  // Return false if and only if every polygon has just one outline, without holes.
873  return false;
874 }
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 531 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().

532  {
533  return m_polys[aOutline][aHole + 1];
534  }
int SHAPE_POLY_SET::HoleCount ( int  aOutline) const
inline

Returns the number of holes in a given outline

Definition at line 501 of file shape_poly_set.h.

References m_polys.

Referenced by CINFO3D_VISU::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), 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().

502  {
503  if( (aOutline > (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
504  return 0;
505  return m_polys[aOutline].size() - 1;
506  }
void SHAPE_POLY_SET::importTree ( ClipperLib::PolyTree *  tree)
private

Definition at line 618 of file shape_poly_set.cpp.

References convertFromClipper().

Referenced by booleanOp(), and Inflate().

619 {
620  m_polys.clear();
621 
622  for( PolyNode* n = tree->GetFirst(); n; n = n->GetNext() )
623  {
624  if( !n->IsHole() )
625  {
626  POLYGON paths;
627  paths.reserve( n->Childs.size() + 1 );
628  paths.push_back( convertFromClipper( n->Contour ) );
629 
630  for( unsigned int i = 0; i < n->Childs.size(); i++ )
631  paths.push_back( convertFromClipper( n->Childs[i]->Contour ) );
632 
633  m_polys.push_back( paths );
634  }
635  }
636 }
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 572 of file shape_poly_set.cpp.

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

Referenced by ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList_NG(), ZONE_CONTAINER::BuildFilledSolidAreasPolygons(), Collide(), PlotSolderMaskLayer(), ZONE_CONTAINER::TransformOutlinesShapeWithClearanceToPolygon(), TransformRoundRectToPolygon(), and D_PAD::TransformShapeWithClearanceToPolygon().

573 {
574  // A static table to avoid repetitive calculations of the coefficient
575  // 1.0 - cos( M_PI/aCircleSegmentsCount)
576  // aCircleSegmentsCount is most of time <= 64 and usually 8, 12, 16, 32
577  #define SEG_CNT_MAX 64
578  static double arc_tolerance_factor[SEG_CNT_MAX+1];
579 
580  ClipperOffset c;
581 
582  for( const POLYGON& poly : m_polys )
583  {
584  for( unsigned int i = 0; i < poly.size(); i++ )
585  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), jtRound, etClosedPolygon );
586  }
587 
588  PolyTree solution;
589 
590  // Calculate the arc tolerance (arc error) from the seg count by circle.
591  // the seg count is nn = M_PI / acos(1.0 - c.ArcTolerance / abs(aFactor))
592  // see:
593  // www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/ClipperOffset/Properties/ArcTolerance.htm
594 
595  if( aCircleSegmentsCount < 6 ) // avoid incorrect aCircleSegmentsCount values
596  aCircleSegmentsCount = 6;
597 
598  double coeff;
599 
600  if( aCircleSegmentsCount > SEG_CNT_MAX || arc_tolerance_factor[aCircleSegmentsCount] == 0 )
601  {
602  coeff = 1.0 - cos( M_PI/aCircleSegmentsCount);
603 
604  if( aCircleSegmentsCount <= SEG_CNT_MAX )
605  arc_tolerance_factor[aCircleSegmentsCount] = coeff;
606  }
607  else
608  coeff = arc_tolerance_factor[aCircleSegmentsCount];
609 
610  c.ArcTolerance = std::abs( aFactor ) * coeff;
611 
612  c.Execute( solution, aFactor );
613 
614  importTree( &solution );
615 }
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 198 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().

199 {
200  VERTEX_INDEX index;
201 
202  if( aGlobalIndex < 0 )
203  aGlobalIndex = 0;
204 
205  if( aGlobalIndex >= TotalVertices() )
206  {
207  Append( aNewVertex );
208  }
209  else
210  {
211  // Assure the position to be inserted exists; throw an exception otherwise
212  if( GetRelativeIndices( aGlobalIndex, &index ) )
213  m_polys[index.m_polygon][index.m_contour].Insert( index.m_vertex, aNewVertex );
214  else
215  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
216  }
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 375 of file shape_poly_set.cpp.

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

Referenced by IsSelfIntersecting().

376 {
377  // Get polygon
378  const POLYGON poly = CPolygon( aPolygonIndex );
379 
380  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
381  SEGMENT_ITERATOR innerIterator;
382 
383  for( iterator = IterateSegmentsWithHoles( aPolygonIndex ); iterator; iterator++ )
384  {
385  SEG firstSegment = *iterator;
386 
387  // Iterate through all remaining segments.
388  innerIterator = iterator;
389 
390  // Start in the next segment, we don't want to check collision between a segment and itself
391  for( innerIterator++; innerIterator; innerIterator++ )
392  {
393  SEG secondSegment = *innerIterator;
394 
395  // Check whether the two segments built collide, only when they are not adjacent.
396  if( !iterator.IsAdjacent( innerIterator ) && firstSegment.Collide( secondSegment, 0 ) )
397  return true;
398  }
399  }
400 
401  return false;
402 }
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:37
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 405 of file shape_poly_set.cpp.

References IsPolygonSelfIntersecting(), and m_polys.

Referenced by BOARD::NormalizeAreaPolygon().

406 {
407  for( unsigned int polygon = 0; polygon < m_polys.size(); polygon++ )
408  {
409  if( IsPolygonSelfIntersecting( polygon ) )
410  return true;
411  }
412 
413  return false;
414 }
bool IsPolygonSelfIntersecting(int aPolygonIndex)
Function IsPolygonSelfIntersecting.
bool SHAPE_POLY_SET::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 791 of file shape_poly_set.h.

792  {
793  return true;
794  }
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 1467 of file shape_poly_set.cpp.

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

Referenced by PCB_EDIT_FRAME::createPopUpMenuForZones().

1468 {
1469  VERTEX_INDEX index;
1470 
1471  // Get the polygon and contour where the vertex is. If the vertex does not exist, return false
1472  if( !GetRelativeIndices( aGlobalIdx, &index ) )
1473  return false;
1474 
1475  // The contour is a hole if its index is greater than zero
1476  return index.m_contour > 0;
1477 }
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 567 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(), ZONE_CONTAINER::DrawWhileCreateOutline(), ZONE_CONTAINER::Iterate(), ZONE_CONTAINER::Mirror(), and ZONE_CONTAINER::Rotate().

568  {
569  ITERATOR iter;
570 
571  iter.m_poly = this;
572  iter.m_currentPolygon = aFirst;
573  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
574  iter.m_currentContour = 0;
575  iter.m_currentVertex = 0;
576  iter.m_iterateHoles = aIterateHoles;
577 
578  return iter;
579  }
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 587 of file shape_poly_set.h.

References Iterate().

588  {
589  return Iterate( aOutline, aOutline );
590  }
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 608 of file shape_poly_set.h.

References OutlineCount().

Referenced by Iterate(), and IterateWithHoles().

609  {
610  return Iterate( 0, OutlineCount() - 1 );
611  }
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 658 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.

659  {
660  // Build iterator
661  ITERATOR iter = IterateWithHoles();
662 
663  // Get the relative indices of the globally indexed vertex
664  VERTEX_INDEX indices;
665 
666  if( !GetRelativeIndices( aGlobalIdx, &indices ) )
667  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
668 
669  // Adjust where the iterator is pointing
670  iter.m_currentPolygon = indices.m_polygon;
671  iter.m_currentContour = indices.m_contour;
672  iter.m_currentVertex = indices.m_vertex;
673 
674  return iter;
675  }
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 679 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().

680  {
681  SEGMENT_ITERATOR iter;
682 
683  iter.m_poly = this;
684  iter.m_currentPolygon = aFirst;
685  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
686  iter.m_currentContour = 0;
687  iter.m_currentSegment = 0;
688  iter.m_iterateHoles = aIterateHoles;
689 
690  return iter;
691  }
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 694 of file shape_poly_set.h.

References IterateSegments().

695  {
696  return IterateSegments( aPolygonIdx, aPolygonIdx );
697  }
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 700 of file shape_poly_set.h.

References OutlineCount().

Referenced by IterateSegments(), and IterateSegmentsWithHoles().

701  {
702  return IterateSegments( 0, OutlineCount() - 1 );
703  }
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 706 of file shape_poly_set.h.

References IterateSegments(), and OutlineCount().

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

707  {
708  return IterateSegments( 0, OutlineCount() - 1, true );
709  }
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 712 of file shape_poly_set.h.

References IterateSegments().

713  {
714  return IterateSegments( aOutline, aOutline, true );
715  }
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 598 of file shape_poly_set.h.

References Iterate().

Referenced by ZONE_CONTAINER::Hatch(), ZONE_CONTAINER::IterateWithHoles(), ZONE_CONTAINER::Mirror(), ZONE_CONTAINER::Rotate(), BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines(), and BOARD::TestAreaIntersection().

599  {
600  return Iterate( aOutline, aOutline, true );
601  }
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 618 of file shape_poly_set.h.

References Iterate(), and OutlineCount().

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

619  {
620  return Iterate( 0, OutlineCount() - 1, true );
621  }
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 1328 of file shape_poly_set.cpp.

Referenced by ZONE_CONTAINER::Move().

1329 {
1330  for( POLYGON &poly : m_polys )
1331  {
1332  for( SHAPE_LINE_CHAIN &path : poly )
1333  {
1334  path.Move( aVector );
1335  }
1336  }
1337 }
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  empty_path.SetClosed( true );
165 
166  // Default outline is the last one
167  if( aOutline < 0 )
168  aOutline += m_polys.size();
169 
170  // Add hole to the selected outline
171  m_polys[aOutline].push_back( empty_path );
172 
173  return m_polys.back().size() - 2;
174 }
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 150 of file shape_poly_set.cpp.

References m_polys, and SHAPE_LINE_CHAIN::SetClosed().

Referenced by ZONE_CONTAINER::AppendCorner(), BuildBoardPolygonOutlines(), D_PAD::BuildPadShapePolygon(), BuildUnconnectedThermalStubsPolygonList(), ConvertOutlineToPolygon(), ConvertPolyListToPolySet(), CreateThermalReliefPadPolygon(), KIGFX::PCB_PAINTER::draw(), getRectangleAlongCentreLine(), LEGACY_PLUGIN::loadZONE_CONTAINER(), CPolyLine::NormalizeAreaOutlines(), PCB_PARSER::parseZONE_CONTAINER(), DXF_PLOTTER::PlotPoly(), KIGFX::PREVIEW::POLYGON_ITEM::SetPoints(), TEXTE_PCB::TransformBoundingBoxWithClearanceToPolygon(), TransformCircleToPolygon(), TransformRingToPolygon(), TransformRoundedEndsSegmentToPolygon(), TransformRoundRectToPolygon(), DRAWSEGMENT::TransformShapeWithClearanceToPolygon(), and D_PAD::TransformShapeWithClearanceToPolygon().

151 {
152  SHAPE_LINE_CHAIN empty_path;
153  POLYGON poly;
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 885 of file shape_poly_set.cpp.

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

Referenced by BOARD::NormalizeAreaPolygon().

886 {
887  // We are expecting only one main outline, but this main outline can have holes
888  // if holes: combine holes and remove them from the main outline.
889  // Note also we are using SHAPE_POLY_SET::PM_STRICTLY_SIMPLE in polygon
890  // calculations, but it is not mandatory. It is used mainly
891  // because there is usually only very few vertices in area outlines
892  SHAPE_POLY_SET::POLYGON& outline = Polygon( 0 );
893  SHAPE_POLY_SET holesBuffer;
894 
895  // Move holes stored in outline to holesBuffer:
896  // The first SHAPE_LINE_CHAIN is the main outline, others are holes
897  while( outline.size() > 1 )
898  {
899  holesBuffer.AddOutline( outline.back() );
900  outline.pop_back();
901  }
902 
904 
905  // If any hole, substract it to main outline
906  if( holesBuffer.OutlineCount() )
907  {
908  holesBuffer.Simplify( SHAPE_POLY_SET::PM_FAST);
910  }
911 
913 
914  return OutlineCount();
915 }
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
int SHAPE_POLY_SET::OutlineCount ( ) const
inline

Returns the number of outlines in the set

Definition at line 495 of file shape_poly_set.h.

References m_polys.

Referenced by POINT_EDITOR::addCorner(), RN_NET::AddItem(), ZONE_CONTAINER::AddPolygon(), CINFO3D_VISU::AddSolidAreasShapesToContainer(), CLAYER_TRIANGLES::AddToMiddleContourns(), ZONE_CONTAINER::AppendCorner(), BuildBoardPolygonOutlines(), BuildConvexHull(), DRC::checkClearancePadToPad(), CIterate(), CIterateWithHoles(), BOARD::CombineAreas(), Contains(), Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(), Convert_shape_line_polygon_to_triangles(), DRC::doFootprintOverlappingDrc(), KIGFX::PCB_PAINTER::draw(), APERTURE_MACRO::DrawApertureMacroShape(), ZONE_CONTAINER::DrawFilledArea(), KIGFX::CAIRO_GAL::DrawPolygon(), KIGFX::OPENGL_GAL::DrawPolygon(), export_vrml_board(), export_vrml_zones(), DSN::SPECCTRA_DB::fillBOUNDARY(), ZONE_CONTAINER::FillZoneAreasWithSegments(), HPGL_PLOTTER::FlashPadCustom(), PSLIKE_PLOTTER::FlashPadCustom(), GERBER_PLOTTER::FlashPadCustom(), DXF_PLOTTER::FlashPadCustom(), C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads(), C3D_RENDER_OGL_LEGACY::generate_holes_display_list(), GetRelativeIndices(), Iterate(), IterateSegments(), IterateSegmentsWithHoles(), IterateWithHoles(), CPolyLine::NormalizeAreaOutlines(), NormalizeAreaOutlines(), PlotLayerOutlines(), DXF_PLOTTER::PlotPoly(), Polygon_Calc_BBox_3DU(), C3D_RENDER_OGL_LEGACY::reload(), Subset(), BOARD::Test_Connections_To_Copper_Areas(), ZONE_CONTAINER::TestForCopperIslandAndRemoveInsulatedIslands(), and ZONE_CONTAINER::TransformSolidAreasShapesToPolygonSet().

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

Reimplemented from SHAPE.

Definition at line 940 of file shape_poly_set.cpp.

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

941 {
942  std::string tmp;
943 
944  aStream >> tmp;
945 
946  if( tmp != "polyset" )
947  return false;
948 
949  aStream >> tmp;
950 
951  int n_polys = atoi( tmp.c_str() );
952 
953  if( n_polys < 0 )
954  return false;
955 
956  for( int i = 0; i < n_polys; i++ )
957  {
958  POLYGON paths;
959 
960  aStream >> tmp;
961 
962  if( tmp != "poly" )
963  return false;
964 
965  aStream >> tmp;
966  int n_outlines = atoi( tmp.c_str() );
967 
968  if( n_outlines < 0 )
969  return false;
970 
971  for( int j = 0; j < n_outlines; j++ )
972  {
973  SHAPE_LINE_CHAIN outline;
974 
975  outline.SetClosed( true );
976 
977  aStream >> tmp;
978  int n_vertices = atoi( tmp.c_str() );
979  for( int v = 0; v < n_vertices; v++ )
980  {
981  VECTOR2I p;
982 
983  aStream >> tmp; p.x = atoi( tmp.c_str() );
984  aStream >> tmp; p.y = atoi( tmp.c_str() );
985  outline.Append( p );
986  }
987 
988  paths.push_back( outline );
989  }
990 
991  m_polys.push_back( paths );
992  }
993  return true;
994 }
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 1263 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().

1264 {
1265  int result = 0;
1266  int cnt = aPath.PointCount();
1267 
1268  if ( !aPath.BBox().Contains( aP ) ) // test with bounding box first
1269  return false;
1270 
1271  if( cnt < 3 )
1272  return false;
1273 
1274  VECTOR2I ip = aPath.CPoint( 0 );
1275 
1276  for( int i = 1; i <= cnt; ++i )
1277  {
1278  VECTOR2I ipNext = ( i == cnt ? aPath.CPoint( 0 ) : aPath.CPoint( i ) );
1279 
1280  if( ipNext.y == aP.y )
1281  {
1282  if( ( ipNext.x == aP.x ) || ( ip.y == aP.y &&
1283  ( ( ipNext.x > aP.x ) == ( ip.x < aP.x ) ) ) )
1284  return true;
1285  }
1286 
1287  if( ( ip.y < aP.y ) != ( ipNext.y < aP.y ) )
1288  {
1289  if( ip.x >= aP.x )
1290  {
1291  if( ipNext.x > aP.x )
1292  result = 1 - result;
1293  else
1294  {
1295  int64_t d = (int64_t)( ip.x - aP.x ) * (int64_t)( ipNext.y - aP.y ) -
1296  (int64_t)( ipNext.x - aP.x ) * (int64_t)( ip.y - aP.y );
1297 
1298  if( !d )
1299  return true;
1300 
1301  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1302  result = 1 - result;
1303  }
1304  }
1305  else
1306  {
1307  if( ipNext.x > aP.x )
1308  {
1309  int64_t d = (int64_t)( ip.x - aP.x ) * (int64_t)( ipNext.y - aP.y ) -
1310  (int64_t)( ipNext.x - aP.x ) * (int64_t)( ip.y - aP.y );
1311 
1312  if( !d )
1313  return true;
1314 
1315  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1316  result = 1 - result;
1317  }
1318  }
1319  }
1320 
1321  ip = ipNext;
1322  }
1323 
1324  return result ? true : false;
1325 }
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 1014 of file shape_poly_set.cpp.

1015 {
1016  // Iterate through all the polygons in the set
1017  for( const POLYGON& polygon : m_polys )
1018  {
1019  // Iterate through all the line chains in the polygon
1020  for( const SHAPE_LINE_CHAIN& lineChain : polygon )
1021  {
1022  if( lineChain.PointOnEdge( aP ) )
1023  return true;
1024  }
1025  }
1026 
1027  return false;
1028 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
Class SHAPE_LINE_CHAIN.
POLYGON& SHAPE_POLY_SET::Polygon ( int  aIndex)
inline
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 1053 of file shape_poly_set.cpp.

Referenced by PCB_EDIT_FRAME::Delete_Zone_Contour().

1054 {
1055  // Default polygon is the last one
1056  if( aPolygonIdx < 0 )
1057  aPolygonIdx += m_polys.size();
1058 
1059  m_polys[aPolygonIdx].erase( m_polys[aPolygonIdx].begin() + aContourIdx );
1060 }
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 1063 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().

1064 {
1065  int removed = 0;
1066 
1067  ITERATOR iterator = IterateWithHoles();
1068 
1069  VECTOR2I contourStart = *iterator;
1070  VECTOR2I segmentStart, segmentEnd;
1071 
1072  VERTEX_INDEX indexStart;
1073 
1074  while( iterator )
1075  {
1076  // Obtain first point and its index
1077  segmentStart = *iterator;
1078  indexStart = iterator.GetIndex();
1079 
1080  // Obtain last point
1081  if( iterator.IsEndContour() )
1082  {
1083  segmentEnd = contourStart;
1084 
1085  // Advance
1086  iterator++;
1087 
1088  if( iterator )
1089  contourStart = *iterator;
1090  }
1091  else
1092  {
1093  // Advance
1094  iterator++;
1095 
1096  if( iterator )
1097  segmentEnd = *iterator;
1098  }
1099 
1100  // Remove segment start if both points are equal
1101  if( segmentStart == segmentEnd )
1102  {
1103  RemoveVertex( indexStart );
1104  removed++;
1105 
1106  // Advance the iterator one position, as there is one vertex less.
1107  if( iterator )
1108  iterator++;
1109  }
1110  }
1111 
1112  return removed;
1113 }
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 1223 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().

1224 {
1225  VERTEX_INDEX index;
1226 
1227  // Assure the to be removed vertex exists, abort otherwise
1228  if( GetRelativeIndices( aGlobalIndex, &index ) )
1229  RemoveVertex( index );
1230  else
1231  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
1232 }
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
aindexis the set of relative indices of the to-be-removed vertex.

Definition at line 1235 of file shape_poly_set.cpp.

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

1236 {
1237  m_polys[aIndex.m_polygon][aIndex.m_contour].Remove( aIndex.m_vertex );
1238 }
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 877 of file shape_poly_set.cpp.

References booleanOp(), and empty().

Referenced by ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList_NG(), CINFO3D_VISU::AddShapeWithClearanceToContainer(), CINFO3D_VISU::AddSolidAreasShapesToContainer(), BOARD::CombineAreas(), CINFO3D_VISU::createBoardPolygon(), CINFO3D_VISU::createLayers(), CreateThermalReliefPadPolygon(), Fracture(), BOARD::GetBoardPolygonOutlines(), CPolyLine::NormalizeAreaOutlines(), NormalizeAreaOutlines(), and PlotLayerOutlines().

878 {
880 
881  booleanOp( ctUnion, empty, aFastMode );
882 }
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 240 of file shape_poly_set.cpp.

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

Referenced by UnitSet().

241 {
242  assert( aFirstPolygon >= 0 && aLastPolygon <= OutlineCount() );
243 
244  SHAPE_POLY_SET newPolySet;
245 
246  for( int index = aFirstPolygon; index < aLastPolygon; index++ )
247  {
248  newPolySet.m_polys.push_back( Polygon( index ) );
249  }
250 
251  return newPolySet;
252 }
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 1340 of file shape_poly_set.cpp.

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

1341 {
1342  int c = 0;
1343 
1344  for( const POLYGON& poly : m_polys )
1345  {
1346  for( const SHAPE_LINE_CHAIN& path : poly )
1347  {
1348  c += path.PointCount();
1349  }
1350  }
1351 
1352  return c;
1353 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
Class SHAPE_LINE_CHAIN.
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
SHAPE_POLY_SET SHAPE_POLY_SET::UnitSet ( int  aPolygonIndex)
inline

Definition at line 525 of file shape_poly_set.h.

References Subset().

Referenced by BOARD::NormalizeAreaPolygon().

526  {
527  return Subset( aPolygonIndex, aPolygonIndex + 1 );
528  }
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 255 of file shape_poly_set.cpp.

References m_polys.

Referenced by Abort_Zone_Move_Corner_Or_Outlines(), POINT_EDITOR::addCorner(), DRC::doFootprintOverlappingDrc(), ZONE_CONTAINER::Hatch(), ZONE_CONTAINER::HitTest(), ZONE_CONTAINER::MoveEdge(), POINT_EDITOR::removeCorner(), ZONE_CONTAINER::SetCornerPosition(), Show_Zone_Corner_Or_Outline_While_Move_Mouse(), PCB_EDIT_FRAME::Start_Move_Zone_Corner(), POINT_EDITOR::updateItem(), and Vertex().

256 {
257  if( aOutline < 0 )
258  aOutline += m_polys.size();
259 
260  int idx;
261 
262  if( aHole < 0 )
263  idx = 0;
264  else
265  idx = aHole + 1;
266 
267  assert( aOutline < (int)m_polys.size() );
268  assert( idx < (int)m_polys[aOutline].size() );
269 
270  return m_polys[aOutline][idx].Point( aIndex );
271 }
VECTOR2I & SHAPE_POLY_SET::Vertex ( int  aGlobalIndex)

Returns the aGlobalIndex-th vertex in the poly set

Definition at line 293 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.

294 {
296 
297  // Assure the passed index references a legal position; abort otherwise
298  if( !GetRelativeIndices( aGlobalIndex, &index ) )
299  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
300 
301  return m_polys[index.m_polygon][index.m_contour].Point( index.m_vertex );
302 }
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 317 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().

318 {
319  return Vertex( index.m_vertex, index.m_polygon, index.m_contour - 1 );
320 }
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.

222 {
223  if( aOutline < 0 )
224  aOutline += m_polys.size();
225 
226  int idx;
227 
228  if( aHole < 0 )
229  idx = 0;
230  else
231  idx = aHole + 1;
232 
233  assert ( aOutline < (int)m_polys.size() );
234  assert ( idx < (int)m_polys[aOutline].size() );
235 
236  return m_polys[aOutline][idx].PointCount();
237 }

Member Data Documentation

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: