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...
 
SEG Edge (int aGlobalIndex)
 Function Edge Returns a reference to the aGlobalIndex-th segment 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...
 
void Unfracture ()
 

Converts a set of slitted polygons to a set of polygons with holes

More...
 
bool HasHoles () const
 

Returns true if the polygon set has any holes.

More...
 
void Simplify (POLYGON_MODE aFastMode)
 

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

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

Returns true if a given subpolygon contains the point aP.

More...
 
bool IsEmpty () const
 

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

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

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

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

Returns total number of vertices stored in the set.

More...
 
void DeletePolygon (int aIdx)
 

Deletes aIdx-th polygon from the set

More...
 
POLYGON ChamferPolygon (unsigned int aDistance, int aIndex=0)
 Function Chamfer returns a chamfered version of the aIndex-th polygon. More...
 
POLYGON FilletPolygon (unsigned int aRadius, unsigned int aSegments, int aIndex=0)
 Function Fillet returns a filleted version of the aIndex-th polygon. More...
 
SHAPE_POLY_SET Chamfer (int aDistance)
 Function Chamfer returns a chamfered version of the polygon set. More...
 
SHAPE_POLY_SET Fillet (int aRadius, int aSegments)
 Function Fillet returns a filleted version of the polygon set. More...
 
int DistanceToPolygon (VECTOR2I aPoint, int aIndex)
 Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aPoint. More...
 
int DistanceToPolygon (SEG aSegment, int aIndex, int aSegmentWidth=0)
 Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aSegment with a possible width. More...
 
int Distance (VECTOR2I 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 1061 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 1038 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 722 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 396 of file shape_poly_set.cpp.

References m_polys.

Referenced by PCB_EDIT_FRAME::End_Zone().

397 {
398  assert ( m_polys.size() );
399 
400  if( aOutline < 0 )
401  aOutline += m_polys.size();
402 
403  POLYGON& poly = m_polys[aOutline];
404 
405  assert( poly.size() );
406 
407  poly.push_back( aHole );
408 
409  return poly.size() - 1;
410 }
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 382 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().

383 {
384  assert( aOutline.IsClosed() );
385 
386  POLYGON poly;
387 
388  poly.push_back( aOutline );
389 
390  m_polys.push_back( poly );
391 
392  return m_polys.size() - 1;
393 }
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 1087 of file shape_poly_set.cpp.

References m_polys.

1088 {
1089  m_polys.insert( m_polys.end(), aSet.m_polys.begin(), aSet.m_polys.end() );
1090 }
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 1093 of file shape_poly_set.cpp.

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

1094 {
1095  Append( aP.x, aP.y, aOutline, aHole );
1096 }
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 962 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(), ZONE_CONTAINER::HitTest(), BOARD::TestAreaIntersection(), KIGFX::PREVIEW::POLYGON_ITEM::ViewBBox(), and KIGFX::PREVIEW::CENTRELINE_RECT_ITEM::ViewBBox().

963 {
964  BOX2I bb;
965 
966  for( unsigned i = 0; i < m_polys.size(); i++ )
967  {
968  if( i == 0 )
969  bb = m_polys[i][0].BBox();
970  else
971  bb.Merge( m_polys[i][0].BBox() );
972  }
973 
974  bb.Inflate( aClearance );
975  return bb;
976 }
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 501 of file shape_poly_set.cpp.

References booleanOp().

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

502 {
503  booleanOp( ctUnion, b, aFastMode );
504 }
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 519 of file shape_poly_set.cpp.

References booleanOp().

520 {
521  booleanOp( ctUnion, a, b, aFastMode );
522 }
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 513 of file shape_poly_set.cpp.

References booleanOp().

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

514 {
515  booleanOp( ctIntersection, b, aFastMode );
516 }
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 531 of file shape_poly_set.cpp.

References booleanOp().

532 {
533  booleanOp( ctIntersection, a, b, aFastMode );
534 }
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 471 of file shape_poly_set.cpp.

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

475 {
476  Clipper c;
477 
478  if( aFastMode == PM_STRICTLY_SIMPLE )
479  c.StrictlySimple( true );
480 
481  for( const POLYGON& poly : aShape.m_polys )
482  {
483  for( unsigned int i = 0; i < poly.size(); i++ )
484  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptSubject, true );
485  }
486 
487  for( const POLYGON& poly : aOtherShape.m_polys )
488  {
489  for( unsigned int i = 0; i < poly.size(); i++ )
490  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), ptClip, true );
491  }
492 
493  PolyTree solution;
494 
495  c.Execute( aType, solution, pftNonZero, pftNonZero );
496 
497  importTree( &solution );
498 }
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 507 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().

