KiCad PCB EDA Suite
PolyLine.h File Reference
#include <vector>
#include <wx/gdicmn.h>
#include <layers_id_colors_and_visibility.h>
#include <class_eda_rect.h>
#include <geometry/shape_poly_set.h>

Go to the source code of this file.

Classes

class  CSegment
 
class  CPolyPt
 
class  CPOLYGONS_LIST
 CPOLYGONS_LIST handle a list of contours (polygons corners). More...
 
class  CPolyLine
 

Functions

const SHAPE_POLY_SET ConvertPolyListToPolySet (const CPOLYGONS_LIST &aList)
 
const CPOLYGONS_LIST ConvertPolySetToPolyList (const SHAPE_POLY_SET &aPolyset)
 

Detailed Description

Note
definition of CPolyLine class

Definition in file PolyLine.h.

Function Documentation

const SHAPE_POLY_SET ConvertPolyListToPolySet ( const CPOLYGONS_LIST aList)

Definition at line 1315 of file PolyLine.cpp.

References SHAPE_POLY_SET::Append(), CPOLYGONS_LIST::GetCornersCount(), CPOLYGONS_LIST::GetX(), CPOLYGONS_LIST::GetY(), CPOLYGONS_LIST::IsEndContour(), SHAPE_POLY_SET::NewHole(), and SHAPE_POLY_SET::NewOutline().

Referenced by CPolyLine::NormalizeAreaOutlines().

1316 {
1317  SHAPE_POLY_SET rv;
1318 
1319  unsigned corners_count = aList.GetCornersCount();
1320 
1321  // Enter main outline: this is the first contour
1322  unsigned ic = 0;
1323 
1324  if( !corners_count )
1325  return rv;
1326 
1327  int index = 0;
1328 
1329  while( ic < corners_count )
1330  {
1331  int hole = -1;
1332 
1333  if( index == 0 )
1334  {
1335  rv.NewOutline();
1336  hole = -1;
1337  }
1338  else
1339  {
1340  hole = rv.NewHole();
1341  }
1342 
1343  while( ic < corners_count )
1344  {
1345  rv.Append( aList.GetX( ic ), aList.GetY( ic ), 0, hole );
1346 
1347  if( aList.IsEndContour( ic ) )
1348  break;
1349 
1350  ic++;
1351  }
1352  ic++;
1353 
1354  index++;
1355  }
1356 
1357  return rv;
1358 }
int NewHole(int aOutline=-1)
Creates a new hole in a given outline
bool IsEndContour(int ic) const
Definition: PolyLine.h:131
unsigned GetCornersCount() const
Definition: PolyLine.h:146
Class SHAPE_POLY_SET.
int NewOutline()
Creates a new empty polygon in the set and returns its index
int GetY(int ic) const
Definition: PolyLine.h:128
int GetX(int ic) const
Definition: PolyLine.h:126
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) ...
const CPOLYGONS_LIST ConvertPolySetToPolyList ( const SHAPE_POLY_SET aPolyset)

Definition at line 1361 of file PolyLine.cpp.

References CPOLYGONS_LIST::AddCorner(), SHAPE_LINE_CHAIN::CPoint(), SHAPE_POLY_SET::CPolygon(), CPolyPt::end_contour, SHAPE_LINE_CHAIN::PointCount(), wxPoint::x, VECTOR2< T >::x, wxPoint::y, and VECTOR2< T >::y.

Referenced by CPolyLine::NormalizeAreaOutlines().

1362 {
1363  CPOLYGONS_LIST list;
1364  CPolyPt corner, firstCorner;
1365 
1366  const SHAPE_POLY_SET::POLYGON& poly = aPolyset.CPolygon( 0 );
1367 
1368  for( unsigned int jj = 0; jj < poly.size() ; jj++ )
1369  {
1370  const SHAPE_LINE_CHAIN& path = poly[jj];
1371 
1372  for( int i = 0; i < path.PointCount(); i++ )
1373  {
1374  const VECTOR2I &v = path.CPoint( i );
1375 
1376  corner.x = v.x;
1377  corner.y = v.y;
1378  corner.end_contour = false;
1379 
1380  if( i == 0 )
1381  firstCorner = corner;
1382 
1383  list.AddCorner( corner );
1384  }
1385 
1386  firstCorner.end_contour = true;
1387  list.AddCorner( firstCorner );
1388  }
1389 
1390  return list;
1391 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
int PointCount() const
Function PointCount()
Class SHAPE_LINE_CHAIN.
void AddCorner(const CPolyPt &aCorner)
function AddCorner add a corner to the list
Definition: PolyLine.h:188
bool end_contour
Definition: PolyLine.h:97
const POLYGON & CPolygon(int aIndex) const
CPOLYGONS_LIST handle a list of contours (polygons corners).
Definition: PolyLine.h:114
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()