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 <memory>
32 #include <geometry/shape.h>
34 
35 #include <md5_hash.h>
36 
37 
54 class SHAPE_POLY_SET : public SHAPE
55 {
56  public:
60  typedef std::vector<SHAPE_LINE_CHAIN> POLYGON;
61 
63  {
64  public:
65  struct TRI
66  {
67  TRI( int _a = 0, int _b = 0, int _c = 0 ) : a( _a ), b( _b ), c( _c )
68  {
69  }
70 
71  int a, b, c;
72  };
73 
74  void Clear()
75  {
76  m_vertices.clear();
77  m_triangles.clear();
78  }
79 
80  void GetTriangle( int index, VECTOR2I& a, VECTOR2I& b, VECTOR2I& c ) const
81  {
82  auto tri = m_triangles[ index ];
83  a = m_vertices[ tri.a ];
84  b = m_vertices[ tri.b ];
85  c = m_vertices[ tri.c ];
86  }
87 
88  void AddTriangle( const TRI& aTri )
89  {
90  m_triangles.push_back( aTri );
91  }
92 
93  void AddTriangle( int a, int b, int c )
94  {
95  m_triangles.emplace_back( a, b, c );
96  }
97 
98  void AddVertex( const VECTOR2I& aP )
99  {
100  m_vertices.push_back( aP );
101  }
102 
103  size_t GetTriangleCount() const
104  {
105  return m_triangles.size();
106  }
107 
108  size_t GetVertexCount() const
109  {
110  return m_vertices.size();
111  }
112 
113  private:
114 
115  std::deque<TRI> m_triangles;
116  std::deque<VECTOR2I> m_vertices;
117  };
118 
126  typedef struct VERTEX_INDEX
127  {
128  int m_polygon;
129  int m_contour;
130  int m_vertex;
132  VERTEX_INDEX() : m_polygon(-1), m_contour(-1), m_vertex(-1)
133  {
134  }
135  } VERTEX_INDEX;
136 
142  template <class T>
144  {
145  public:
146 
152  bool IsEndContour() const
153  {
154  return m_currentVertex + 1 == m_poly->CPolygon( m_currentPolygon )[m_currentContour].PointCount();
155  }
156 
161  bool IsLastPolygon() const
162  {
163  return m_currentPolygon == m_lastPolygon;
164  }
165 
166  operator bool() const
167  {
168  return m_currentPolygon <= m_lastPolygon;
169  }
170 
176  void Advance()
177  {
178  // Advance vertex index
179  m_currentVertex ++;
180 
181  // Check whether the user wants to iterate through the vertices of the holes
182  // and behave accordingly
183  if( m_iterateHoles )
184  {
185  // If the last vertex of the contour was reached, advance the contour index
186  if( m_currentVertex >= m_poly->CPolygon( m_currentPolygon )[m_currentContour].PointCount() )
187  {
188  m_currentVertex = 0;
189  m_currentContour++;
190 
191  // If the last contour of the current polygon was reached, advance the
192  // outline index
193  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
194 
195  if( m_currentContour >= totalContours )
196  {
197  m_currentContour = 0;
198  m_currentPolygon++;
199  }
200  }
201  }
202  else
203  {
204  // If the last vertex of the outline was reached, advance to the following polygon
205  if( m_currentVertex >= m_poly->CPolygon( m_currentPolygon )[0].PointCount() )
206  {
207  m_currentVertex = 0;
208  m_currentPolygon++;
209  }
210  }
211  }
212 
213  void operator++( int dummy )
214  {
215  Advance();
216  }
217 
218  void operator++()
219  {
220  Advance();
221  }
222 
223  T& Get()
224  {
225  return m_poly->Polygon( m_currentPolygon )[m_currentContour].Point( m_currentVertex );
226  }
227 
229  {
230  return Get();
231  }
232 
234  {
235  return &Get();
236  }
237 
243  {
244  VERTEX_INDEX index;
245 
246  index.m_polygon = m_currentPolygon;
247  index.m_contour = m_currentContour;
248  index.m_vertex = m_currentVertex;
249 
250  return index;
251  }
252 
253 
254  private:
255  friend class SHAPE_POLY_SET;
256 
263  };
264 
270  template <class T>
272  {
273  public:
278  bool IsLastPolygon() const
279  {
280  return m_currentPolygon == m_lastPolygon;
281  }
282 
283  operator bool() const
284  {
285  return m_currentPolygon <= m_lastPolygon;
286  }
287 
293  void Advance()
294  {
295  // Advance vertex index
296  m_currentSegment++;
297  int last;
298 
299  // Check whether the user wants to iterate through the vertices of the holes
300  // and behave accordingly
301  if( m_iterateHoles )
302  {
303  last = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
304 
305  // If the last vertex of the contour was reached, advance the contour index
306  if( m_currentSegment >= last )
307  {
308  m_currentSegment = 0;
309  m_currentContour++;
310 
311  // If the last contour of the current polygon was reached, advance the
312  // outline index
313  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
314 
315  if( m_currentContour >= totalContours )
316  {
317  m_currentContour = 0;
318  m_currentPolygon++;
319  }
320  }
321  }
322  else
323  {
324  last = m_poly->CPolygon( m_currentPolygon )[0].SegmentCount();
325  // If the last vertex of the outline was reached, advance to the following
326  // polygon
327  if( m_currentSegment >= last )
328  {
329  m_currentSegment = 0;
330  m_currentPolygon++;
331  }
332  }
333  }
334 
335  void operator++( int dummy )
336  {
337  Advance();
338  }
339 
340  void operator++()
341  {
342  Advance();
343  }
344 
345  T Get()
346  {
347  return m_poly->Polygon( m_currentPolygon )[m_currentContour].Segment( m_currentSegment );
348  }
349 
351  {
352  return Get();
353  }
354 
360  {
361  VERTEX_INDEX index;
362 
363  index.m_polygon = m_currentPolygon;
364  index.m_contour = m_currentContour;
365  index.m_vertex = m_currentSegment;
366 
367  return index;
368  }
369 
378  {
379  // Check that both iterators point to the same contour of the same polygon of the
380  // same polygon set
381  if( m_poly == aOther.m_poly && m_currentPolygon == aOther.m_currentPolygon &&
382  m_currentContour == aOther.m_currentContour )
383  {
384  // Compute the total number of segments
385  int numSeg;
386  numSeg = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
387 
388  // Compute the difference of the segment indices. If it is exactly one, they
389  // are adjacent. The only missing case where they also are adjacent is when
390  // the segments are the first and last one, in which case the difference
391  // always equals the total number of segments minus one.
392  int indexDiff = abs( m_currentSegment - aOther.m_currentSegment );
393 
394  return ( indexDiff == 1 ) || ( indexDiff == (numSeg - 1) );
395  }
396 
397  return false;
398  }
399 
400  private:
401  friend class SHAPE_POLY_SET;
402 
409  };
410 
411  // Iterator and const iterator types to visit polygon's points.
414 
415  // Iterator and const iterator types to visit polygon's edges.
418 
419  SHAPE_POLY_SET();
420 
427  SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther, bool aDeepCopy = false );
428 
429  ~SHAPE_POLY_SET();
430 
443  bool GetRelativeIndices( int aGlobalIdx, VERTEX_INDEX* aRelativeIndices) const;
444 
454  bool GetGlobalIndex( VERTEX_INDEX aRelativeIndices, int& aGlobalIdx );
455 
457  SHAPE* Clone() const override;
458 
460  int NewOutline();
461 
463  int NewHole( int aOutline = -1 );
464 
466  int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
467 
469  int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
470 
472 
484  int Append( int x, int y, int aOutline = -1, int aHole = -1,
485  bool aAllowDuplication = false );
486 
488  void Append( const SHAPE_POLY_SET& aSet );
489 
491  void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
492 
500  void InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex );
501 
503  VECTOR2I& Vertex( int aIndex, int aOutline, int aHole );
504 
506  const VECTOR2I& CVertex( int aIndex, int aOutline, int aHole ) const;
507 
509  VECTOR2I& Vertex( int aGlobalIndex );
510 
512  const VECTOR2I& CVertex( int aGlobalIndex ) const;
513 
515  VECTOR2I& Vertex( VERTEX_INDEX aIndex );
516 
518  const VECTOR2I& CVertex( VERTEX_INDEX aIndex ) const;
519 
531  bool GetNeighbourIndexes( int aGlobalIndex, int* aPrevious, int* aNext );
532 
533 
541  bool IsPolygonSelfIntersecting( int aPolygonIndex );
542 
548  bool IsSelfIntersecting();
549 
551  unsigned int TriangulatedPolyCount() const { return m_triangulatedPolys.size(); }
552 
554  int OutlineCount() const { return m_polys.size(); }
555 
557  int VertexCount( int aOutline = -1, int aHole = -1 ) const;
558 
560  int HoleCount( int aOutline ) const
561  {
562  if( ( aOutline < 0 ) || (aOutline >= (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
563  return 0;
564 
565  // the first polygon in m_polys[aOutline] is the main contour,
566  // only others are holes:
567  return m_polys[aOutline].size() - 1;
568  }
569 
571  SHAPE_LINE_CHAIN& Outline( int aIndex )
572  {
573  return m_polys[aIndex][0];
574  }
575 
585  SHAPE_POLY_SET Subset( int aFirstPolygon, int aLastPolygon );
586 
587  SHAPE_POLY_SET UnitSet( int aPolygonIndex )
588  {
589  return Subset( aPolygonIndex, aPolygonIndex + 1 );
590  }
591 
593  SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
594  {
595  return m_polys[aOutline][aHole + 1];
596  }
597 
599  POLYGON& Polygon( int aIndex )
600  {
601  return m_polys[aIndex];
602  }
603 
604  const POLYGON& Polygon( int aIndex ) const
605  {
606  return m_polys[aIndex];
607  }
608 
609  const TRIANGULATED_POLYGON* TriangulatedPolygon( int aIndex ) const
610  {
611  return m_triangulatedPolys[aIndex].get();
612  }
613 
614  const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
615  {
616  return m_polys[aIndex][0];
617  }
618 
619  const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
620  {
621  return m_polys[aOutline][aHole + 1];
622  }
623 
624  const POLYGON& CPolygon( int aIndex ) const
625  {
626  return m_polys[aIndex];
627  }
628 
639  ITERATOR Iterate( int aFirst, int aLast, bool aIterateHoles = false )
640  {
641  ITERATOR iter;
642 
643  iter.m_poly = this;
644  iter.m_currentPolygon = aFirst;
645  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
646  iter.m_currentContour = 0;
647  iter.m_currentVertex = 0;
648  iter.m_iterateHoles = aIterateHoles;
649 
650  return iter;
651  }
652 
659  ITERATOR Iterate( int aOutline )
660  {
661  return Iterate( aOutline, aOutline );
662  }
663 
670  ITERATOR IterateWithHoles( int aOutline )
671  {
672  return Iterate( aOutline, aOutline, true );
673  }
674 
680  ITERATOR Iterate()
681  {
682  return Iterate( 0, OutlineCount() - 1 );
683  }
684 
690  ITERATOR IterateWithHoles()
691  {
692  return Iterate( 0, OutlineCount() - 1, true );
693  }
694 
695 
696  CONST_ITERATOR CIterate( int aFirst, int aLast, bool aIterateHoles = false ) const
697  {
698  CONST_ITERATOR iter;
699 
700  iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
701  iter.m_currentPolygon = aFirst;
702  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
703  iter.m_currentContour = 0;
704  iter.m_currentVertex = 0;
705  iter.m_iterateHoles = aIterateHoles;
706 
707  return iter;
708  }
709 
710  CONST_ITERATOR CIterate( int aOutline ) const
711  {
712  return CIterate( aOutline, aOutline );
713  }
714 
715  CONST_ITERATOR CIterateWithHoles( int aOutline ) const
716  {
717  return CIterate( aOutline, aOutline, true );
718  }
719 
720  CONST_ITERATOR CIterate() const
721  {
722  return CIterate( 0, OutlineCount() - 1 );
723  }
724 
725  CONST_ITERATOR CIterateWithHoles() const
726  {
727  return CIterate( 0, OutlineCount() - 1, true );
728  }
729 
730  ITERATOR IterateFromVertexWithHoles( int aGlobalIdx )
731  {
732  // Build iterator
733  ITERATOR iter = IterateWithHoles();
734 
735  // Get the relative indices of the globally indexed vertex
736  VERTEX_INDEX indices;
737 
738  if( !GetRelativeIndices( aGlobalIdx, &indices ) )
739  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
740 
741  // Adjust where the iterator is pointing
742  iter.m_currentPolygon = indices.m_polygon;
743  iter.m_currentContour = indices.m_contour;
744  iter.m_currentVertex = indices.m_vertex;
745 
746  return iter;
747  }
748 
751  SEGMENT_ITERATOR IterateSegments( int aFirst, int aLast, bool aIterateHoles = false )
752  {
753  SEGMENT_ITERATOR iter;
754 
755  iter.m_poly = this;
756  iter.m_currentPolygon = aFirst;
757  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
758  iter.m_currentContour = 0;
759  iter.m_currentSegment = 0;
760  iter.m_iterateHoles = aIterateHoles;
761 
762  return iter;
763  }
764 
766  SEGMENT_ITERATOR IterateSegments( int aPolygonIdx )
767  {
768  return IterateSegments( aPolygonIdx, aPolygonIdx );
769  }
770 
772  SEGMENT_ITERATOR IterateSegments()
773  {
774  return IterateSegments( 0, OutlineCount() - 1 );
775  }
776 
778  SEGMENT_ITERATOR IterateSegmentsWithHoles()
779  {
780  return IterateSegments( 0, OutlineCount() - 1, true );
781  }
782 
784  SEGMENT_ITERATOR IterateSegmentsWithHoles( int aOutline )
785  {
786  return IterateSegments( aOutline, aOutline, true );
787  }
788 
797  {
798  PM_FAST = true,
800  };
801 
804  void BooleanAdd( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
805 
808  void BooleanSubtract( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
809 
812  void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
813 
816  void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
817  POLYGON_MODE aFastMode );
818 
821  void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
822  POLYGON_MODE aFastMode );
823 
826  void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
827  POLYGON_MODE aFastMode );
828 
830  void Inflate( int aFactor, int aCircleSegmentsCount );
831 
835  void Fracture( POLYGON_MODE aFastMode );
836 
839  void Unfracture( POLYGON_MODE aFastMode );
840 
842  bool HasHoles() const;
843 
845  bool HasTouchingHoles() const;
846 
847 
850  void Simplify( POLYGON_MODE aFastMode );
851 
859  int NormalizeAreaOutlines();
860 
862  const std::string Format() const override;
863 
865  bool Parse( std::stringstream& aStream ) override;
866 
868  void Move( const VECTOR2I& aVector ) override;
869 
876  void Rotate( double aAngle, const VECTOR2I& aCenter );
877 
879  bool IsSolid() const override
880  {
881  return true;
882  }
883 
884  const BOX2I BBox( int aClearance = 0 ) const override;
885 
893  bool PointOnEdge( const VECTOR2I& aP ) const;
894 
906  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
907 
920  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override;
921 
932  bool CollideVertex( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
933  int aClearance = 0 );
934 
945  bool CollideEdge( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
946  int aClearance = 0 );
947 
956  bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1, bool aIgnoreHoles = false ) const;
957 
959  bool IsEmpty() const
960  {
961  return m_polys.size() == 0;
962  }
963 
969  void RemoveVertex( int aGlobalIndex );
970 
976  void RemoveVertex( VERTEX_INDEX aRelativeIndices );
977 
979  void RemoveAllContours();
980 
989  void RemoveContour( int aContourIdx, int aPolygonIdx = -1 );
990 
996  int RemoveNullSegments();
997 
999  int TotalVertices() const;
1000 
1002  void DeletePolygon( int aIdx );
1003 
1011  POLYGON ChamferPolygon( unsigned int aDistance, int aIndex = 0 );
1012 
1021  POLYGON FilletPolygon( unsigned int aRadius, int aErrorMax, int aIndex = 0 );
1022 
1029  SHAPE_POLY_SET Chamfer( int aDistance );
1030 
1038  SHAPE_POLY_SET Fillet( int aRadius, int aErrorMax );
1039 
1048  int DistanceToPolygon( VECTOR2I aPoint, int aIndex );
1049 
1062  int DistanceToPolygon( SEG aSegment, int aIndex, int aSegmentWidth = 0 );
1063 
1071  int Distance( VECTOR2I aPoint );
1072 
1081  int Distance( const SEG& aSegment, int aSegmentWidth = 0 );
1082 
1089  bool IsVertexInHole( int aGlobalIdx );
1090 
1091  private:
1092 
1093  SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
1094  VECTOR2I& vertex( int aCornerId );
1095  const VECTOR2I& cvertex( int aCornerId ) const;
1096 
1097 
1098  void fractureSingle( POLYGON& paths );
1099  void unfractureSingle ( POLYGON& path );
1100  void importTree( ClipperLib::PolyTree* tree );
1101 
1113  void booleanOp( ClipperLib::ClipType aType,
1114  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1115 
1116  void booleanOp( ClipperLib::ClipType aType,
1117  const SHAPE_POLY_SET& aShape,
1118  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1119 
1120  bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
1121 
1134  bool containsSingle( const VECTOR2I& aP, int aSubpolyIndex, bool aIgnoreHoles = false ) const;
1135 
1142  {
1145  };
1146 
1147 
1148 
1163  POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
1164  int aIndex, int aErrorMax = -1 );
1165 
1167  bool hasTouchingHoles( const POLYGON& aPoly ) const;
1168 
1169  typedef std::vector<POLYGON> POLYSET;
1170 
1171  POLYSET m_polys;
1172 
1173  public:
1174 
1176 
1177  void CacheTriangulation();
1178  bool IsTriangulationUpToDate() const;
1179 
1180  MD5_HASH GetHash() const;
1181 
1182  private:
1183 
1184  MD5_HASH checksum() const;
1185 
1186  std::vector<std::unique_ptr<TRIANGULATED_POLYGON>> m_triangulatedPolys;
1187  bool m_triangulationValid = false;
1189 
1190 };
1191 
1192 #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 unfractureSingle(POLYGON &path)
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...
std::vector< POLYGON > POLYSET
bool IsLastPolygon() const
Function IsLastOutline.
MD5_HASH checksum() const
MD5_HASH GetHash() const
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
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
bool Parse(std::stringstream &aStream) override
int TotalVertices() const
Returns total number of vertices stored in the set.
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, bool aIgnoreHoles=false) const
Returns true if a given subpolygon contains the point aP.
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
bool IsTriangulationUpToDate() const
SHAPE_POLY_SET Fillet(int aRadius, int aErrorMax)
Function Fillet returns a filleted version of the polygon set.
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
std::vector< std::unique_ptr< TRIANGULATED_POLYGON > > m_triangulatedPolys
bool HasTouchingHoles() const
Returns true if the polygon set has any holes tha share a vertex.
#define abs(a)
Definition: auxiliary.h:84
VERTEX_INDEX GetIndex()
Function GetIndex.
struct SHAPE_POLY_SET::VERTEX_INDEX VERTEX_INDEX
Struct VERTEX_INDEX.
POLYGON FilletPolygon(unsigned int aRadius, int aErrorMax, int aIndex=0)
Function Fillet returns a filleted version of the aIndex-th polygon.
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
POLYGON chamferFilletPolygon(CORNER_MODE aMode, unsigned int aDistance, int aIndex, int aErrorMax=-1)
Function chamferFilletPolygon Returns the camfered or filleted version of the aIndex-th polygon in th...
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...
const POLYGON & Polygon(int aIndex) const
SHAPE_POLY_SET & operator=(const SHAPE_POLY_SET &)
void Inflate(int aFactor, int aCircleSegmentsCount)
Performs outline inflation/deflation, using round corners.
void Move(const VECTOR2I &aVector) override
ITERATOR IterateWithHoles(int aOutline)
Function IterateWithHoles.
Class SHAPE_POLY_SET.
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...
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
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)
bool hasTouchingHoles(const POLYGON &aPoly) const
Returns true if the polygon set has any holes that touch share a vertex.
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:58
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:36
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.
void AddVertex(const VECTOR2I &aP)
void AddTriangle(int a, int b, int c)
SHAPE_POLY_SET UnitSet(int aPolygonIndex)
TRI(int _a=0, int _b=0, int _c=0)
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...
unsigned int TriangulatedPolyCount() const
Returns the number of triangulated polygons
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.
void GetTriangle(int index, VECTOR2I &a, VECTOR2I &b, VECTOR2I &c) const
POLYGON_MODE
operations on polygons use a aFastMode param if aFastMode is PM_FAST (true) the result can be a weak ...
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
bool containsSingle(const VECTOR2I &aP, int aSubpolyIndex, bool aIgnoreHoles=false) const
containsSingle function Checks whether the point aP is inside the aSubpolyIndex-th polygon of the pol...
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)
void Rotate(double aAngle, const VECTOR2I &aCenter)
Function Rotate rotates all vertices by a given angle.
const BOX2I BBox(int aClearance=0) const override
Function BBox()
VERTEX_INDEX GetIndex()
Function GetIndex.
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)
void Unfracture(POLYGON_MODE aFastMode)
Converts a single outline slitted ("fractured") polygon into a set ouf outlines with holes...