508 {
509  booleanOp( ctDifference, b, aFastMode );
510 }
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 525 of file shape_poly_set.cpp.

References booleanOp().

526 {
527  booleanOp( ctDifference, a, b, aFastMode );
528 }
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 1445 of file shape_poly_set.cpp.

References ChamferPolygon(), and m_polys.

Referenced by ZONE_CONTAINER::BuildFilledSolidAreasPolygons().

1446 {
1447  SHAPE_POLY_SET chamfered;
1448 
1449  for( unsigned int polygonIdx = 0; polygonIdx < m_polys.size(); polygonIdx++ )
1450  chamfered.m_polys.push_back( ChamferPolygon( aDistance, polygonIdx ) );
1451 
1452  return chamfered;
1453 }
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 1467 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().

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

References chamferFilletPolygon().

Referenced by Chamfer().

1322 {
1323  return chamferFilletPolygon( CORNER_MODE::CHAMFERED, aDistance, aIndex );
1324 }
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 622 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().

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

References CIterate().

637  {
638  return CIterate( aOutline, aOutline );
639  }
CONST_ITERATOR CIterate() const
CONST_ITERATOR SHAPE_POLY_SET::CIterate ( ) const
inline

Definition at line 646 of file shape_poly_set.h.

References OutlineCount().

Referenced by CIterate(), and CIterateWithHoles().

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

References CIterate().

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

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

Definition at line 651 of file shape_poly_set.h.

References CIterate(), and OutlineCount().

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

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

997 {
998  SHAPE_POLY_SET polySet = SHAPE_POLY_SET( *this );
999 
1000  // Inflate the polygon if necessary.
1001  if( aClearance > 0 )
1002  {
1003  // fixme: the number of arc segments should not be hardcoded
1004  polySet.Inflate( aClearance, 8 );
1005  }
1006 
1007  // There is a collision if and only if the point is inside of the polygon.
1008  return polySet.Contains( aP );
1009 }
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 822 of file shape_poly_set.h.

