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 
387  bool GetRelativeIndices( int aGlobalIdx, VERTEX_INDEX* aRelativeIndices) const;
388 
398  bool GetGlobalIndex( VERTEX_INDEX aRelativeIndices, int& aGlobalIdx );
399 
401  SHAPE* Clone() const override;
402 
404  int NewOutline();
405 
407  int NewHole( int aOutline = -1 );
408 
410  int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
411 
413  int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
414 
416 
428  int Append( int x, int y, int aOutline = -1, int aHole = -1,
429  bool aAllowDuplication = false );
430 
432  void Append( const SHAPE_POLY_SET& aSet );
433 
435  void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
436 
444  void InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex );
445 
447  VECTOR2I& Vertex( int aIndex, int aOutline, int aHole );
448 
450  const VECTOR2I& CVertex( int aIndex, int aOutline, int aHole ) const;
451 
453  VECTOR2I& Vertex( int aGlobalIndex );
454 
456  const VECTOR2I& CVertex( int aGlobalIndex ) const;
457 
459  VECTOR2I& Vertex( VERTEX_INDEX aIndex );
460 
462  const VECTOR2I& CVertex( VERTEX_INDEX aIndex ) const;
463 
473  SEG Edge( int aGlobalIndex );
474 
475 
483  bool IsPolygonSelfIntersecting( int aPolygonIndex );
484 
490  bool IsSelfIntersecting();
491 
493  int OutlineCount() const { return m_polys.size(); }
494 
496  int VertexCount( int aOutline = -1, int aHole = -1 ) const;
497 
499  int HoleCount( int aOutline ) const
500  {
501  if( (aOutline > (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
502  return 0;
503  return m_polys[aOutline].size() - 1;
504  }
505 
507  SHAPE_LINE_CHAIN& Outline( int aIndex )
508  {
509  return m_polys[aIndex][0];
510  }
511 
521  SHAPE_POLY_SET Subset( int aFirstPolygon, int aLastPolygon );
522 
523  SHAPE_POLY_SET UnitSet( int aPolygonIndex )
524  {
525  return Subset( aPolygonIndex, aPolygonIndex + 1 );
526  }
527 
529  SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
530  {
531  return m_polys[aOutline][aHole + 1];
532  }
533 
535  POLYGON& Polygon( int aIndex )
536  {
537  return m_polys[aIndex];
538  }
539 
540  const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
541  {
542  return m_polys[aIndex][0];
543  }
544 
545  const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
546  {
547  return m_polys[aOutline][aHole + 1];
548  }
549 
550  const POLYGON& CPolygon( int aIndex ) const
551  {
552  return m_polys[aIndex];
553  }
554 
565  ITERATOR Iterate( int aFirst, int aLast, bool aIterateHoles = false )
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  }
578 
585  ITERATOR Iterate( int aOutline )
586  {
587  return Iterate( aOutline, aOutline );
588  }
589 
596  ITERATOR IterateWithHoles( int aOutline )
597  {
598  return Iterate( aOutline, aOutline, true );
599  }
600 
606  ITERATOR Iterate()
607  {
608  return Iterate( 0, OutlineCount() - 1 );
609  }
610 
616  ITERATOR IterateWithHoles()
617  {
618  return Iterate( 0, OutlineCount() - 1, true );
619  }
620 
621 
622  CONST_ITERATOR CIterate( int aFirst, int aLast, bool aIterateHoles = false ) const
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  }
635 
636  CONST_ITERATOR CIterate( int aOutline ) const
637  {
638  return CIterate( aOutline, aOutline );
639  }
640 
641  CONST_ITERATOR CIterateWithHoles( int aOutline ) const
642  {
643  return CIterate( aOutline, aOutline, true );
644  }
645 
646  CONST_ITERATOR CIterate() const
647  {
648  return CIterate( 0, OutlineCount() - 1 );
649  }
650 
651  CONST_ITERATOR CIterateWithHoles() const
652  {
653  return CIterate( 0, OutlineCount() - 1, true );
654  }
655 
656  ITERATOR IterateFromVertexWithHoles( int aGlobalIdx )
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  }
674 
677  SEGMENT_ITERATOR IterateSegments( int aFirst, int aLast, bool aIterateHoles = false )
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  }
690 
692  SEGMENT_ITERATOR IterateSegments( int aPolygonIdx )
693  {
694  return IterateSegments( aPolygonIdx, aPolygonIdx );
695  }
696 
698  SEGMENT_ITERATOR IterateSegments()
699  {
700  return IterateSegments( 0, OutlineCount() - 1 );
701  }
702 
704  SEGMENT_ITERATOR IterateSegmentsWithHoles()
705  {
706  return IterateSegments( 0, OutlineCount() - 1, true );
707  }
708 
710  SEGMENT_ITERATOR IterateSegmentsWithHoles( int aOutline )
711  {
712  return IterateSegments( aOutline, aOutline, true );
713  }
714 
723  {
724  PM_FAST = true,
726  };
727 
730  void BooleanAdd( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
731 
734  void BooleanSubtract( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
735 
738  void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
739 
742  void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
743  POLYGON_MODE aFastMode );
744 
747  void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
748  POLYGON_MODE aFastMode );
749 
752  void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
753  POLYGON_MODE aFastMode );
754 
756  void Inflate( int aFactor, int aCircleSegmentsCount );
757 
761  void Fracture( POLYGON_MODE aFastMode );
762 
764  void Unfracture();
765 
767  bool HasHoles() const;
768 
771  void Simplify( POLYGON_MODE aFastMode );
772 
780  int NormalizeAreaOutlines();
781 
783  const std::string Format() const override;
784 
786  bool Parse( std::stringstream& aStream ) override;
787 
789  void Move( const VECTOR2I& aVector ) override;
790 
792  bool IsSolid() const override
793  {
794  return true;
795  }
796 
797  const BOX2I BBox( int aClearance = 0 ) const override;
798 
806  bool PointOnEdge( const VECTOR2I& aP ) const;
807 
819  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
820 
821  // fixme: add collision support
822  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override { return false; }
823 
834  bool CollideVertex( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
835  int aClearance = 0 );
836 
847  bool CollideEdge( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
848  int aClearance = 0 );
849 
852  bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1 ) const;
853 
855  bool IsEmpty() const
856  {
857  return m_polys.size() == 0;
858  }
859 
865  void RemoveVertex( int aGlobalIndex );
866 
872  void RemoveVertex( VERTEX_INDEX aRelativeIndices );
873 
875  void RemoveAllContours();
876 
885  void RemoveContour( int aContourIdx, int aPolygonIdx = -1 );
886 
892  int RemoveNullSegments();
893 
895  int TotalVertices() const;
896 
898  void DeletePolygon( int aIdx );
899 
907  POLYGON ChamferPolygon( unsigned int aDistance, int aIndex = 0 );
908 
917  POLYGON FilletPolygon( unsigned int aRadius, unsigned int aSegments, int aIndex = 0 );
918 
925  SHAPE_POLY_SET Chamfer( int aDistance );
926 
934  SHAPE_POLY_SET Fillet( int aRadius, int aSegments );
935 
944  int DistanceToPolygon( VECTOR2I aPoint, int aIndex );
945 
958  int DistanceToPolygon( SEG aSegment, int aIndex, int aSegmentWidth = 0 );
959 
967  int Distance( VECTOR2I point );
968 
977  int Distance( SEG aSegment, int aSegmentWidth = 0 );
978 
985  bool IsVertexInHole( int aGlobalIdx );
986 
987  private:
988 
989  SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
990  VECTOR2I& vertex( int aCornerId );
991  const VECTOR2I& cvertex( int aCornerId ) const;
992 
993 
994  void fractureSingle( POLYGON& paths );
995  void importTree( ClipperLib::PolyTree* tree );
996 
1008  void booleanOp( ClipperLib::ClipType aType,
1009  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1010 
1011  void booleanOp( ClipperLib::ClipType aType,
1012  const SHAPE_POLY_SET& aShape,
1013  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1014 
1015  bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
1016 
1017  const ClipperLib::Path convertToClipper( const SHAPE_LINE_CHAIN& aPath, bool aRequiredOrientation );
1018  const SHAPE_LINE_CHAIN convertFromClipper( const ClipperLib::Path& aPath );
1019 
1031  bool containsSingle( const VECTOR2I& aP, int aSubpolyIndex ) const;
1032 
1039  {
1042  };
1043 
1058  POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
1059  int aIndex, int aSegments = -1 );
1060 
1061  typedef std::vector<POLYGON> Polyset;
1062 
1063  Polyset m_polys;
1064 };
1065 
1066 #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)
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 Unfracture()
Converts a set of slitted polygons to a set of polygons with holes
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 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.
SEG Edge(int aGlobalIndex)
Function Edge Returns a reference to the aGlobalIndex-th segment in the polygon set.
int Distance(VECTOR2I point)
Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the s...
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)