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 "clipper.hpp"
36 
37 #include <md5_hash.h>
38 
39 
56 class SHAPE_POLY_SET : public SHAPE
57 {
58  public:
62  typedef std::vector<SHAPE_LINE_CHAIN> POLYGON;
63 
65  {
66  public:
67  struct TRI
68  {
69  TRI( int _a = 0, int _b = 0, int _c = 0 ) : a( _a ), b( _b ), c( _c )
70  {
71  }
72 
73  int a, b, c;
74  };
75 
76  void Clear()
77  {
78  m_vertices.clear();
79  m_triangles.clear();
80  }
81 
82  void GetTriangle( int index, VECTOR2I& a, VECTOR2I& b, VECTOR2I& c ) const
83  {
84  auto tri = m_triangles[ index ];
85  a = m_vertices[ tri.a ];
86  b = m_vertices[ tri.b ];
87  c = m_vertices[ tri.c ];
88  }
89 
90  void AddTriangle( const TRI& aTri )
91  {
92  m_triangles.push_back( aTri );
93  }
94 
95  void AddTriangle( int a, int b, int c )
96  {
97  m_triangles.emplace_back( a, b, c );
98  }
99 
100  void AddVertex( const VECTOR2I& aP )
101  {
102  m_vertices.push_back( aP );
103  }
104 
105  size_t GetTriangleCount() const
106  {
107  return m_triangles.size();
108  }
109 
110  size_t GetVertexCount() const
111  {
112  return m_vertices.size();
113  }
114 
115  private:
116 
117  std::deque<TRI> m_triangles;
118  std::deque<VECTOR2I> m_vertices;
119  };
120 
128  typedef struct VERTEX_INDEX
129  {
130  int m_polygon;
131  int m_contour;
132  int m_vertex;
134  VERTEX_INDEX() : m_polygon(-1), m_contour(-1), m_vertex(-1)
135  {
136  }
137  } VERTEX_INDEX;
138 
144  template <class T>
146  {
147  public:
148 
154  bool IsEndContour() const
155  {
156  return m_currentVertex + 1 == m_poly->CPolygon( m_currentPolygon )[m_currentContour].PointCount();
157  }
158 
163  bool IsLastPolygon() const
164  {
165  return m_currentPolygon == m_lastPolygon;
166  }
167 
168  operator bool() const
169  {
170  return m_currentPolygon <= m_lastPolygon;
171  }
172 
178  void Advance()
179  {
180  // Advance vertex index
181  m_currentVertex ++;
182 
183  // Check whether the user wants to iterate through the vertices of the holes
184  // and behave accordingly
185  if( m_iterateHoles )
186  {
187  // If the last vertex of the contour was reached, advance the contour index
188  if( m_currentVertex >= m_poly->CPolygon( m_currentPolygon )[m_currentContour].PointCount() )
189  {
190  m_currentVertex = 0;
191  m_currentContour++;
192 
193  // If the last contour of the current polygon was reached, advance the
194  // outline index
195  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
196 
197  if( m_currentContour >= totalContours )
198  {
199  m_currentContour = 0;
200  m_currentPolygon++;
201  }
202  }
203  }
204  else
205  {
206  // If the last vertex of the outline was reached, advance to the following polygon
207  if( m_currentVertex >= m_poly->CPolygon( m_currentPolygon )[0].PointCount() )
208  {
209  m_currentVertex = 0;
210  m_currentPolygon++;
211  }
212  }
213  }
214 
215  void operator++( int dummy )
216  {
217  Advance();
218  }
219 
220  void operator++()
221  {
222  Advance();
223  }
224 
225  T& Get()
226  {
227  return m_poly->Polygon( m_currentPolygon )[m_currentContour].Point( m_currentVertex );
228  }
229 
231  {
232  return Get();
233  }
234 
236  {
237  return &Get();
238  }
239 
245  {
246  VERTEX_INDEX index;
247 
248  index.m_polygon = m_currentPolygon;
249  index.m_contour = m_currentContour;
250  index.m_vertex = m_currentVertex;
251 
252  return index;
253  }
254 
255 
256  private:
257  friend class SHAPE_POLY_SET;
258 
265  };
266 
272  template <class T>
274  {
275  public:
280  bool IsLastPolygon() const
281  {
282  return m_currentPolygon == m_lastPolygon;
283  }
284 
285  operator bool() const
286  {
287  return m_currentPolygon <= m_lastPolygon;
288  }
289 
295  void Advance()
296  {
297  // Advance vertex index
298  m_currentSegment++;
299  int last;
300 
301  // Check whether the user wants to iterate through the vertices of the holes
302  // and behave accordingly
303  if( m_iterateHoles )
304  {
305  last = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
306 
307  // If the last vertex of the contour was reached, advance the contour index
308  if( m_currentSegment >= last )
309  {
310  m_currentSegment = 0;
311  m_currentContour++;
312 
313  // If the last contour of the current polygon was reached, advance the
314  // outline index
315  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
316 
317  if( m_currentContour >= totalContours )
318  {
319  m_currentContour = 0;
320  m_currentPolygon++;
321  }
322  }
323  }
324  else
325  {
326  last = m_poly->CPolygon( m_currentPolygon )[0].SegmentCount();
327  // If the last vertex of the outline was reached, advance to the following
328  // polygon
329  if( m_currentSegment >= last )
330  {
331  m_currentSegment = 0;
332  m_currentPolygon++;
333  }
334  }
335  }
336 
337  void operator++( int dummy )
338  {
339  Advance();
340  }
341 
342  void operator++()
343  {
344  Advance();
345  }
346 
347  T Get()
348  {
349  return m_poly->Polygon( m_currentPolygon )[m_currentContour].Segment( m_currentSegment );
350  }
351 
353  {
354  return Get();
355  }
356 
362  {
363  VERTEX_INDEX index;
364 
365  index.m_polygon = m_currentPolygon;
366  index.m_contour = m_currentContour;
367  index.m_vertex = m_currentSegment;
368 
369  return index;
370  }
371 
380  {
381  // Check that both iterators point to the same contour of the same polygon of the
382  // same polygon set
383  if( m_poly == aOther.m_poly && m_currentPolygon == aOther.m_currentPolygon &&
384  m_currentContour == aOther.m_currentContour )
385  {
386  // Compute the total number of segments
387  int numSeg;
388  numSeg = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
389 
390  // Compute the difference of the segment indices. If it is exactly one, they
391  // are adjacent. The only missing case where they also are adjacent is when
392  // the segments are the first and last one, in which case the difference
393  // always equals the total number of segments minus one.
394  int indexDiff = abs( m_currentSegment - aOther.m_currentSegment );
395 
396  return ( indexDiff == 1 ) || ( indexDiff == (numSeg - 1) );
397  }
398 
399  return false;
400  }
401 
402  private:
403  friend class SHAPE_POLY_SET;
404 
411  };
412 
413  // Iterator and const iterator types to visit polygon's points.
416 
417  // Iterator and const iterator types to visit polygon's edges.
420 
421  SHAPE_POLY_SET();
422 
429  SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther, bool aDeepCopy = false );
430 
431  ~SHAPE_POLY_SET();
432 
445  bool GetRelativeIndices( int aGlobalIdx, VERTEX_INDEX* aRelativeIndices) const;
446 
456  bool GetGlobalIndex( VERTEX_INDEX aRelativeIndices, int& aGlobalIdx );
457 
459  SHAPE* Clone() const override;
460 
462  int NewOutline();
463 
465  int NewHole( int aOutline = -1 );
466 
468  int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
469 
471  int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
472 
474 
486  int Append( int x, int y, int aOutline = -1, int aHole = -1,
487  bool aAllowDuplication = false );
488 
490  void Append( const SHAPE_POLY_SET& aSet );
491 
493  void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
494 
502  void InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex );
503 
505  VECTOR2I& Vertex( int aIndex, int aOutline, int aHole );
506 
508  const VECTOR2I& CVertex( int aIndex, int aOutline, int aHole ) const;
509 
511  VECTOR2I& Vertex( int aGlobalIndex );
512 
514  const VECTOR2I& CVertex( int aGlobalIndex ) const;
515 
517  VECTOR2I& Vertex( VERTEX_INDEX aIndex );
518 
520  const VECTOR2I& CVertex( VERTEX_INDEX aIndex ) const;
521 
533  bool GetNeighbourIndexes( int aGlobalIndex, int* aPrevious, int* aNext );
534 
535 
543  bool IsPolygonSelfIntersecting( int aPolygonIndex );
544 
550  bool IsSelfIntersecting();
551 
553  unsigned int TriangulatedPolyCount() const { return m_triangulatedPolys.size(); }
554 
556  int OutlineCount() const { return m_polys.size(); }
557 
559  int VertexCount( int aOutline = -1, int aHole = -1 ) const;
560 
562  int HoleCount( int aOutline ) const
563  {
564  if( ( aOutline < 0 ) || (aOutline >= (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
565  return 0;
566 
567  // the first polygon in m_polys[aOutline] is the main contour,
568  // only others are holes:
569  return m_polys[aOutline].size() - 1;
570  }
571 
573  SHAPE_LINE_CHAIN& Outline( int aIndex )
574  {
575  return m_polys[aIndex][0];
576  }
577 
587  SHAPE_POLY_SET Subset( int aFirstPolygon, int aLastPolygon );
588 
589  SHAPE_POLY_SET UnitSet( int aPolygonIndex )
590  {
591  return Subset( aPolygonIndex, aPolygonIndex + 1 );
592  }
593 
595  SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
596  {
597  return m_polys[aOutline][aHole + 1];
598  }
599 
601  POLYGON& Polygon( int aIndex )
602  {
603  return m_polys[aIndex];
604  }
605 
606  const POLYGON& Polygon( int aIndex ) const
607  {
608  return m_polys[aIndex];
609  }
610 
611  const TRIANGULATED_POLYGON* TriangulatedPolygon( int aIndex ) const
612  {
613  return m_triangulatedPolys[aIndex].get();
614  }
615 
616  const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
617  {
618  return m_polys[aIndex][0];
619  }
620 
621  const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
622  {
623  return m_polys[aOutline][aHole + 1];
624  }
625 
626  const POLYGON& CPolygon( int aIndex ) const
627  {
628  return m_polys[aIndex];
629  }
630 
641  ITERATOR Iterate( int aFirst, int aLast, bool aIterateHoles = false )
642  {
643  ITERATOR iter;
644 
645  iter.m_poly = this;
646  iter.m_currentPolygon = aFirst;
647  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
648  iter.m_currentContour = 0;
649  iter.m_currentVertex = 0;
650  iter.m_iterateHoles = aIterateHoles;
651 
652  return iter;
653  }
654 
661  ITERATOR Iterate( int aOutline )
662  {
663  return Iterate( aOutline, aOutline );
664  }
665 
672  ITERATOR IterateWithHoles( int aOutline )
673  {
674  return Iterate( aOutline, aOutline, true );
675  }
676 
682  ITERATOR Iterate()
683  {
684  return Iterate( 0, OutlineCount() - 1 );
685  }
686 
692  ITERATOR IterateWithHoles()
693  {
694  return Iterate( 0, OutlineCount() - 1, true );
695  }
696 
697 
698  CONST_ITERATOR CIterate( int aFirst, int aLast, bool aIterateHoles = false ) const
699  {
700  CONST_ITERATOR iter;
701 
702  iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
703  iter.m_currentPolygon = aFirst;
704  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
705  iter.m_currentContour = 0;
706  iter.m_currentVertex = 0;
707  iter.m_iterateHoles = aIterateHoles;
708 
709  return iter;
710  }
711 
712  CONST_ITERATOR CIterate( int aOutline ) const
713  {
714  return CIterate( aOutline, aOutline );
715  }
716 
717  CONST_ITERATOR CIterateWithHoles( int aOutline ) const
718  {
719  return CIterate( aOutline, aOutline, true );
720  }
721 
722  CONST_ITERATOR CIterate() const
723  {
724  return CIterate( 0, OutlineCount() - 1 );
725  }
726 
727  CONST_ITERATOR CIterateWithHoles() const
728  {
729  return CIterate( 0, OutlineCount() - 1, true );
730  }
731 
732  ITERATOR IterateFromVertexWithHoles( int aGlobalIdx )
733  {
734  // Build iterator
735  ITERATOR iter = IterateWithHoles();
736 
737  // Get the relative indices of the globally indexed vertex
738  VERTEX_INDEX indices;
739 
740  if( !GetRelativeIndices( aGlobalIdx, &indices ) )
741  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
742 
743  // Adjust where the iterator is pointing
744  iter.m_currentPolygon = indices.m_polygon;
745  iter.m_currentContour = indices.m_contour;
746  iter.m_currentVertex = indices.m_vertex;
747 
748  return iter;
749  }
750 
753  SEGMENT_ITERATOR IterateSegments( int aFirst, int aLast, bool aIterateHoles = false )
754  {
755  SEGMENT_ITERATOR iter;
756 
757  iter.m_poly = this;
758  iter.m_currentPolygon = aFirst;
759  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
760  iter.m_currentContour = 0;
761  iter.m_currentSegment = 0;
762  iter.m_iterateHoles = aIterateHoles;
763 
764  return iter;
765  }
766 
768  SEGMENT_ITERATOR IterateSegments( int aPolygonIdx )
769  {
770  return IterateSegments( aPolygonIdx, aPolygonIdx );
771  }
772 
774  SEGMENT_ITERATOR IterateSegments()
775  {
776  return IterateSegments( 0, OutlineCount() - 1 );
777  }
778 
780  SEGMENT_ITERATOR IterateSegmentsWithHoles()
781  {
782  return IterateSegments( 0, OutlineCount() - 1, true );
783  }
784 
786  SEGMENT_ITERATOR IterateSegmentsWithHoles( int aOutline )
787  {
788  return IterateSegments( aOutline, aOutline, true );
789  }
790 
799  {
800  PM_FAST = true,
802  };
803 
806  void BooleanAdd( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
807 
810  void BooleanSubtract( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
811 
814  void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
815 
818  void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
819  POLYGON_MODE aFastMode );
820 
823  void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
824  POLYGON_MODE aFastMode );
825 
828  void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
829  POLYGON_MODE aFastMode );
830 
832  void Inflate( int aFactor, int aCircleSegmentsCount );
833 
837  void Fracture( POLYGON_MODE aFastMode );
838 
841  void Unfracture( POLYGON_MODE aFastMode );
842 
844  bool HasHoles() const;
845 
847  bool HasTouchingHoles() const;
848 
849 
852  void Simplify( POLYGON_MODE aFastMode );
853 
861  int NormalizeAreaOutlines();
862 
864  const std::string Format() const override;
865 
867  bool Parse( std::stringstream& aStream ) override;
868 
870  void Move( const VECTOR2I& aVector ) override;
871 
878  void Rotate( double aAngle, const VECTOR2I& aCenter );
879 
881  bool IsSolid() const override
882  {
883  return true;
884  }
885 
886  const BOX2I BBox( int aClearance = 0 ) const override;
887 
895  bool PointOnEdge( const VECTOR2I& aP ) const;
896 
908  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
909 
922  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override;
923 
934  bool CollideVertex( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
935  int aClearance = 0 );
936 
947  bool CollideEdge( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
948  int aClearance = 0 );
949 
958  bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1, bool aIgnoreHoles = false ) const;
959 
961  bool IsEmpty() const
962  {
963  return m_polys.size() == 0;
964  }
965 
971  void RemoveVertex( int aGlobalIndex );
972 
978  void RemoveVertex( VERTEX_INDEX aRelativeIndices );
979 
981  void RemoveAllContours();
982 
991  void RemoveContour( int aContourIdx, int aPolygonIdx = -1 );
992 
998  int RemoveNullSegments();
999 
1001  int TotalVertices() const;
1002 
1004  void DeletePolygon( int aIdx );
1005 
1013  POLYGON ChamferPolygon( unsigned int aDistance, int aIndex = 0 );
1014 
1023  POLYGON FilletPolygon( unsigned int aRadius, int aErrorMax, int aIndex = 0 );
1024 
1031  SHAPE_POLY_SET Chamfer( int aDistance );
1032 
1040  SHAPE_POLY_SET Fillet( int aRadius, int aErrorMax );
1041 
1050  int DistanceToPolygon( VECTOR2I aPoint, int aIndex );
1051 
1064  int DistanceToPolygon( SEG aSegment, int aIndex, int aSegmentWidth = 0 );
1065 
1073  int Distance( VECTOR2I aPoint );
1074 
1083  int Distance( const SEG& aSegment, int aSegmentWidth = 0 );
1084 
1091  bool IsVertexInHole( int aGlobalIdx );
1092 
1093  private:
1094 
1095  SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
1096  VECTOR2I& vertex( int aCornerId );
1097  const VECTOR2I& cvertex( int aCornerId ) const;
1098 
1099 
1100  void fractureSingle( POLYGON& paths );
1101  void unfractureSingle ( POLYGON& path );
1102  void importTree( ClipperLib::PolyTree* tree );
1103 
1115  void booleanOp( ClipperLib::ClipType aType,
1116  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1117 
1118  void booleanOp( ClipperLib::ClipType aType,
1119  const SHAPE_POLY_SET& aShape,
1120  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1121 
1122  bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
1123 
1136  bool containsSingle( const VECTOR2I& aP, int aSubpolyIndex, bool aIgnoreHoles = false ) const;
1137 
1144  {
1147  };
1148 
1149 
1150 
1165  POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
1166  int aIndex, int aErrorMax = -1 );
1167 
1169  bool hasTouchingHoles( const POLYGON& aPoly ) const;
1170 
1171  typedef std::vector<POLYGON> POLYSET;
1172 
1173  POLYSET m_polys;
1174 
1175  public:
1176 
1178 
1179  void CacheTriangulation();
1180  bool IsTriangulationUpToDate() const;
1181 
1182  MD5_HASH GetHash() const;
1183 
1184  private:
1185 
1186  MD5_HASH checksum() const;
1187 
1188  std::vector<std::unique_ptr<TRIANGULATED_POLYGON>> m_triangulatedPolys;
1189  bool m_triangulationValid = false;
1191 
1192 };
1193 
1194 #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
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...