822 { 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 1137 of file shape_poly_set.cpp.

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

Referenced by ZONE_CONTAINER::HitTestForEdge().

1139 {
1140  // Shows whether there was a collision
1141  bool collision = false;
1142 
1143  SEGMENT_ITERATOR iterator;
1144 
1145  for( iterator = IterateSegmentsWithHoles(); iterator; iterator++ )
1146  {
1147  SEG currentSegment = *iterator;
1148  int distance = currentSegment.Distance( aPoint );
1149 
1150  // Check for collisions
1151  if( distance <= aClearance )
1152  {
1153  collision = true;
1154 
1155  // Update aClearance to look for closer edges
1156  aClearance = distance;
1157 
1158  // Store the indices that identify the vertex
1159  aClosestVertex = iterator.GetIndex();
1160  }
1161  }
1162 
1163  return collision;
1164 }
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:228
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 1099 of file shape_poly_set.cpp.

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

Referenced by ZONE_CONTAINER::HitTestForCorner().

1101 {
1102  // Shows whether there was a collision
1103  bool collision = false;
1104 
1105  // Difference vector between each vertex and aPoint.
1106  VECTOR2D delta;
1107  double distance, clearance;
1108 
1109  // Convert clearance to double for precission when comparing distances
1110  clearance = aClearance;
1111 
1112  for( ITERATOR iterator = IterateWithHoles(); iterator; iterator++ )
1113  {
1114  // Get the difference vector between current vertex and aPoint
1115  delta = *iterator - aPoint;
1116 
1117  // Compute distance
1118  distance = delta.EuclideanNorm();
1119 
1120  // Check for collisions
1121  if( distance <= clearance )
1122  {
1123  collision = true;
1124 
1125  // Update aClearance to look for closer vertices
1126  clearance = distance;
1127 
1128  // Store the indices that identify the vertex
1129  aClosestVertex = iterator.GetIndex();
1130  }
1131  }
1132 
1133  return collision;
1134 }
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 1167 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().

1168 {
1169  if( m_polys.size() == 0 ) // empty set?
1170  return false;
1171 
1172  // If there is a polygon specified, check the condition against that polygon
1173  if( aSubpolyIndex >= 0 )
1174  return containsSingle( aP, aSubpolyIndex );
1175 
1176  // In any other case, check it against all polygons in the set
1177  for( int polygonIdx = 0; polygonIdx < OutlineCount(); polygonIdx++ )
1178  {
1179  if( containsSingle( aP, polygonIdx ) )
1180  return true;
1181  }
1182 
1183  return false;
1184 
1185 }
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 1206 of file shape_poly_set.cpp.

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

Referenced by Contains(), and DistanceToPolygon().

1207 {
1208  // Check that the point is inside the outline
1209  if( pointInPolygon( aP, m_polys[aSubpolyIndex][0] ) )
1210  {
1211  // Check that the point is not in any of the holes
1212  for( int holeIdx = 0; holeIdx < HoleCount( aSubpolyIndex ); holeIdx++ )
1213  {
1214  const SHAPE_LINE_CHAIN hole = CHole( aSubpolyIndex, holeIdx );
1215  // If the point is inside a hole (and not on its edge),
1216  // it is outside of the polygon
1217  if( pointInPolygon( aP, hole ) && !hole.PointOnEdge( aP ) )
1218  return false;
1219  }
1220 
1221  return true;
1222  }
1223 
1224  return false;
1225 }
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 430 of file shape_poly_set.cpp.

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

Referenced by importTree().

431 {
432  SHAPE_LINE_CHAIN lc;
433 
434  for( unsigned int i = 0; i < aPath.size(); i++ )
435  lc.Append( aPath[i].X, aPath[i].Y );
436 
437  lc.SetClosed( true );
438 
439  return lc;
440 }
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 413 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().

414 {
415  Path c_path;
416 
417  for( int i = 0; i < aPath.PointCount(); i++ )
418  {
419  const VECTOR2I& vertex = aPath.CPoint( i );
420  c_path.push_back( IntPoint( vertex.x, vertex.y ) );
421  }
422 
423  if( Orientation( c_path ) != aRequiredOrientation )
424  ReversePath( c_path );
425 
426  return c_path;
427 }
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 273 of file shape_poly_set.cpp.

References m_polys.

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

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

Returns the aGlobalIndex-th vertex in the poly set

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

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

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

Referenced by ZONE_CONTAINER::TestForCopperIslandAndRemoveInsulatedIslands().

1082 {
1083  m_polys.erase( m_polys.begin() + aIdx );
1084 }
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 1396 of file shape_poly_set.cpp.

References DistanceToPolygon().

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

1397 {
1398  int currentDistance;
1399  int minDistance = DistanceToPolygon( aPoint, 0 );
1400 
1401  // Iterate through all the polygons and get the minimum distance.
1402  for( unsigned int polygonIdx = 1; polygonIdx < m_polys.size(); polygonIdx++ )
1403  {
1404  currentDistance = DistanceToPolygon( aPoint, polygonIdx );
1405 
1406  if( currentDistance < minDistance )
1407  minDistance = currentDistance;
1408  }
1409 
1410  return minDistance;
1411 }
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 1414 of file shape_poly_set.cpp.

References DistanceToPolygon().

1415 {
1416  int currentDistance;
1417  int minDistance = DistanceToPolygon( aSegment, 0 );
1418 
1419  // Iterate through all the polygons and get the minimum distance.
1420  for( unsigned int polygonIdx = 1; polygonIdx < m_polys.size(); polygonIdx++ )
1421  {
1422  currentDistance = DistanceToPolygon( aSegment, polygonIdx, aSegmentWidth );
1423 
1424  if( currentDistance < minDistance )
1425  minDistance = currentDistance;
1426  }
1427 
1428  return minDistance;
1429 }
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 1335 of file shape_poly_set.cpp.

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

Referenced by Distance().

1336 {
1337  // We calculate the min dist between the segment and each outline segment
1338  // However, if the segment to test is inside the outline, and does not cross
1339  // any edge, it can be seen outside the polygon.
1340  // Therefore test if a segment end is inside ( testing only one end is enough )
1341  if( containsSingle( aPoint, aPolygonIndex ) )
1342  return 0;
1343 
1344  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
1345 
1346  SEG polygonEdge = *iterator;
1347  int minDistance = polygonEdge.Distance( aPoint );
1348 
1349  for( iterator++; iterator && minDistance > 0; iterator++ )
1350  {
1351  polygonEdge = *iterator;
1352 
1353  int currentDistance = polygonEdge.Distance( aPoint );
1354 
1355  if( currentDistance < minDistance )
1356  minDistance = currentDistance;
1357  }
1358 
1359  return minDistance;
1360 }
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:228
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 1363 of file shape_poly_set.cpp.

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

1364 {
1365  // We calculate the min dist between the segment and each outline segment
1366  // However, if the segment to test is inside the outline, and does not cross
1367  // any edge, it can be seen outside the polygon.
1368  // Therefore test if a segment end is inside ( testing only one end is enough )
1369  if( containsSingle( aSegment.A, aPolygonIndex ) )
1370  return 0;
1371 
1372  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
1373 
1374  SEG polygonEdge = *iterator;
1375  int minDistance = polygonEdge.Distance( aSegment );
1376 
1377  for( iterator++; iterator && minDistance > 0; iterator++ )
1378  {
1379  polygonEdge = *iterator;
1380 
1381  int currentDistance = polygonEdge.Distance( aSegment );
1382 
1383  if( currentDistance < minDistance )
1384  minDistance = currentDistance;
1385  }
1386 
1387  // Take into account the width of the segment
1388  if( aSegmentWidth > 0 )
1389  minDistance -= aSegmentWidth/2;
1390 
1391  // Return the maximum of minDistance and zero
1392  return minDistance < 0 ? 0 : minDistance;
1393 }
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
VECTOR2I & A
Definition: seg.h:51
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:228
SEG SHAPE_POLY_SET::Edge ( int  aGlobalIndex)

Function Edge Returns a reference to the aGlobalIndex-th segment in the polygon set.

Modifying the points in the returned object will modify the corresponding vertices on the polygon set.

Parameters
aGlobalIndexis index of the edge, globally indexed between all edges in all contours
Returns
SEG - the aGlobalIndex-th segment, whose points are references to the polygon points.

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

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, &indices ) )
334  throw( std::out_of_range( "aGlobalIndex-th edge does not exist" ) );
335 
336  return m_polys[indices.m_polygon][indices.m_contour].Segment( indices.m_vertex );
337 }
Struct VERTEX_INDEX.
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
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 1456 of file shape_poly_set.cpp.

