KiCad PCB EDA Suite
shape_poly_set.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2017 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Alejandro GarcĂ­a Montoro <alejandro.garciamontoro@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef __SHAPE_POLY_SET_H
27 #define __SHAPE_POLY_SET_H
28 
29 #include <vector>
30 #include <cstdio>
31 #include <geometry/shape.h>
33 
34 #include "clipper.hpp"
35 
36 
53 class SHAPE_POLY_SET : public SHAPE
54 {
55  public:
58  typedef std::vector<SHAPE_LINE_CHAIN> POLYGON;
59 
67  typedef struct VERTEX_INDEX
68  {
69  int m_polygon;
70  int m_contour;
71  int m_vertex;
73  VERTEX_INDEX() : m_polygon(-1), m_contour(-1), m_vertex(-1)
74  {
75  }
76  } VERTEX_INDEX;
77 
83  template <class T>
85  {
86  public:
87 
93  bool IsEndContour() const
94  {
95  return m_currentVertex + 1 == m_poly->CPolygon( m_currentPolygon )[m_currentContour].PointCount();
96  }
97 
102  bool IsLastPolygon() const
103  {
105  }
106 
107  operator bool() const
108  {
110  }
111 
117  void Advance()
118  {
119  // Advance vertex index
120  m_currentVertex ++;
121 
122  // Check whether the user wants to iterate through the vertices of the holes
123  // and behave accordingly
124  if( m_iterateHoles )
125  {
126  // If the last vertex of the contour was reached, advance the contour index
128  {
129  m_currentVertex = 0;
131 
132  // If the last contour of the current polygon was reached, advance the
133  // outline index
134  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
135 
136  if( m_currentContour >= totalContours )
137  {
138  m_currentContour = 0;
140  }
141  }
142  }
143  else
144  {
145  // If the last vertex of the outline was reached, advance to the following polygon
146  if( m_currentVertex >= m_poly->CPolygon( m_currentPolygon )[0].PointCount() )
147  {
148  m_currentVertex = 0;
150  }
151  }
152  }
153 
154  void operator++( int dummy )
155  {
156  Advance();
157  }
158 
159  void operator++()
160  {
161  Advance();
162  }
163 
164  T& Get()
165  {
167  }
168 
170  {
171  return Get();
172  }
173 
175  {
176  return &Get();
177  }
178 
184  {
185  VERTEX_INDEX index;
186 
187  index.m_polygon = m_currentPolygon;
188  index.m_contour = m_currentContour;
189  index.m_vertex = m_currentVertex;
190 
191  return index;
192  }
193 
194 
195  private:
196  friend class SHAPE_POLY_SET;
197 
204  };
205 
211  template <class T>
213  {
214  public:
219  bool IsLastPolygon() const
220  {
222  }
223 
224  operator bool() const
225  {
227  }
228 
234  void Advance()
235  {
236  // Advance vertex index
238  int last;
239 
240  // Check whether the user wants to iterate through the vertices of the holes
241  // and behave accordingly
242  if( m_iterateHoles )
243  {
244  last = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
245 
246  // If the last vertex of the contour was reached, advance the contour index
247  if( m_currentSegment >= last )
248  {
249  m_currentSegment = 0;
251 
252  // If the last contour of the current polygon was reached, advance the
253  // outline index
254  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
255 
256  if( m_currentContour >= totalContours )
257  {
258  m_currentContour = 0;
260  }
261  }
262  }
263  else
264  {
265  last = m_poly->CPolygon( m_currentPolygon )[0].SegmentCount();
266  // If the last vertex of the outline was reached, advance to the following
267  // polygon
268  if( m_currentSegment >= last )
269  {
270  m_currentSegment = 0;
272  }
273  }
274  }
275 
276  void operator++( int dummy )
277  {
278  Advance();
279  }
280 
281  void operator++()
282  {
283  Advance();
284  }
285 
286  T Get()
287  {
289  }
290 
292  {
293  return Get();
294  }
295 
301  {
302  VERTEX_INDEX index;
303 
304  index.m_polygon = m_currentPolygon;
305  index.m_contour = m_currentContour;
306  index.m_vertex = m_currentSegment;
307 
308  return index;
309  }
310 
319  {
320  // Check that both iterators point to the same contour of the same polygon of the
321  // same polygon set
322  if( m_poly == aOther.m_poly && m_currentPolygon == aOther.m_currentPolygon &&
324  {
325  // Compute the total number of segments
326  int numSeg;
327  numSeg = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
328 
329  // Compute the difference of the segment indices. If it is exactly one, they
330  // are adjacent. The only missing case where they also are adjacent is when
331  // the segments are the first and last one, in which case the difference
332  // always equals the total number of segments minus one.
333  int indexDiff = abs( m_currentSegment - aOther.m_currentSegment );
334 
335  return ( indexDiff == 1 ) || ( indexDiff == (numSeg - 1) );
336  }
337 
338  return false;
339  }
340 
341  private:
342  friend class SHAPE_POLY_SET;
343 
350  };
351 
352  // Iterator and const iterator types to visit polygon's points.
355 
356  // Iterator and const iterator types to visit polygon's edges.
359 
360  SHAPE_POLY_SET();
361 
367  SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther );
368 
369  ~SHAPE_POLY_SET();
370 
383  bool GetRelativeIndices( int aGlobalIdx, VERTEX_INDEX* aRelativeIndices) const;
384 
394  bool GetGlobalIndex( VERTEX_INDEX aRelativeIndices, int& aGlobalIdx );
395 
397  SHAPE* Clone() const override;
398 
400  int NewOutline();
401 
403  int NewHole( int aOutline = -1 );
404 
406  int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
407 
409  int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
410 
412 
424  int Append( int x, int y, int aOutline = -1, int aHole = -1,
425  bool aAllowDuplication = false );
426 
428  void Append( const SHAPE_POLY_SET& aSet );
429 
431  void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
432 
440  void InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex );
441 
443  VECTOR2I& Vertex( int aIndex, int aOutline, int aHole );
444 
446  const VECTOR2I& CVertex( int aIndex, int aOutline, int aHole ) const;
447 
449  VECTOR2I& Vertex( int aGlobalIndex );
450 
452  const VECTOR2I& CVertex( int aGlobalIndex ) const;
453 
455  VECTOR2I& Vertex( VERTEX_INDEX aIndex );
456 
458  const VECTOR2I& CVertex( VERTEX_INDEX aIndex ) const;
459 
471  bool GetNeighbourIndexes( int aGlobalIndex, int* aPrevious, int* aNext );
472 
473 
481  bool IsPolygonSelfIntersecting( int aPolygonIndex );
482 
488  bool IsSelfIntersecting();
489 
491  int OutlineCount() const { return m_polys.size(); }
492 
494  int VertexCount( int aOutline = -1, int aHole = -1 ) const;
495 
497  int HoleCount( int aOutline ) const
498  {
499  if( (aOutline > (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
500  return 0;
501  return m_polys[aOutline].size() - 1;
502  }
503 
505  SHAPE_LINE_CHAIN& Outline( int aIndex )
506  {
507  return m_polys[aIndex][0];
508  }
509 
519  SHAPE_POLY_SET Subset( int aFirstPolygon, int aLastPolygon );
520 
521  SHAPE_POLY_SET UnitSet( int aPolygonIndex )
522  {
523  return Subset( aPolygonIndex, aPolygonIndex + 1 );
524  }
525 
527  SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
528  {
529  return m_polys[aOutline][aHole + 1];
530  }
531 
533  POLYGON& Polygon( int aIndex )
534  {
535  return m_polys[aIndex];
536  }
537 
538  const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
539  {
540  return m_polys[aIndex][0];
541  }
542 
543  const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
544  {
545  return m_polys[aOutline][aHole + 1];
546  }
547 
548  const POLYGON& CPolygon( int aIndex ) const
549  {
550  return m_polys[aIndex];
551  }
552 
563  ITERATOR Iterate( int aFirst, int aLast, bool aIterateHoles = false )
564  {
565  ITERATOR iter;
566 
567  iter.m_poly = this;
568  iter.m_currentPolygon = aFirst;
569  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
570  iter.m_currentContour = 0;
571  iter.m_currentVertex = 0;
572  iter.m_iterateHoles = aIterateHoles;
573 
574  return iter;
575  }
576 
583  ITERATOR Iterate( int aOutline )
584  {
585  return Iterate( aOutline, aOutline );
586  }
587 
594  ITERATOR IterateWithHoles( int aOutline )
595  {
596  return Iterate( aOutline, aOutline, true );
597  }
598 
604  ITERATOR Iterate()
605  {
606  return Iterate( 0, OutlineCount() - 1 );
607  }
608 
614  ITERATOR IterateWithHoles()
615  {
616  return Iterate( 0, OutlineCount() - 1, true );
617  }
618 
619 
620  CONST_ITERATOR CIterate( int aFirst, int aLast, bool aIterateHoles = false ) const
621  {
622  CONST_ITERATOR iter;
623 
624  iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
625  iter.m_currentPolygon = aFirst;
626  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
627  iter.m_currentContour = 0;
628  iter.m_currentVertex = 0;
629  iter.m_iterateHoles = aIterateHoles;
630 
631  return iter;
632  }
633 
634  CONST_ITERATOR CIterate( int aOutline ) const
635  {
636  return CIterate( aOutline, aOutline );
637  }
638 
639  CONST_ITERATOR CIterateWithHoles( int aOutline ) const
640  {
641  return CIterate( aOutline, aOutline, true );
642  }
643 
644  CONST_ITERATOR CIterate() const
645  {
646  return CIterate( 0, OutlineCount() - 1 );
647  }
648 
649  CONST_ITERATOR CIterateWithHoles() const
650  {
651  return CIterate( 0, OutlineCount() - 1, true );
652  }
653 
654  ITERATOR IterateFromVertexWithHoles( int aGlobalIdx )
655  {
656  // Build iterator
657  ITERATOR iter = IterateWithHoles();
658 
659  // Get the relative indices of the globally indexed vertex
660  VERTEX_INDEX indices;
661 
662  if( !GetRelativeIndices( aGlobalIdx, &indices ) )
663  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
664 
665  // Adjust where the iterator is pointing
666  iter.m_currentPolygon = indices.m_polygon;
667  iter.m_currentContour = indices.m_contour;
668  iter.m_currentVertex = indices.m_vertex;
669 
670  return iter;
671  }
672 
675  SEGMENT_ITERATOR IterateSegments( int aFirst, int aLast, bool aIterateHoles = false )
676  {
677  SEGMENT_ITERATOR iter;
678 
679  iter.m_poly = this;
680  iter.m_currentPolygon = aFirst;
681  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
682  iter.m_currentContour = 0;
683  iter.m_currentSegment = 0;
684  iter.m_iterateHoles = aIterateHoles;
685 
686  return iter;
687  }
688 
690  SEGMENT_ITERATOR IterateSegments( int aPolygonIdx )
691  {
692  return IterateSegments( aPolygonIdx, aPolygonIdx );
693  }
694 
696  SEGMENT_ITERATOR IterateSegments()
697  {
698  return IterateSegments( 0, OutlineCount() - 1 );
699  }
700 
702  SEGMENT_ITERATOR IterateSegmentsWithHoles()
703  {
704  return IterateSegments( 0, OutlineCount() - 1, true );
705  }
706 
708  SEGMENT_ITERATOR IterateSegmentsWithHoles( int aOutline )
709  {
710  return IterateSegments( aOutline, aOutline, true );
711  }
712 
721  {
722  PM_FAST = true,
724  };
725 
728  void BooleanAdd( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
729 
732  void BooleanSubtract( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
733 
736  void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
737 
740  void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
741  POLYGON_MODE aFastMode );
742 
745  void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
746  POLYGON_MODE aFastMode );
747 
750  void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
751  POLYGON_MODE aFastMode );
752 
754  void Inflate( int aFactor, int aCircleSegmentsCount );
755 
759  void Fracture( POLYGON_MODE aFastMode );
760 
762  bool HasHoles() const;
763 
766  void Simplify( POLYGON_MODE aFastMode );
767 
775  int NormalizeAreaOutlines();
776 
778  const std::string Format() const override;
779 
781  bool Parse( std::stringstream& aStream ) override;
782 
784  void Move( const VECTOR2I& aVector ) override;
785 
787  bool IsSolid() const override
788  {
789  return true;
790  }
791 
792  const BOX2I BBox( int aClearance = 0 ) const override;
793 
801  bool PointOnEdge( const VECTOR2I& aP ) const;
802 
814  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
815 
816  // fixme: add collision support
817  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override { return false; }
818 
829  bool CollideVertex( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
830  int aClearance = 0 );
831 
842  bool CollideEdge( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
843  int aClearance = 0 );
844 
847  bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1 ) const;
848 
850  bool IsEmpty() const
851  {
852  return m_polys.size() == 0;
853  }
854 
860  void RemoveVertex( int aGlobalIndex );
861 
867  void RemoveVertex( VERTEX_INDEX aRelativeIndices );
868 
870  void RemoveAllContours();
871 
880  void RemoveContour( int aContourIdx, int aPolygonIdx = -1 );
881 
887  int RemoveNullSegments();
888 
890  int TotalVertices() const;
891 
893  void DeletePolygon( int aIdx );
894 
902  POLYGON ChamferPolygon( unsigned int aDistance, int aIndex = 0 );
903 
912  POLYGON FilletPolygon( unsigned int aRadius, unsigned int aSegments, int aIndex = 0 );
913 
920  SHAPE_POLY_SET Chamfer( int aDistance );
921 
929  SHAPE_POLY_SET Fillet( int aRadius, int aSegments );
930 
939  int DistanceToPolygon( VECTOR2I aPoint, int aIndex );
940 
953  int DistanceToPolygon( SEG aSegment, int aIndex, int aSegmentWidth = 0 );
954 
962  int Distance( VECTOR2I aPoint );
963 
972  int Distance( SEG aSegment, int aSegmentWidth = 0 );
973 
980  bool IsVertexInHole( int aGlobalIdx );
981 
982  private:
983 
984  SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
985  VECTOR2I& vertex( int aCornerId );
986  const VECTOR2I& cvertex( int aCornerId ) const;
987 
988 
989  void fractureSingle( POLYGON& paths );
990  void importTree( ClipperLib::PolyTree* tree );
991 
1003  void booleanOp( ClipperLib::ClipType aType,
1004  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1005 
1006  void booleanOp( ClipperLib::ClipType aType,
1007  const SHAPE_POLY_SET& aShape,
1008  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1009 
1010  bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
1011 
1012  const ClipperLib::Path convertToClipper( const SHAPE_LINE_CHAIN& aPath, bool aRequiredOrientation );
1013  const SHAPE_LINE_CHAIN convertFromClipper( const ClipperLib::Path& aPath );
1014 
1026  bool containsSingle( const VECTOR2I& aP, int aSubpolyIndex ) const;
1027 
1034  {
1037  };
1038 
1053  POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
1054  int aIndex, int aSegments = -1 );
1055 
1056  typedef std::vector<POLYGON> Polyset;
1057 
1058  Polyset m_polys;
1059 };
1060 
1061 #endif
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
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, ...
int NewHole(int aOutline=-1)
Creates a new hole in a given outline
ITERATOR IterateFromVertexWithHoles(int aGlobalIdx)
POLYGON ChamferPolygon(unsigned int aDistance, int aIndex=0)
Function Chamfer returns a chamfered version of the aIndex-th polygon.
bool HasHoles() const
Returns true if the polygon set has any holes.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Returns the index-th vertex in a given hole outline within a given outline
void fractureSingle(POLYGON &paths)
SEGMENT_ITERATOR IterateSegmentsWithHoles()
Returns an iterator object, for all outlines in the set (with holes)
void BooleanAdd(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset union For aFastMode meaning, see function booleanOp
ITERATOR Iterate(int aOutline)
Function Iterate.
CONST_ITERATOR CIterate() const
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 polyg...
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
T
enum T contains all this lexer's tokens.
bool IsLastPolygon() const
Function IsLastOutline.
const ClipperLib::Path convertToClipper(const SHAPE_LINE_CHAIN &aPath, bool aRequiredOrientation)
SEGMENT_ITERATOR_TEMPLATE< const SEG > CONST_SEGMENT_ITERATOR
CONST_ITERATOR CIterateWithHoles(int aOutline) const
bool IsPolygonSelfIntersecting(int aPolygonIndex)
Function IsPolygonSelfIntersecting.
SEGMENT_ITERATOR_TEMPLATE< SEG > SEGMENT_ITERATOR
int NormalizeAreaOutlines()
Function NormalizeAreaOutlines Convert a self-intersecting polygon to one (or more) non self-intersec...
bool IsSolid() const override
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
bool Parse(std::stringstream &aStream) override
int TotalVertices() const
Returns total number of vertices stored in the set.
void Advance()
Function Advance advances the indices of the current vertex/outline/contour, checking whether the ver...
Struct VERTEX_INDEX.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Returns the reference to aHole-th hole in the aIndex-th outline
const VECTOR2I & cvertex(int aCornerId) const
Class SEGMENT_ITERATOR_TEMPLATE.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
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...
ITERATOR Iterate()
Function Iterate.
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 a...
int OutlineCount() const
Returns the number of outlines in the set
#define abs(a)
Definition: auxiliary.h:84
VERTEX_INDEX GetIndex()
Function GetIndex.
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
bool IsEndContour() const
Function IsEndContour.
bool IsVertexInHole(int aGlobalIdx)
Function IsVertexInHole.
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
void DeletePolygon(int aIdx)
Deletes aIdx-th polygon from the set
CONST_ITERATOR CIterate(int aOutline) const
SHAPE_LINE_CHAIN & getContourForCorner(int aCornerId, int &aIndexWithinContour)
bool GetNeighbourIndexes(int aGlobalIndex, int *aPrevious, int *aNext)
Returns the global indexes of the previous and the next corner of the aGlobalIndex-th corner of a con...
void Inflate(int aFactor, int aCircleSegmentsCount)
Performs outline inflation/deflation, using round corners.
SHAPE_POLY_SET Fillet(int aRadius, int aSegments)
Function Fillet returns a filleted version of the polygon set.
void Move(const VECTOR2I &aVector) override
ITERATOR IterateWithHoles(int aOutline)
Function IterateWithHoles.
Class SHAPE_POLY_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...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
SEGMENT_ITERATOR IterateSegments(int aPolygonIdx)
Returns an iterator object, for iterating aPolygonIdx-th polygon edges
void Advance()
Function Advance advances the indices of the current vertex/outline/contour, checking whether the ver...
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
bool IsAdjacent(SEGMENT_ITERATOR_TEMPLATE< T > aOther)
Function IsAdjacent.
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 p...
bool PointOnEdge(const VECTOR2I &aP) const
Function PointOnEdge()
SEGMENT_ITERATOR IterateSegmentsWithHoles(int aOutline)
Returns an iterator object, for the aOutline-th outline in the set (with holes)
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
Class SHAPE.
Definition: shape.h:57
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 poin...
const std::string Format() const override
int RemoveNullSegments()
Function RemoveNullSegments looks for null segments; ie, segments whose ends are exactly the same and...
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset intersection For aFastMode meaning, see function booleanOp ...
int NewOutline()
Creates a new empty polygon in the set and returns its index
void Fracture(POLYGON_MODE aFastMode)
Converts a set of polygons with holes to a singe outline with "slits"/"fractures" connecting the oute...
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index
VECTOR2I & vertex(int aCornerId)
ITERATOR_TEMPLATE< VECTOR2I > ITERATOR
bool pointInPolygon(const VECTOR2I &aP, const SHAPE_LINE_CHAIN &aPath) const
bool GetGlobalIndex(VERTEX_INDEX aRelativeIndices, int &aGlobalIdx)
Function GetGlobalIndex computes the global index of a vertex from the relative indices of polygon...
Definition: seg.h:37
int DistanceToPolygon(VECTOR2I aPoint, int aIndex)
Function DistanceToPolygon computes the minimum distance between the aIndex-th polygon and aPoint...
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
CORNER_MODE
Operations ChamferPolygon and FilletPolygon are computed under the private chamferFillet method; this...
SHAPE_POLY_SET Chamfer(int aDistance)
Function Chamfer returns a chamfered version of the polygon set.
SHAPE_POLY_SET UnitSet(int aPolygonIndex)
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...
const SHAPE_LINE_CHAIN convertFromClipper(const ClipperLib::Path &aPath)
ITERATOR IterateWithHoles()
Function IterateWithHoles.
Class SHAPE_LINE_CHAIN.
void RemoveVertex(int aGlobalIndex)
Function RemoveVertex deletes the aGlobalIndex-th vertex.
int Distance(VECTOR2I aPoint)
Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the s...
int VertexCount(int aOutline=-1, int aHole=-1) const
Returns the number of vertices in a given outline/hole
Class ITERATOR_TEMPLATE.
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
ITERATOR_TEMPLATE< const VECTOR2I > CONST_ITERATOR
bool IsLastPolygon() const
Function IsLastOutline.
const POLYGON & CPolygon(int aIndex) const
void InsertVertex(int aGlobalIndex, VECTOR2I aNewVertex)
Function InsertVertex Adds a vertex in the globally indexed position aGlobalIndex.
POLYGON_MODE
operations on polygons use a aFastMode param if aFastMode is PM_FAST (true) the result can be a weak ...
std::vector< POLYGON > Polyset
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset difference For aFastMode meaning, see function booleanOp ...
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
POLYGON FilletPolygon(unsigned int aRadius, unsigned int aSegments, int aIndex=0)
Function Fillet returns a filleted version of the aIndex-th polygon.
SHAPE * Clone() const override
Function Clone()
bool IsSelfIntersecting()
Function IsSelfIntersecting Checks whether any of the polygons in the set is self intersecting...
CONST_ITERATOR CIterateWithHoles() const
SEGMENT_ITERATOR IterateSegments()
Returns an iterator object, for all outlines in the set (no holes)
const BOX2I BBox(int aClearance=0) const override
Function BBox()
VERTEX_INDEX GetIndex()
Function GetIndex.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1) const
Returns true if a given subpolygon contains the point aP.
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 (de...
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...
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) ...
void RemoveContour(int aContourIdx, int aPolygonIdx=-1)
Function RemoveContour deletes the aContourIdx-th contour of the aPolygonIdx-th polygon in the set...
void importTree(ClipperLib::PolyTree *tree)