KiCad PCB EDA Suite
PolyLine.cpp File Reference
#include <cmath>
#include <vector>
#include <algorithm>
#include <fctsys.h>
#include <common.h>
#include <PolyLine.h>
#include <bezier_curves.h>
#include <polygon_test_point_inside.h>
#include <math_for_graphics.h>

Go to the source code of this file.

Macros

#define MAXPTS   200
 

Functions

bool sort_ends_by_descending_X (const wxPoint &ref, const wxPoint &tst)
 
const SHAPE_POLY_SET ConvertPolyListToPolySet (const CPOLYGONS_LIST &aList)
 
const CPOLYGONS_LIST ConvertPolySetToPolyList (const SHAPE_POLY_SET &aPolyset)
 

Detailed Description

Note
implementation of CPolyLine class

Definition in file PolyLine.cpp.

Macro Definition Documentation

#define MAXPTS   200

Referenced by CPolyLine::Hatch().

Function Documentation

const SHAPE_POLY_SET ConvertPolyListToPolySet ( const CPOLYGONS_LIST aList)

Definition at line 1316 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().

1317 {
1318  SHAPE_POLY_SET rv;
1319 
1320  unsigned corners_count = aList.GetCornersCount();
1321 
1322  // Enter main outline: this is the first contour
1323  unsigned ic = 0;
1324 
1325  if( !corners_count )
1326  return rv;
1327 
1328  int index = 0;
1329 
1330  while( ic < corners_count )
1331  {
1332  int hole = -1;
1333 
1334  if( index == 0 )
1335  {
1336  rv.NewOutline();
1337  hole = -1;
1338  }
1339  else
1340  {
1341  hole = rv.NewHole();
1342  }
1343 
1344  while( ic < corners_count )
1345  {
1346  rv.Append( aList.GetX( ic ), aList.GetY( ic ), 0, hole );
1347 
1348  if( aList.IsEndContour( ic ) )
1349  break;
1350 
1351  ic++;
1352  }
1353  ic++;
1354 
1355  index++;
1356  }
1357 
1358  return rv;
1359 }
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 1362 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().

1363 {
1364  CPOLYGONS_LIST list;
1365  CPolyPt corner, firstCorner;
1366 
1367  const SHAPE_POLY_SET::POLYGON& poly = aPolyset.CPolygon( 0 );
1368 
1369  for( unsigned int jj = 0; jj < poly.size() ; jj++ )
1370  {
1371  const SHAPE_LINE_CHAIN& path = poly[jj];
1372 
1373  for( int i = 0; i < path.PointCount(); i++ )
1374  {
1375  const VECTOR2I &v = path.CPoint( i );
1376 
1377  corner.x = v.x;
1378  corner.y = v.y;
1379  corner.end_contour = false;
1380 
1381  if( i == 0 )
1382  firstCorner = corner;
1383 
1384  list.AddCorner( corner );
1385  }
1386 
1387  firstCorner.end_contour = true;
1388  list.AddCorner( firstCorner );
1389  }
1390 
1391  return list;
1392 }
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()
bool sort_ends_by_descending_X ( const wxPoint ref,
const wxPoint tst 
)

Definition at line 722 of file PolyLine.cpp.

References wxPoint::x.

Referenced by CPolyLine::Hatch().

723 {
724  return tst.x < ref.x;
725 }