References FilletPolygon(), and m_polys.

Referenced by ZONE_CONTAINER::BuildFilledSolidAreasPolygons().

1457 {
1458  SHAPE_POLY_SET filleted;
1459 
1460  for( size_t polygonIdx = 0; polygonIdx < m_polys.size(); polygonIdx++ )
1461  filleted.m_polys.push_back( FilletPolygon( aRadius, aSegments, polygonIdx ) );
1462 
1463  return filleted;
1464 }
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 1327 of file shape_poly_set.cpp.

References chamferFilletPolygon().

Referenced by Fillet().

1330 {
1331  return chamferFilletPolygon(CORNER_MODE::FILLETED, aRadius, aIndex, aSegments );
1332 }
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 883 of file shape_poly_set.cpp.

884 {
885  std::stringstream ss;
886 
887  ss << "polyset " << m_polys.size() << "\n";
888 
889  for( unsigned i = 0; i < m_polys.size(); i++ )
890  {
891  ss << "poly " << m_polys[i].size() << "\n";
892  for( unsigned j = 0; j < m_polys[i].size(); j++ )
893  {
894  ss << m_polys[i][j].PointCount() << "\n";
895  for( int v = 0; v < m_polys[i][j].PointCount(); v++ )
896  ss << m_polys[i][j].CPoint( v ).x << " " << m_polys[i][j].CPoint( v ).y << "\n";
897  }
898  ss << "\n";
899  }
900 
901  return ss.str();
902 }
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 816 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().

817 {
818  Simplify( aFastMode ); // remove overlapping holes/degeneracy
819 
820  for( POLYGON& paths : m_polys )
821  {
822  fractureSingle( paths );
823  }
824 }
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 715 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().

