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:
61  typedef std::vector<SHAPE_LINE_CHAIN> POLYGON;
62 
64 
66  {
67  public:
68  struct TRI
69  {
70  TRI()
71  {
72  }
73 
74  int a, b, c;
75  };
76 
78 
79  void Clear();
80 
81  void AllocateVertices( int aSize );
82  void AllocateTriangles ( int aSize );
83 
84  void GetTriangle( int index, VECTOR2I& a, VECTOR2I& b, VECTOR2I& c ) const
85  {
86  auto tri = &m_triangles[ index ];
87  a = m_vertices[ tri->a ];
88  b = m_vertices[ tri->b ];
89  c = m_vertices[ tri->c ];
90  }
91 
92  void SetTriangle( int aIndex, const TRI& aTri )
93  {
94  m_triangles[aIndex] = aTri;
95  }
96 
97  int AddVertex( const VECTOR2I& aP )
98  {
99  m_vertices[ m_vertexCount ] = aP;
100  return (m_vertexCount++);
101  }
102 
103  int VertexCount() const
104  {
105  return m_vertexCount;
106  }
107 
108  int TriangleCount() const
109  {
110  return m_triangleCount;
111  }
112 
113  private:
114 
115  TRI* m_triangles = nullptr;
116  VECTOR2I* m_vertices = nullptr;
117  int m_vertexCount = 0;
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  {
166  }
167 
168  operator bool() const
169  {
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
189  {
190  m_currentVertex = 0;
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;
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;
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  {
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  {
283  }
284 
285  operator bool() const
286  {
288  }
289 
295  void Advance()
296  {
297  // Advance vertex index
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;
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;
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;
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  {
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 &&
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 
428  SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther );
429 
442  bool GetRelativeIndices( int aGlobalIdx, VERTEX_INDEX* aRelativeIndices) const;
443 
453  bool GetGlobalIndex( VERTEX_INDEX aRelativeIndices, int& aGlobalIdx );
454 
456  SHAPE* Clone() const override;
457 
459  int NewOutline();
460 
462  int NewHole( int aOutline = -1 );
463 
465  int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
466 
468  int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
469 
471 
483  int Append( int x, int y, int aOutline = -1, int aHole = -1,
484  bool aAllowDuplication = false );
485 
487  void Append( const SHAPE_POLY_SET& aSet );
488 
490  void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
491 
499  void InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex );
500 
502  VECTOR2I& Vertex( int aIndex, int aOutline, int aHole );
503 
505  const VECTOR2I& CVertex( int aIndex, int aOutline, int aHole ) const;
506 
508  VECTOR2I& Vertex( int aGlobalIndex );
509 
511  const VECTOR2I& CVertex( int aGlobalIndex ) const;
512 
514  VECTOR2I& Vertex( VERTEX_INDEX aIndex );
515 
517  const VECTOR2I& CVertex( VERTEX_INDEX aIndex ) const;
518 
530  bool GetNeighbourIndexes( int aGlobalIndex, int* aPrevious, int* aNext );
531 
532 
540  bool IsPolygonSelfIntersecting( int aPolygonIndex );
541 
547  bool IsSelfIntersecting();
548 
550  int OutlineCount() const { return m_polys.size(); }
551 
553  int VertexCount( int aOutline = -1, int aHole = -1 ) const;
554 
556  int HoleCount( int aOutline ) const
557  {
558  if( ( aOutline < 0 ) || (aOutline >= (int)m_polys.size()) || (m_polys[aOutline].size() < 2) )
559  return 0;
560 
561  // the first polygon in m_polys[aOutline] is the main contour,
562  // only others are holes:
563  return m_polys[aOutline].size() - 1;
564  }
565 
567  SHAPE_LINE_CHAIN& Outline( int aIndex )
568  {
569  return m_polys[aIndex][0];
570  }
571 
581  SHAPE_POLY_SET Subset( int aFirstPolygon, int aLastPolygon );
582 
583  SHAPE_POLY_SET UnitSet( int aPolygonIndex )
584  {
585  return Subset( aPolygonIndex, aPolygonIndex + 1 );
586  }
587 
589  SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
590  {
591  return m_polys[aOutline][aHole + 1];
592  }
593 
595  POLYGON& Polygon( int aIndex )
596  {
597  return m_polys[aIndex];
598  }
599 
600  const POLYGON& Polygon( int aIndex ) const
601  {
602  return m_polys[aIndex];
603  }
604 
605  const TRIANGULATED_POLYGON* TriangulatedPolygon( int aIndex ) const
606  {
607  return m_triangulatedPolys[aIndex].get();
608  }
609 
610 
611  const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
612  {
613  return m_polys[aIndex][0];
614  }
615 
616  const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
617  {
618  return m_polys[aOutline][aHole + 1];
619  }
620 
621  const POLYGON& CPolygon( int aIndex ) const
622  {
623  return m_polys[aIndex];
624  }
625 
636  ITERATOR Iterate( int aFirst, int aLast, bool aIterateHoles = false )
637  {
638  ITERATOR iter;
639 
640  iter.m_poly = this;
641  iter.m_currentPolygon = aFirst;
642  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
643  iter.m_currentContour = 0;
644  iter.m_currentVertex = 0;
645  iter.m_iterateHoles = aIterateHoles;
646 
647  return iter;
648  }
649 
656  ITERATOR Iterate( int aOutline )
657  {
658  return Iterate( aOutline, aOutline );
659  }
660 
667  ITERATOR IterateWithHoles( int aOutline )
668  {
669  return Iterate( aOutline, aOutline, true );
670  }
671 
677  ITERATOR Iterate()
678  {
679  return Iterate( 0, OutlineCount() - 1 );
680  }
681 
687  ITERATOR IterateWithHoles()
688  {
689  return Iterate( 0, OutlineCount() - 1, true );
690  }
691 
692 
693  CONST_ITERATOR CIterate( int aFirst, int aLast, bool aIterateHoles = false ) const
694  {
695  CONST_ITERATOR iter;
696 
697  iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
698  iter.m_currentPolygon = aFirst;
699  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
700  iter.m_currentContour = 0;
701  iter.m_currentVertex = 0;
702  iter.m_iterateHoles = aIterateHoles;
703 
704  return iter;
705  }
706 
707  CONST_ITERATOR CIterate( int aOutline ) const
708  {
709  return CIterate( aOutline, aOutline );
710  }
711 
712  CONST_ITERATOR CIterateWithHoles( int aOutline ) const
713  {
714  return CIterate( aOutline, aOutline, true );
715  }
716 
717  CONST_ITERATOR CIterate() const
718  {
719  return CIterate( 0, OutlineCount() - 1 );
720  }
721 
722  CONST_ITERATOR CIterateWithHoles() const
723  {
724  return CIterate( 0, OutlineCount() - 1, true );
725  }
726 
727  ITERATOR IterateFromVertexWithHoles( int aGlobalIdx )
728  {
729  // Build iterator
730  ITERATOR iter = IterateWithHoles();
731 
732  // Get the relative indices of the globally indexed vertex
733  VERTEX_INDEX indices;
734 
735  if( !GetRelativeIndices( aGlobalIdx, &indices ) )
736  throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
737 
738  // Adjust where the iterator is pointing
739  iter.m_currentPolygon = indices.m_polygon;
740  iter.m_currentContour = indices.m_contour;
741  iter.m_currentVertex = indices.m_vertex;
742 
743  return iter;
744  }
745 
748  SEGMENT_ITERATOR IterateSegments( int aFirst, int aLast, bool aIterateHoles = false )
749  {
750  SEGMENT_ITERATOR iter;
751 
752  iter.m_poly = this;
753  iter.m_currentPolygon = aFirst;
754  iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
755  iter.m_currentContour = 0;
756  iter.m_currentSegment = 0;
757  iter.m_iterateHoles = aIterateHoles;
758 
759  return iter;
760  }
761 
763  SEGMENT_ITERATOR IterateSegments( int aPolygonIdx )
764  {
765  return IterateSegments( aPolygonIdx, aPolygonIdx );
766  }
767 
769  SEGMENT_ITERATOR IterateSegments()
770  {
771  return IterateSegments( 0, OutlineCount() - 1 );
772  }
773 
775  SEGMENT_ITERATOR IterateSegmentsWithHoles()
776  {
777  return IterateSegments( 0, OutlineCount() - 1, true );
778  }
779 
781  SEGMENT_ITERATOR IterateSegmentsWithHoles( int aOutline )
782  {
783  return IterateSegments( aOutline, aOutline, true );
784  }
785 
794  {
795  PM_FAST = true,
797  };
798 
801  void BooleanAdd( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
802 
805  void BooleanSubtract( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
806 
809  void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
810 
813  void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
814  POLYGON_MODE aFastMode );
815 
818  void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
819  POLYGON_MODE aFastMode );
820 
823  void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
824  POLYGON_MODE aFastMode );
825 
827  void Inflate( int aFactor, int aCircleSegmentsCount );
828 
832  void Fracture( POLYGON_MODE aFastMode );
833 
836  void Unfracture( POLYGON_MODE aFastMode );
837 
839  bool HasHoles() const;
840 
842  bool HasTouchingHoles() const;
843 
844 
847  void Simplify( POLYGON_MODE aFastMode );
848 
856  int NormalizeAreaOutlines();
857 
859  const std::string Format() const override;
860 
862  bool Parse( std::stringstream& aStream ) override;
863 
865  void Move( const VECTOR2I& aVector ) override;
866 
868  bool IsSolid() const override
869  {
870  return true;
871  }
872 
873  const BOX2I BBox( int aClearance = 0 ) const override;
874 
882  bool PointOnEdge( const VECTOR2I& aP ) const;
883 
895  bool Collide( const VECTOR2I& aP, int aClearance = 0 ) const override;
896 
897  // fixme: add collision support
898  bool Collide( const SEG& aSeg, int aClearance = 0 ) const override { return false; }
899 
910  bool CollideVertex( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
911  int aClearance = 0 );
912 
923  bool CollideEdge( const VECTOR2I& aPoint, VERTEX_INDEX& aClosestVertex,
924  int aClearance = 0 );
925 
928  bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1 ) const;
929 
931  bool IsEmpty() const
932  {
933  return m_polys.size() == 0;
934  }
935 
941  void RemoveVertex( int aGlobalIndex );
942 
948  void RemoveVertex( VERTEX_INDEX aRelativeIndices );
949 
951  void RemoveAllContours();
952 
961  void RemoveContour( int aContourIdx, int aPolygonIdx = -1 );
962 
968  int RemoveNullSegments();
969 
971  int TotalVertices() const;
972 
974  void DeletePolygon( int aIdx );
975 
983  POLYGON ChamferPolygon( unsigned int aDistance, int aIndex = 0 );
984 
993  POLYGON FilletPolygon( unsigned int aRadius, unsigned int aSegments, int aIndex = 0 );
994 
1001  SHAPE_POLY_SET Chamfer( int aDistance );
1002 
1010  SHAPE_POLY_SET Fillet( int aRadius, int aSegments );
1011 
1020  int DistanceToPolygon( VECTOR2I aPoint, int aIndex );
1021 
1034  int DistanceToPolygon( SEG aSegment, int aIndex, int aSegmentWidth = 0 );
1035 
1043  int Distance( VECTOR2I aPoint );
1044 
1053  int Distance( SEG aSegment, int aSegmentWidth = 0 );
1054 
1061  bool IsVertexInHole( int aGlobalIdx );
1062 
1063  private:
1064 
1065  SHAPE_LINE_CHAIN& getContourForCorner( int aCornerId, int& aIndexWithinContour );
1066  VECTOR2I& vertex( int aCornerId );
1067  const VECTOR2I& cvertex( int aCornerId ) const;
1068 
1069 
1070  void fractureSingle( POLYGON& paths );
1071  void unfractureSingle ( POLYGON& path );
1072  void importTree( ClipperLib::PolyTree* tree );
1073 
1085  void booleanOp( ClipperLib::ClipType aType,
1086  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1087 
1088  void booleanOp( ClipperLib::ClipType aType,
1089  const SHAPE_POLY_SET& aShape,
1090  const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
1091 
1092  bool pointInPolygon( const VECTOR2I& aP, const SHAPE_LINE_CHAIN& aPath ) const;
1093 
1094  const ClipperLib::Path convertToClipper( const SHAPE_LINE_CHAIN& aPath, bool aRequiredOrientation );
1095  const SHAPE_LINE_CHAIN convertFromClipper( const ClipperLib::Path& aPath );
1096 
1108  bool containsSingle( const VECTOR2I& aP, int aSubpolyIndex ) const;
1109 
1116  {
1119  };
1120 
1121 
1122 
1137  POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
1138  int aIndex, int aSegments = -1 );
1139 
1141  bool hasTouchingHoles( const POLYGON& aPoly ) const;
1142 
1143  typedef std::vector<POLYGON> POLYSET;
1144 
1145  POLYSET m_polys;
1146 
1147  public:
1148 
1150 
1151  void CacheTriangulation();
1152  bool IsTriangulationUpToDate() const;
1153 
1154  private:
1155  void triangulateSingle( const POLYGON& aPoly, SHAPE_POLY_SET::TRIANGULATED_POLYGON& aResult );
1156 
1157  MD5_HASH checksum() const;
1158 
1159  std::vector<std::unique_ptr<TRIANGULATED_POLYGON>> m_triangulatedPolys;
1160  bool m_triangulationValid = false;
1162 
1163 };
1164 
1165 #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.
void SetTriangle(int aIndex, const TRI &aTri)
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...
bool Collide(const SEG &aSeg, int aClearance=0) const override
Function Collide()
T
enum T contains all this lexer's tokens.
std::vector< POLYGON > POLYSET
bool IsLastPolygon() const
Function IsLastOutline.
const ClipperLib::Path convertToClipper(const SHAPE_LINE_CHAIN &aPath, bool aRequiredOrientation)
MD5_HASH checksum() 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.
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
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
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.
bool IsEndContour() const
Function IsEndContour.
bool IsVertexInHole(int aGlobalIdx)
Function IsVertexInHole.
VECTOR2I & Vertex(int aIndex, int aOutline, int aHole)
Returns the index-th vertex in a given hole outline within a given outline
void DeletePolygon(int aIdx)
Deletes aIdx-th polygon from the set
CONST_ITERATOR CIterate(int aOutline) const
SHAPE_LINE_CHAIN & getContourForCorner(int aCornerId, int &aIndexWithinContour)
bool GetNeighbourIndexes(int aGlobalIndex, int *aPrevious, int *aNext)
Returns the global indexes of the previous and the next corner of the aGlobalIndex-th corner of a con...
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.
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...
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
int AddVertex(const VECTOR2I &aP)
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
Class SHAPE.
Definition: shape.h:57
bool Collide(const VECTOR2I &aP, int aClearance=0) const override
Function Collide Checks whether the point aP collides with the inside of the polygon set; if the poin...
const std::string Format() const override
int RemoveNullSegments()
Function RemoveNullSegments looks for null segments; ie, segments whose ends are exactly the same and...
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Performs boolean polyset intersection For aFastMode meaning, see function booleanOp ...
void triangulateSingle(const POLYGON &aPoly, SHAPE_POLY_SET::TRIANGULATED_POLYGON &aResult)
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.
SHAPE_POLY_SET UnitSet(int aPolygonIndex)
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
const SHAPE_LINE_CHAIN convertFromClipper(const ClipperLib::Path &aPath)
ITERATOR IterateWithHoles()
Function IterateWithHoles.
Class SHAPE_LINE_CHAIN.
void RemoveVertex(int aGlobalIndex)
Function RemoveVertex deletes the aGlobalIndex-th vertex.
int Distance(VECTOR2I aPoint)
Function DistanceToPolygon computes the minimum distance between aPoint and all the polygons in the s...
int VertexCount(int aOutline=-1, int aHole=-1) const
Returns the number of vertices in a given outline/hole
Class ITERATOR_TEMPLATE.
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
ITERATOR_TEMPLATE< const VECTOR2I > CONST_ITERATOR
bool IsLastPolygon() const
Function IsLastOutline.
const POLYGON & CPolygon(int aIndex) const
void InsertVertex(int aGlobalIndex, VECTOR2I aNewVertex)
Function InsertVertex Adds a vertex in the globally indexed position aGlobalIndex.
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
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)
void Unfracture(POLYGON_MODE aFastMode)
Converts a single outline slitted ("fractured") polygon into a set ouf outlines with holes...