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 1301 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 ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList_NG(), ZONE_CONTAINER::BuildFilledSolidAreasPolygons(), BOARD::CombineAreas(), mergeZones(), and CPolyLine::NormalizeAreaOutlines().

1302 {
1303  SHAPE_POLY_SET rv;
1304 
1305  unsigned corners_count = aList.GetCornersCount();
1306 
1307  // Enter main outline: this is the first contour
1308  unsigned ic = 0;
1309 
1310  if( !corners_count )
1311  return rv;
1312 
1313  int index = 0;
1314 
1315  while( ic < corners_count )
1316  {
1317  int hole = -1;
1318 
1319  if( index == 0 )
1320  {
1321  rv.NewOutline();
1322  hole = -1;
1323  }
1324  else
1325  {
1326  hole = rv.NewHole();
1327  }
1328 
1329  while( ic < corners_count )
1330  {
1331  rv.Append( aList.GetX( ic ), aList.GetY( ic ), 0, hole );
1332 
1333  if( aList.IsEndContour( ic ) )
1334  break;
1335 
1336  ic++;
1337  }
1338  ic++;
1339 
1340  index++;
1341  }
1342 
1343  return rv;
1344 }
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
int Append(int x, int y, int aOutline=-1, int aHole=-1)
Appends a vertex at the end of the given outline/hole (default: the last outline) ...
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
const CPOLYGONS_LIST ConvertPolySetToPolyList ( const SHAPE_POLY_SET aPolyset)

Definition at line 1347 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 BOARD::CombineAreas(), mergeZones(), and CPolyLine::NormalizeAreaOutlines().

1348 {
1349  CPOLYGONS_LIST list;
1350  CPolyPt corner, firstCorner;
1351 
1352  const SHAPE_POLY_SET::POLYGON& poly = aPolyset.CPolygon( 0 );
1353 
1354  for( unsigned int jj = 0; jj < poly.size() ; jj++ )
1355  {
1356  const SHAPE_LINE_CHAIN& path = poly[jj];
1357 
1358  for( int i = 0; i < path.PointCount(); i++ )
1359  {
1360  const VECTOR2I &v = path.CPoint( i );
1361 
1362  corner.x = v.x;
1363  corner.y = v.y;
1364  corner.end_contour = false;
1365 
1366  if( i == 0 )
1367  firstCorner = corner;
1368 
1369  list.AddCorner( corner );
1370  }
1371 
1372  firstCorner.end_contour = true;
1373  list.AddCorner( firstCorner );
1374  }
1375 
1376  return list;
1377 }
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 708 of file PolyLine.cpp.

References wxPoint::x.

Referenced by CPolyLine::Hatch().

709 {
710  return tst.x < ref.x;
711 }