716 {
717  FractureEdgeSet edges;
718  FractureEdgeSet border_edges;
719  FractureEdge* root = NULL;
720 
721  bool first = true;
722 
723  if( paths.size() == 1 )
724  return;
725 
726  int num_unconnected = 0;
727 
728  for( SHAPE_LINE_CHAIN& path : paths )
729  {
730  int index = 0;
731 
732  FractureEdge *prev = NULL, *first_edge = NULL;
733 
734  int x_min = std::numeric_limits<int>::max();
735 
736  for( int i = 0; i < path.PointCount(); i++ )
737  {
738  const VECTOR2I& p = path.CPoint( i );
739 
740  if( p.x < x_min )
741  x_min = p.x;
742  }
743 
744  for( int i = 0; i < path.PointCount(); i++ )
745  {
746  FractureEdge* fe = new FractureEdge( first, &path, index++ );
747 
748  if( !root )
749  root = fe;
750 
751  if( !first_edge )
752  first_edge = fe;
753 
754  if( prev )
755  prev->m_next = fe;
756 
757  if( i == path.PointCount() - 1 )
758  fe->m_next = first_edge;
759 
760  prev = fe;
761  edges.push_back( fe );
762 
763  if( !first )
764  {
765  if( fe->m_p1.x == x_min )
766  border_edges.push_back( fe );
767  }
768 
769  if( !fe->m_connected )
770  num_unconnected++;
771  }
772  first = false; // first path is always the outline
773  }
774 
775  // keep connecting holes to the main outline, until there's no holes left...
776  while( num_unconnected > 0 )
777  {
778  int x_min = std::numeric_limits<int>::max();
779 
780  FractureEdge* smallestX = NULL;
781 
782  // find the left-most hole edge and merge with the outline
783  for( FractureEdgeSet::iterator i = border_edges.begin(); i != border_edges.end(); ++i )
784  {
785  int xt = (*i)->m_p1.x;
786 
787  if( ( xt < x_min ) && ! (*i)->m_connected )
788  {
789  x_min = xt;
790  smallestX = *i;
791  }
792  }
793 
794  num_unconnected -= processEdge( edges, smallestX );
795  }
796 
797  paths.clear();
798  SHAPE_LINE_CHAIN newPath;
799 
800  newPath.SetClosed( true );
801 
802  FractureEdge* e;
803 
804  for( e = root; e->m_next != root; e = e->m_next )
805  newPath.Append( e->m_p1 );
806 
807  newPath.Append( e->m_p1 );
808 
809  for( FractureEdgeSet::iterator i = edges.begin(); i != edges.end(); ++i )
810  delete *i;
811 
812  paths.push_back( newPath );
813 }
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 cmoputed 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 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::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(), Edge(), ZONE_CONTAINER::GetCornerPosition(), 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 827 of file shape_poly_set.cpp.

828 {
829  // Iterate through all the polygons on the set
830  for( const POLYGON& paths : m_polys )
831  {
832  // If any of them has more than one contour, it is a hole.
833  if( paths.size() > 1 )
834  return true;
835  }
836 
837  // Return false if and only if every polygon has just one outline, without holes.
838  return false;
839 }
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 529 of file shape_poly_set.h.

References m_polys.

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

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

Returns the number of holes in a given outline

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

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

Definition at line 583 of file shape_poly_set.cpp.

References convertFromClipper().

Referenced by booleanOp(), and Inflate().

584 {
585  m_polys.clear();
586 
587  for( PolyNode* n = tree->GetFirst(); n; n = n->GetNext() )
588  {
589  if( !n->IsHole() )
590  {
591  POLYGON paths;
592  paths.reserve( n->Childs.size() + 1 );
593  paths.push_back( convertFromClipper( n->Contour ) );
594 
595  for( unsigned int i = 0; i < n->Childs.size(); i++ )
596  paths.push_back( convertFromClipper( n->Childs[i]->Contour ) );
597 
598  m_polys.push_back( paths );
599  }
600  }
601 }
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 537 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().

538 {
539  // A static table to avoid repetitive calculations of the coefficient
540  // 1.0 - cos( M_PI/aCircleSegmentsCount)
541  // aCircleSegmentsCount is most of time <= 64 and usually 8, 12, 16, 32
542  #define SEG_CNT_MAX 64
543  static double arc_tolerance_factor[SEG_CNT_MAX+1];
544 
545  ClipperOffset c;
546 
547  for( const POLYGON& poly : m_polys )
548  {
549  for( unsigned int i = 0; i < poly.size(); i++ )
550  c.AddPath( convertToClipper( poly[i], i > 0 ? false : true ), jtRound, etClosedPolygon );
551  }
552 
553  PolyTree solution;
554 
555  // Calculate the arc tolerance (arc error) from the seg count by circle.
556  // the seg count is nn = M_PI / acos(1.0 - c.ArcTolerance / abs(aFactor))
557  // see:
558  // www.angusj.com/delphi/clipper/documentation/Docs/Units/ClipperLib/Classes/ClipperOffset/Properties/ArcTolerance.htm
559 
560  if( aCircleSegmentsCount < 6 ) // avoid incorrect aCircleSegmentsCount values
561  aCircleSegmentsCount = 6;
562 
563  double coeff;
564 
565  if( aCircleSegmentsCount > SEG_CNT_MAX || arc_tolerance_factor[aCircleSegmentsCount] == 0 )
566  {
567  coeff = 1.0 - cos( M_PI/aCircleSegmentsCount);
568 
569  if( aCircleSegmentsCount <= SEG_CNT_MAX )
570  arc_tolerance_factor[aCircleSegmentsCount] = coeff;
571  }
572  else
573  coeff = arc_tolerance_factor[aCircleSegmentsCount];
574 
575  c.ArcTolerance = std::abs( aFactor ) * coeff;
576 
577  c.Execute( solution, aFactor );
578 
579  importTree( &solution );
580 }
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  Append( aNewVertex );
207  }
208  else
209  {
210  // Assure the position to be inserted exists; throw an exception otherwise
211  if( GetRelativeIndices( aGlobalIndex, &index ) )
212  m_polys[index.m_polygon][index.m_contour].Insert( index.m_vertex, aNewVertex );
213  else
214  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
215  }
216 
217 }
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 340 of file shape_poly_set.cpp.

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

