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;
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  {
164  }
165 
166  operator bool() const
167  {
168  return ( ( m_currentPolygon < m_lastPolygon ) || ( IsLastPolygon() &&
169  ( m_currentContour < static_cast<int>( m_poly->CPolygon( m_currentPolygon ).size() ) ||
171  )
172  ) );
173  }
174 
180  void Advance()
181  {
182  // Advance vertex index
183  m_currentVertex ++;
184 
185  // Check whether the user wants to iterate through the vertices of the holes
186  // and behave accordingly
187  if( m_iterateHoles )
188  {
189  // If the last vertex of the contour was reached, advance the contour index
191  {
192  m_currentVertex = 0;
194 
195  // If the last contour of the current polygon was reached, advance the
196  // outline index
197  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
198 
199  if( m_currentContour >= totalContours )
200  {
201  m_currentContour = 0;
203  }
204  }
205  }
206  else
207  {
208  // If the last vertex of the outline was reached, advance to the following polygon
209  if( m_currentVertex >= m_poly->CPolygon( m_currentPolygon )[0].PointCount() )
210  {
211  m_currentVertex = 0;
213  }
214  }
215  }
216 
217  void operator++( int dummy )
218  {
219  Advance();
220  }
221 
222  void operator++()
223  {
224  Advance();
225  }
226 
227  T& Get()
228  {
230  }
231 
233  {
234  return Get();
235  }
236 
238  {
239  return &Get();
240  }
241 
247  {
248  VERTEX_INDEX index;
249 
250  index.m_polygon = m_currentPolygon;
251  index.m_contour = m_currentContour;
252  index.m_vertex = m_currentVertex;
253 
254  return index;
255  }
256 
257 
258  private:
259  friend class SHAPE_POLY_SET;
260 
267  };
268 
274  template <class T>
276  {
277  public:
282  bool IsLastPolygon() const
283  {
285  }
286 
287  operator bool() const
288  {
290  }
291 
297  void Advance()
298  {
299  // Advance vertex index
301  int last;
302 
303  // Check whether the user wants to iterate through the vertices of the holes
304  // and behave accordingly
305  if( m_iterateHoles )
306  {
307  last = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
308 
309  // If the last vertex of the contour was reached, advance the contour index
310  if( m_currentSegment >= last )
311  {
312  m_currentSegment = 0;
314 
315  // If the last contour of the current polygon was reached, advance the
316  // outline index
317  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
318 
319  if( m_currentContour >= totalContours )
320  {
321  m_currentContour = 0;
323  }
324  }
325  }
326  else
327  {
328  last = m_poly->CPolygon( m_currentPolygon )[0].SegmentCount();
329  // If the last vertex of the outline was reached, advance to the following
330  // polygon
331  if( m_currentSegment >= last )
332  {
333  m_currentSegment = 0;
335  }
336  }
337  }
338 
339  void operator++( int dummy )
340  {
341  Advance();
342  }
343 
344  void operator++()
345  {
346  Advance();
347  }
348 
349  T Get()
350  {
352  }
353 
355  {
356  return Get();
357  }
358 
364  {
365  VERTEX_INDEX index;
366 
367  index.m_polygon = m_currentPolygon;
368  index.m_contour = m_currentContour;
369  index.m_vertex = m_currentSegment;
370 
371  return index;
372  }
373 
382  {
383  // Check that both iterators point to the same contour of the same polygon of the
384  // same polygon set
385  if( m_poly == aOther.m_poly && m_currentPolygon == aOther.m_currentPolygon &&
387  {
388  // Compute the total number of segments
389  int numSeg;
390  numSeg = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
391 
392  // Compute the difference of the segment indices. If it is exactly one, they
393  // are adjacent. The only missing case where they also are adjacent is when
394  // the segments are the first and last one, in which case the difference
395  // always equals the total number of segments minus one.
396  int indexDiff = abs( m_currentSegment - aOther.m_currentSegment );
397 
398  return ( indexDiff == 1 ) || ( indexDiff == (numSeg - 1) );
399  }
400 
401  return false;
402  }
403 
404  private:
405  friend class SHAPE_POLY_SET;
406 
413  };
414 
415  // Iterator and const iterator types to visit polygon's points.
418 
419  // Iterator and const iterator types to visit polygon's edges.
422 
423  SHAPE_POLY_SET();
424 
431  SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther, bool aDeepCopy = false );
432 
433  ~SHAPE_POLY_SET();
434 
447  bool GetRelativeIndices( int aGlobalIdx, VERTEX_INDEX* aRelativeIndices) const;
448 
458  bool GetGlobalIndex( VERTEX_INDEX aRelativeIndices, int& aGlobalIdx );
459 
461  SHAPE* Clone() const override;
462 
464  int NewOutline();
465 
467  int NewHole( int aOutline = -1 );
468 
470  int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
471 
473  int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
474 
476 
488  int Append( int x, int y, int aOutline = -1, int aHole = -1,
489  bool aAllowDuplication = false );
490 
492  void Append( const SHAPE_POLY_SET& aSet );
493 
495  void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
496 
504  void InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex );
505 
507  VECTOR2I& Vertex( int aIndex, int aOutline, int aHole );
508 
510  const VECTOR2I& CVertex( int aIndex, int aOutline, int aHole ) const;
511 
513  VECTOR2I& Vertex( int aGlobalIndex );
514 
516  const VECTOR2I& CVertex( int aGlobalIndex ) const;
517 
519  VECTOR2I& Vertex( VERTEX_INDEX aIndex );
520 
522  const VECTOR2I& CVertex( VERTEX_INDEX aIndex ) const;
523 
535  bool GetNeighbourIndexes( int aGlobalIndex, int* aPrevious, int* aNext );
536 
537 
545  bool IsPolygonSelfIntersecting( int aPolygonIndex );
546 
552  bool IsSelfIntersecting();
553 
555  unsigned int TriangulatedPolyCount() const { return m_triangulatedPolys.size(); }
556 
558  int OutlineCount() const { return m_polys.size(); }
559 
561  int VertexCount( int aOutline = -1, int aHole = -1 ) const;
562 
564  int HoleCount( int aOutline ) const
565  {
566  if( ( aOutline < 0 ) || (aOutline >= (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
567  return 0;
568 
569  // the first polygon in m_polys[aOutline] is the main contour,
570  // only others are holes:
571  return m_polys[aOutline].size() - 1;
572  }
573 
575  SHAPE_LINE_CHAIN& Outline( int aIndex )
576  {
577  return m_polys[aIndex][0];
578  }
579 
589  SHAPE_POLY_SET Subset( int aFirstPolygon, int aLastPolygon );
590 
591  SHAPE_POLY_SET UnitSet( int aPolygonIndex )
592  {
593  return Subset( aPolygonIndex, aPolygonIndex + 1 );
594  }
595 
597  SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
598  {
599  return m_polys[aOutline][aHole + 1];
600  }
601 
603  POLYGON& Polygon( int aIndex )
604  {
605  return m_polys[aIndex];
606  }
607 
608  const POLYGON& Polygon( int aIndex ) const
609  {
610  return m_polys[aIndex];
611  }
612 
613  const TRIANGULATED_POLYGON* TriangulatedPolygon( int aIndex ) const
614  {
615  return m_triangulatedPolys[aIndex].get();
616  }
617 
618  const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
619  {
620  return m_polys[aIndex][0];
621  }
622 
623  const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
624  {
625  return m_polys[aOutline][aHole + 1];
626  }
627 
628  const POLYGON& CPolygon( int aIndex ) const
629  {
630  return m_polys[aIndex];
631  }
632 
643  ITERATOR Iterate( int aFirst, int aLast, bool aIterateHoles = false )
644  {
645  ITERATOR iter;
646 
647  iter.m_poly = this;
648  iter.m_currentPolygon = aFirst;
649  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
650  iter.m_currentContour = 0;
651  iter.m_currentVertex = 0;
652  iter.m_iterateHoles = aIterateHoles;
653 
654  return iter;
655  }
656 
663  ITERATOR Iterate( int aOutline )
664  {
665  return Iterate( aOutline, aOutline );
666  }
667 
674  ITERATOR IterateWithHoles( int aOutline )
675  {
676  return Iterate( aOutline, aOutline, true );
677  }
678 
685  {
686  return Iterate( 0, OutlineCount() - 1 );
687  }
688 
695  {
696  return Iterate( 0, OutlineCount() - 1, true );
697  }
698 
699 
700  CONST_ITERATOR CIterate( int aFirst, int aLast, bool aIterateHoles = false ) const
701  {
702  CONST_ITERATOR iter;
703 
704  iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
705  iter.m_currentPolygon = aFirst;
706  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
707  iter.m_currentContour = 0;
708  iter.m_currentVertex = 0;
709  iter.m_iterateHoles = aIterateHoles;
710 
711  return iter;
712  }
713 
714  CONST_ITERATOR CIterate( int aOutline ) const
715  {
716  return CIterate( aOutline, aOutline );
717  }
718 
719  CONST_ITERATOR CIterateWithHoles( int aOutline ) const
720  {
721  return CIterate( aOutline, aOutline, true );
722  }
723 
725  {
726  return CIterate( 0, OutlineCount() - 1 );
727  }
728 
730  {
731  return CIterate( 0, OutlineCount() - 1, true );
732  }
733 
735  {
736  // Build iterator
737  ITERATOR iter = IterateWithHoles();
738 
739  // Get the relative indices of the globally indexed vertex
740  VERTEX_INDEX indices;
741 
742  if( !GetRelativeIndices( aGlobalIdx, &indices ) )
743  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
744 
745  // Adjust where the iterator is pointing
746  iter.m_currentPolygon = indices.m_polygon;
747  iter.m_currentContour = indices.m_contour;
748  iter.m_currentVertex = indices.m_vertex;
749 
750  return iter;
751  }
752 
755  SEGMENT_ITERATOR IterateSegments( int aFirst, int aLast, bool aIterateHoles = false )
756  {
757  SEGMENT_ITERATOR iter;
758 
759  iter.m_poly = this;
760  iter.m_currentPolygon = aFirst;
761  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
762  iter.m_currentContour = 0;
763  iter.m_currentSegment = 0;
764  iter.m_iterateHoles = aIterateHoles;
765 
766  return iter;
767  }
768 
771  {
772  return IterateSegments( aPolygonIdx, aPolygonIdx );
773  }
774 
777  {
778  return IterateSegments( 0, OutlineCount() - 1 );
779  }
780 
783  {
784  return IterateSegments( 0, OutlineCount() - 1, true );
785  }
786 
789  {
790  return IterateSegments( aOutline, aOutline, true );
791  }
792 
801  {
802  PM_FAST = true,
804  };
805 
808  void BooleanAdd( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
809 
812  void BooleanSubtract( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
813 
816  void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
817 
820  void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
821  POLYGON_MODE aFastMode );
822 
825  void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
826  POLYGON_MODE aFastMode );
827 
830  void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
831  POLYGON_MODE aFastMode );
832 
834  void Inflate( int aFactor, int aCircleSegmentsCount );
835 
839  void Fracture( POLYGON_MODE aFastMode );
840 
843  void Unfracture( POLYGON_MODE aFastMode );
844 
846  bool HasHoles() const;
847 
849  bool HasTouchingHoles() const;
850 
851 
854  void Simplify( POLYGON_MODE aFastMode );
855 
863  int NormalizeAreaOutlines();
864 
866  const std::string Format() const override;
867 
869  bool Parse( std::stringstream& aStream ) override;
870 
872  void Move( const VECTOR2I& aVector ) override;
873 
880  void Rotate( double aAngle, const VECTOR2I& aCenter );
881 
883  bool IsSolid() const override
884  {
885  return true;
886  }
887 
888  const BOX2I BBox( int aClearance = 0 ) const override;
889 
897  bool PointOnEdge( const VECTOR2I& aP ) const;
898 
910  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
911 
924  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override;
925 
936  bool CollideVertex( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
937  int aClearance = 0 );
938 
949  bool CollideEdge( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
950  int aClearance = 0 );
951 
960  bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1, bool aIgnoreHoles = false ) const;
961 
963  bool IsEmpty() const
964  {
965  return m_polys.size() == 0;
966  }
967 
973  void RemoveVertex( int aGlobalIndex );
974 
980  void RemoveVertex( VERTEX_INDEX aRelativeIndices );
981 
983  void RemoveAllContours();
984 
993  void RemoveContour( int aContourIdx, int aPolygonIdx = -1 );
994 
1000  int RemoveNullSegments();
1001 
1003  int TotalVertices() const;
1004 
1006  void DeletePolygon( int aIdx );
1007 
1015  POLYGON ChamferPolygon( unsigned int aDistance, int aIndex = 0 );
1016 
1025  POLYGON FilletPolygon( unsigned int aRadius, int aErrorMax, int aIndex = 0 );
1026 
1033  SHAPE_POLY_SET Chamfer( int aDistance );
1034 
1042  SHAPE_POLY_SET Fillet( int aRadius, int aErrorMax );
1043 
1052  int DistanceToPolygon( VECTOR2I aPoint, int aIndex );
1053 
1066  int DistanceToPolygon( SEG aSegment, int aIndex, int aSegmentWidth = 0 );
1067 
1075  int Distance( VECTOR2I aPoint );
1076 
1085  int Distance( const SEG& aSegment, int aSegmentWidth = 0 );
1086 
1093  bool IsVertexInHole( int aGlobalIdx );
1094 
1095  private:
1096 
1097  SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
1098  VECTOR2I& vertex( int aCornerId );
1099  const VECTOR2I& cvertex( int aCornerId ) const;
1100 
1101 
1102  void fractureSingle( POLYGON& paths );
1103  void unfractureSingle ( POLYGON& path );
1104  void importTree( ClipperLib::PolyTree* tree );
1105 
1117  void booleanOp( ClipperLib::ClipType aType,
1118  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1119 
1120  void booleanOp( ClipperLib::ClipType aType,
1121  const SHAPE_POLY_SET& aShape,
1122  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1123 
1124  bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
1125 
1138  bool containsSingle( const VECTOR2I& aP, int aSubpolyIndex, bool aIgnoreHoles = false ) const;
1139 
1146  {
1149  };
1150 
1151 
1152 
1167  POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
1168  int aIndex, int aErrorMax = -1 );
1169 
1171  bool hasTouchingHoles( const POLYGON& aPoly ) const;
1172 
1173  typedef std::vector<POLYGON> POLYSET;
1174 
1176 
1177  public:
1178 
1180 
1181  void CacheTriangulation();
1182  bool IsTriangulationUpToDate() const;
1183 
1184  MD5_HASH GetHash() const;
1185 
1186  private:
1187 
1188  MD5_HASH checksum() const;
1189 
1190  std::vector<std::unique_ptr<TRIANGULATED_POLYGON>> m_triangulatedPolys;
1191  bool m_triangulationValid = false;
1193 
1194 };
1195 
1196 #endif
int TotalVertices() const
Returns total number of vertices stored in the set.
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,...
int NewHole(int aOutline=-1)
Creates a new hole in a given outline
bool Contains(const VECTOR2I &aP, int aSubpolyIndex=-1, bool aIgnoreHoles=false) const
Returns true if a given subpolygon contains the point aP.
ITERATOR IterateFromVertexWithHoles(int aGlobalIdx)
POLYGON ChamferPolygon(unsigned int aDistance, int aIndex=0)
Function Chamfer returns a chamfered version of the aIndex-th polygon.
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...
const POLYGON & CPolygon(int aIndex) const
int OutlineCount() const
Returns the number of outlines in the set
bool IsEndContour() const
Function IsEndContour.
void fractureSingle(POLYGON &paths)
bool pointInPolygon(const VECTOR2I &aP, const SHAPE_LINE_CHAIN &aPath) const
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.
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...
void GetTriangle(int index, VECTOR2I &a, VECTOR2I &b, VECTOR2I &c) const
std::vector< POLYGON > POLYSET
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Returns the index-th vertex in a given hole outline within a given outline
SEGMENT_ITERATOR_TEMPLATE< const SEG > CONST_SEGMENT_ITERATOR
bool IsEmpty() const
Returns true if the set is empty (no polygons at all)
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...
int VertexCount(int aOutline=-1, int aHole=-1) const
Returns the number of vertices in a given outline/hole
bool IsSolid() const override
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
bool Parse(std::stringstream &aStream) override
bool HasHoles() const
Returns true if the polygon set has any holes.
CONST_ITERATOR CIterateWithHoles(int aOutline) const
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
MD5_HASH checksum() const
Class SEGMENT_ITERATOR_TEMPLATE.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) 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...
std::vector< std::unique_ptr< TRIANGULATED_POLYGON > > m_triangulatedPolys
#define abs(a)
Definition: auxiliary.h:84
bool PointOnEdge(const VECTOR2I &aP) const
Function PointOnEdge()
VERTEX_INDEX GetIndex()
Function GetIndex.
bool IsTriangulationUpToDate() const
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 hasTouchingHoles(const POLYGON &aPoly) const
Returns true if the polygon set has any holes that touch share a vertex.
bool IsLastPolygon() const
Function IsLastOutline.
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...
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...
SHAPE_POLY_SET & operator=(const SHAPE_POLY_SET &)
void Inflate(int aFactor, int aCircleSegmentsCount)
Performs outline inflation/deflation, using round corners.
MD5_HASH GetHash() const
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 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...
SEGMENT_ITERATOR IterateSegmentsWithHoles(int aOutline)
Returns an iterator object, for the aOutline-th outline in the set (with holes)
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
bool GetRelativeIndices(int aGlobalIdx, VERTEX_INDEX *aRelativeIndices) const
Function GetRelativeIndices.
int NewOutline()
Creates a new empty polygon in the set and returns its index
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
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
const POLYGON & Polygon(int aIndex) 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...
bool HasTouchingHoles() const
Returns true if the polygon set has any holes tha share a vertex.
ITERATOR IterateWithHoles()
Function IterateWithHoles.
Class SHAPE_LINE_CHAIN.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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...
Class ITERATOR_TEMPLATE.
unsigned int TriangulatedPolyCount() const
Returns the number of triangulated polygons
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
CONST_ITERATOR CIterate() const
ITERATOR_TEMPLATE< const VECTOR2I > CONST_ITERATOR
void InsertVertex(int aGlobalIndex, VECTOR2I aNewVertex)
Function InsertVertex Adds a vertex in the globally indexed position aGlobalIndex.
CONST_ITERATOR CIterate(int aOutline) 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
POLYGON & Polygon(int aIndex)
Returns the aIndex-th subpolygon in the set
SHAPE * Clone() const override
Function Clone()
bool IsSelfIntersecting()
Function IsSelfIntersecting Checks whether any of the polygons in the set is self intersecting.
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()
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
VERTEX_INDEX GetIndex()
Function GetIndex.
CONST_ITERATOR CIterateWithHoles() const
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...
const VECTOR2I & cvertex(int aCornerId) const
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.
bool IsLastPolygon() const
Function IsLastOutline.