Referenced by IsSelfIntersecting().

341 {
342  // Get polygon
343  const POLYGON poly = CPolygon( aPolygonIndex );
344 
345  SEGMENT_ITERATOR iterator = IterateSegmentsWithHoles( aPolygonIndex );
346  SEGMENT_ITERATOR innerIterator;
347 
348  for( iterator = IterateSegmentsWithHoles( aPolygonIndex ); iterator; iterator++ )
349  {
350  SEG firstSegment = *iterator;
351 
352  // Iterate through all remaining segments.
353  innerIterator = iterator;
354 
355  // Start in the next segment, we don't want to check collision between a segment and itself
356  for( innerIterator++; innerIterator; innerIterator++ )
357  {
358  SEG secondSegment = *innerIterator;
359 
360  // Check whether the two segments built collide, only when they are not adjacent.
361  if( !iterator.IsAdjacent( innerIterator ) && firstSegment.Collide( secondSegment, 0 ) )
362  return true;
363  }
364  }
365 
366  return false;
367 }
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 370 of file shape_poly_set.cpp.

References IsPolygonSelfIntersecting(), and m_polys.

Referenced by BOARD::NormalizeAreaPolygon().

371 {
372  for( unsigned int polygon = 0; polygon < m_polys.size(); polygon++ )
373  {
374  if( IsPolygonSelfIntersecting( polygon ) )
375  return true;
376  }
377 
378  return false;
379 }
bool IsPolygonSelfIntersecting(int aPolygonIndex)
Function IsPolygonSelfIntersecting.
bool SHAPE_POLY_SET::IsSolid ( ) const
inlineoverridevirtual

Implements SHAPE.

Definition at line 792 of file shape_poly_set.h.

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

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

Referenced by PCB_EDIT_FRAME::createPopUpMenuForZones().

1433 {
1434  VERTEX_INDEX index;
1435 
1436  // Get the polygon and contour where the vertex is. If the vertex does not exist, return false
1437  if( !GetRelativeIndices( aGlobalIdx, &index ) )
1438  return false;
1439 
1440  // The contour is a hole if its index is greater than zero
1441  return index.m_contour > 0;
1442 }
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 565 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 ZONE_CONTAINER::DrawWhileCreateOutline(), ZONE_CONTAINER::Iterate(), ZONE_CONTAINER::Mirror(), and ZONE_CONTAINER::Rotate().

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

References Iterate().

586  {
587  return Iterate( aOutline, aOutline );
588  }
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 606 of file shape_poly_set.h.

References OutlineCount().

Referenced by Iterate(), and IterateWithHoles().

607  {
608  return Iterate( 0, OutlineCount() - 1 );
609  }
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 656 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.

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

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

References IterateSegments().

693  {
694  return IterateSegments( aPolygonIdx, aPolygonIdx );
695  }
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 698 of file shape_poly_set.h.

References OutlineCount().

Referenced by IterateSegments(), and IterateSegmentsWithHoles().

699  {
700  return IterateSegments( 0, OutlineCount() - 1 );
701  }
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 704 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().

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

References IterateSegments().

711  {
712  return IterateSegments( aOutline, aOutline, true );
713  }
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 596 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().

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

References Iterate(), and OutlineCount().

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

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

Referenced by ZONE_CONTAINER::Move().

1294 {
1295  for( POLYGON &poly : m_polys )
1296  {
1297  for( SHAPE_LINE_CHAIN &path : poly )
1298  {
1299  path.Move( aVector );
1300  }
1301  }
1302 }
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(), and ZONE_CONTAINER::NewHole().

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(), ZONE_CREATE_HELPER::performZoneCutout(), 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 850 of file shape_poly_set.cpp.

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

Referenced by BOARD::NormalizeAreaPolygon().

851 {
852  // We are expecting only one main outline, but this main outline can have holes
853  // if holes: combine holes and remove them from the main outline.
854  // Note also we are using SHAPE_POLY_SET::PM_STRICTLY_SIMPLE in polygon
855  // calculations, but it is not mandatory. It is used mainly
856  // because there is usually only very few vertices in area outlines
857  SHAPE_POLY_SET::POLYGON& outline = Polygon( 0 );
858  SHAPE_POLY_SET holesBuffer;
859 
860  // Move holes stored in outline to holesBuffer:
861  // The first SHAPE_LINE_CHAIN is the main outline, others are holes
862  while( outline.size() > 1 )
863  {
864  holesBuffer.AddOutline( outline.back() );
865  outline.pop_back();
866  }
867 
869 
870  // If any hole, substract it to main outline
871  if( holesBuffer.OutlineCount() )
872  {
873  holesBuffer.Simplify( SHAPE_POLY_SET::PM_FAST);
875  }
876 
878 
879  return OutlineCount();
880 }
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 493 of file shape_poly_set.h.

References m_polys.

Referenced by RN_NET::AddItem(), 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().

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

Reimplemented from SHAPE.

Definition at line 905 of file shape_poly_set.cpp.

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

906 {
907  std::string tmp;
908 
909  aStream >> tmp;
910 
911  if( tmp != "polyset" )
912  return false;
913 
914  aStream >> tmp;
915 
916  int n_polys = atoi( tmp.c_str() );
917 
918  if( n_polys < 0 )
919  return false;
920 
921  for( int i = 0; i < n_polys; i++ )
922  {
923  POLYGON paths;
924 
925  aStream >> tmp;
926 
927  if( tmp != "poly" )
928  return false;
929 
930  aStream >> tmp;
931  int n_outlines = atoi( tmp.c_str() );
932 
933  if( n_outlines < 0 )
934  return false;
935 
936  for( int j = 0; j < n_outlines; j++ )
937  {
938  SHAPE_LINE_CHAIN outline;
939 
940  outline.SetClosed( true );
941 
942  aStream >> tmp;
943  int n_vertices = atoi( tmp.c_str() );
944  for( int v = 0; v < n_vertices; v++ )
945  {
946  VECTOR2I p;
947 
948  aStream >> tmp; p.x = atoi( tmp.c_str() );
949  aStream >> tmp; p.y = atoi( tmp.c_str() );
950  outline.Append( p );
951  }
952 
953  paths.push_back( outline );
954  }
955 
956  m_polys.push_back( paths );
957  }
958  return true;
959 }
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 1228 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().

1229 {
1230  int result = 0;
1231  int cnt = aPath.PointCount();
1232 
1233  if ( !aPath.BBox().Contains( aP ) ) // test with bounding box first
1234  return false;
1235 
1236  if( cnt < 3 )
1237  return false;
1238 
1239  VECTOR2I ip = aPath.CPoint( 0 );
1240 
1241  for( int i = 1; i <= cnt; ++i )
1242  {
1243  VECTOR2I ipNext = ( i == cnt ? aPath.CPoint( 0 ) : aPath.CPoint( i ) );
1244 
1245  if( ipNext.y == aP.y )
1246  {
1247  if( ( ipNext.x == aP.x ) || ( ip.y == aP.y &&
1248  ( ( ipNext.x > aP.x ) == ( ip.x < aP.x ) ) ) )
1249  return true;
1250  }
1251 
1252  if( ( ip.y < aP.y ) != ( ipNext.y < aP.y ) )
1253  {
1254  if( ip.x >= aP.x )
1255  {
1256  if( ipNext.x > aP.x )
1257  result = 1 - result;
1258  else
1259  {
1260  int64_t d = (int64_t)( ip.x - aP.x ) * (int64_t)( ipNext.y - aP.y ) -
1261  (int64_t)( ipNext.x - aP.x ) * (int64_t)( ip.y - aP.y );
1262 
1263  if( !d )
1264  return true;
1265 
1266  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1267  result = 1 - result;
1268  }
1269  }
1270  else
1271  {
1272  if( ipNext.x > aP.x )
1273  {
1274  int64_t d = (int64_t)( ip.x - aP.x ) * (int64_t)( ipNext.y - aP.y ) -
1275  (int64_t)( ipNext.x - aP.x ) * (int64_t)( ip.y - aP.y );
1276 
1277  if( !d )
1278  return true;
1279 
1280  if( ( d > 0 ) == ( ipNext.y > ip.y ) )
1281  result = 1 - result;
1282  }
1283  }
1284  }
1285 
1286  ip = ipNext;
1287  }
1288 
1289  return result ? true : false;
1290 }
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 979 of file shape_poly_set.cpp.

980 {
981  // Iterate through all the polygons in the set
982  for( const POLYGON& polygon : m_polys )
983  {
984  // Iterate through all the line chains in the polygon
985  for( const SHAPE_LINE_CHAIN& lineChain : polygon )
986  {
987  if( lineChain.PointOnEdge( aP ) )
988  return true;
989  }
990  }
991 
992  return false;
993 }
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 1018 of file shape_poly_set.cpp.

Referenced by PCB_EDIT_FRAME::Delete_Zone_Contour().

1019 {
1020  // Default polygon is the last one
1021  if( aPolygonIdx < 0 )
1022  aPolygonIdx += m_polys.size();
1023 
1024  m_polys[aPolygonIdx].erase( m_polys[aPolygonIdx].begin() + aContourIdx );
1025 }
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 1028 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().

1029 {
1030  int removed = 0;
1031 
1032  ITERATOR iterator = IterateWithHoles();
1033 
1034  VECTOR2I contourStart = *iterator;
1035  VECTOR2I segmentStart, segmentEnd;
1036 
1037  VERTEX_INDEX indexStart;
1038 
1039  while( iterator )
1040  {
1041  // Obtain first point and its index
1042  segmentStart = *iterator;
1043  indexStart = iterator.GetIndex();
1044 
1045  // Obtain last point
1046  if( iterator.IsEndContour() )
1047  {
1048  segmentEnd = contourStart;
1049 
1050  // Advance
1051  iterator++;
1052 
1053  if( iterator )
1054  contourStart = *iterator;
1055  }
1056  else
1057  {
1058  // Advance
1059  iterator++;
1060 
1061  if( iterator )
1062  segmentEnd = *iterator;
1063  }
1064 
1065  // Remove segment start if both points are equal
1066  if( segmentStart == segmentEnd )
1067  {
1068  RemoveVertex( indexStart );
1069  removed++;
1070 
1071  // Advance the iterator one position, as there is one vertex less.
1072  if( iterator )
1073  iterator++;
1074  }
1075  }
1076 
1077  return removed;
1078 }
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 1188 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().

1189 {
1190  VERTEX_INDEX index;
1191 
1192  // Assure the to be removed vertex exists, abort otherwise
1193  if( GetRelativeIndices( aGlobalIndex, &index ) )
1194  RemoveVertex( index );
1195  else
1196  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
1197 }
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 1200 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.

1201 {
1202  m_polys[aIndex.m_polygon][aIndex.m_contour].Remove( aIndex.m_vertex );
1203 }
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 842 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().

843 {
845 
846  booleanOp( ctUnion, empty, aFastMode );
847 }
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 239 of file shape_poly_set.cpp.

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

Referenced by UnitSet().

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

Referenced by POINT_EDITOR::addCorner(), 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().

1306 {
1307  int c = 0;
1308 
1309  for( const POLYGON& poly : m_polys )
1310  {
1311  for( const SHAPE_LINE_CHAIN& path : poly )
1312  {
1313  c += path.PointCount();
1314  }
1315  }
1316 
1317  return c;
1318 }
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
void SHAPE_POLY_SET::Unfracture ( )

Converts a set of slitted polygons to a set of polygons with holes

SHAPE_POLY_SET SHAPE_POLY_SET::UnitSet ( int  aPolygonIndex)
inline

Definition at line 523 of file shape_poly_set.h.

References Subset().

Referenced by BOARD::NormalizeAreaPolygon().

524  {
525  return Subset( aPolygonIndex, aPolygonIndex + 1 );
526  }
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 254 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(), 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().

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

Returns the aGlobalIndex-th vertex in the poly set

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

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

317 {
318  return Vertex( index.m_vertex, index.m_polygon, index.m_contour - 1 );
319 }
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 220 of file shape_poly_set.cpp.

References m_polys.

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

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: