KiCad PCB EDA Suite
CPolyLine Class Reference

#include <PolyLine.h>

Public Types

enum  HATCH_STYLE { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }
 

Public Member Functions

 CPolyLine ()
 
 CPolyLine (const CPolyLine &aCPolyLine)
 
 ~CPolyLine ()
 
void ImportSettings (const CPolyLine *aPoly)
 Function ImportSettings Copy settings (layer, hatch styles) from aPoly. More...
 
void Start (LAYER_NUM layer, int x, int y, int hatch)
 
void AppendCorner (int x, int y)
 
void InsertCorner (int ic, int x, int y)
 Function InsertCorner insert a new corner between two existing corners. More...
 
void DeleteCorner (int ic)
 Function DeleteCorner remove the given corner. More...
 
void MoveCorner (int ic, int x, int y)
 
void CloseLastContour ()
 function CloseLastContour Set the .end_contour member of the last corner of the last contour to true More...
 
void RemoveContour (int icont)
 Function RemoveContour. More...
 
bool IsPolygonSelfIntersecting ()
 Function IsPolygonSelfIntersecting Test a CPolyLine for self-intersection of vertex (all contours). More...
 
CPolyLineChamfer (unsigned int aDistance)
 Function Chamfer returns a chamfered version of a polygon. More...
 
CPolyLineFillet (unsigned int aRadius, unsigned int aSegments)
 Function Fillet returns a filleted version of a polygon. More...
 
int RemoveNullSegments ()
 Function RemoveNullSegments Removes corners which create a null segment edge (i.e. More...
 
void RemoveAllContours (void)
 function RemoveAllContours removes all corners from the list. More...
 
void UnHatch ()
 
void Hatch ()
 
void MoveOrigin (int x_off, int y_off)
 
const EDA_RECT GetBoundingBox ()
 
const EDA_RECT GetBoundingBox (int icont)
 
void Copy (const CPolyLine *src)
 
bool TestPointInside (int x, int y)
 
bool IsCutoutContour (int aCornerIdx)
 
void AppendArc (int xi, int yi, int xf, int yf, int xc, int yc, int num)
 Function AppendArc. More...
 
void SetLayer (LAYER_NUM aLayer)
 
LAYER_NUM GetLayer () const
 
int GetCornersCount () const
 
bool GetClosed ()
 
int GetContoursCount () const
 Function GetContoursCount. More...
 
int GetContour (int ic)
 Function GetContour. More...
 
int GetContourStart (int icont)
 Function GetContourStart. More...
 
int GetContourEnd (int icont)
 Function GetContourEnd. More...
 
int GetContourSize (int icont)
 Function GetContourSize. More...
 
int GetX (int ic) const
 
int GetY (int ic) const
 
bool IsEndContour (int ic) const
 Function IsEndContour. More...
 
const wxPointGetPos (int ic) const
 
int GetHatchPitch () const
 
enum HATCH_STYLE GetHatchStyle () const
 
void SetHatch (int aHatchStyle, int aHatchPitch, bool aRebuildHatch)
 
void SetX (int ic, int x)
 
void SetY (int ic, int y)
 
void SetHatchStyle (enum HATCH_STYLE style)
 
void SetHatchPitch (int pitch)
 
int NormalizeAreaOutlines (std::vector< CPolyLine * > *aNewPolygonList)
 Function NormalizeAreaOutlines Convert a self-intersecting polygon to one (or more) non self-intersecting polygon(s) Removes null segments. More...
 
void AppendBezier (int x1, int y1, int x2, int y2, int x3, int y3)
 
void AppendBezier (int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
 
int Distance (const wxPoint &aPoint)
 Function Distance Calculates the distance between a point and the zone: More...
 
int Distance (wxPoint aStart, wxPoint aEnd, int aWidth)
 Function Distance Calculates the distance between a segment and the zone: More...
 
int HitTestForEdge (const wxPoint &aPos, int aDistMax) const
 Function HitTestForEdge test is the point aPos is near (< aDistMax ) a vertex. More...
 
int HitTestForCorner (const wxPoint &aPos, int aDistMax) const
 Function HitTestForCorner test is the point aPos is near (< aDistMax ) a corner. More...
 

Static Public Member Functions

static int GetDefaultHatchPitchMils ()
 

Public Attributes

CPOLYGONS_LIST m_CornersList
 
std::vector< CSegmentm_HatchLines
 

Private Attributes

LAYER_NUM m_layer
 
enum HATCH_STYLE m_hatchStyle
 
int m_hatchPitch
 
int m_flags
 

Detailed Description

Definition at line 213 of file PolyLine.h.

Member Enumeration Documentation

Enumerator
NO_HATCH 
DIAGONAL_FULL 
DIAGONAL_EDGE 

Definition at line 216 of file PolyLine.h.

Constructor & Destructor Documentation

CPolyLine::CPolyLine ( )

Definition at line 51 of file PolyLine.cpp.

References F_Cu, m_flags, m_hatchPitch, m_hatchStyle, m_layer, and NO_HATCH.

Referenced by Chamfer(), Fillet(), and NormalizeAreaOutlines().

52 {
54  m_hatchPitch = 0;
55  m_layer = F_Cu;
56  m_flags = 0;
57 }
LAYER_NUM m_layer
Definition: PolyLine.h:480
enum HATCH_STYLE m_hatchStyle
Definition: PolyLine.h:481
int m_flags
Definition: PolyLine.h:485
int m_hatchPitch
Definition: PolyLine.h:482
CPolyLine::CPolyLine ( const CPolyLine aCPolyLine)

Definition at line 59 of file PolyLine.cpp.

References Copy(), and m_HatchLines.

60 {
61  Copy( &aCPolyLine );
62  m_HatchLines = aCPolyLine.m_HatchLines; // vector <> copy
63 }
void Copy(const CPolyLine *src)
Definition: PolyLine.cpp:929
std::vector< CSegment > m_HatchLines
Definition: PolyLine.h:488
CPolyLine::~CPolyLine ( )

Definition at line 68 of file PolyLine.cpp.

References UnHatch().

69 {
70  UnHatch();
71 }
void UnHatch()
Definition: PolyLine.cpp:545

Member Function Documentation

void CPolyLine::AppendArc ( int  xi,
int  yi,
int  xf,
int  yf,
int  xc,
int  yc,
int  num 
)

Function AppendArc.

Adds segments to current contour to approximate the given arc

Definition at line 973 of file PolyLine.cpp.

References AppendCorner(), CloseLastContour(), Distance(), and KiROUND().

974 {
975  // get radius
976  double radius = ::Distance( xi, yi, xf, yf );
977 
978  // get angles of start pint and end point
979  double th_i = atan2( (double) (yi - yc), (double) (xi - xc) );
980  double th_f = atan2( (double) (yf - yc), (double) (xf - xc) );
981  double th_d = (th_f - th_i) / (num - 1);
982  double theta = th_i;
983 
984  // generate arc
985  for( int ic = 0; ic < num; ic++ )
986  {
987  int x = xc + KiROUND( radius * cos( theta ) );
988  int y = yc + KiROUND( radius * sin( theta ) );
989  AppendCorner( x, y );
990  theta += th_d;
991  }
992 
994 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void AppendCorner(int x, int y)
Definition: PolyLine.cpp:199
int Distance(const wxPoint &aPoint)
Function Distance Calculates the distance between a point and the zone:
Definition: PolyLine.cpp:1089
void CloseLastContour()
function CloseLastContour Set the .end_contour member of the last corner of the last contour to true ...
Definition: PolyLine.h:254
void CPolyLine::AppendBezier ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3 
)

Definition at line 998 of file PolyLine.cpp.

References AppendCorner(), and Bezier2Poly().

999 {
1000  std::vector<wxPoint> bezier_points;
1001 
1002  bezier_points = Bezier2Poly( x1, y1, x2, y2, x3, y3 );
1003 
1004  for( unsigned int i = 0; i < bezier_points.size(); i++ )
1005  AppendCorner( bezier_points[i].x, bezier_points[i].y );
1006 }
void AppendCorner(int x, int y)
Definition: PolyLine.cpp:199
std::vector< wxPoint > Bezier2Poly(wxPoint c1, wxPoint c2, wxPoint c3, wxPoint c4)
Function Bezier2Poly convert a Bezier curve to a polyline.
void CPolyLine::AppendBezier ( int  x1,
int  y1,
int  x2,
int  y2,
int  x3,
int  y3,
int  x4,
int  y4 
)

Definition at line 1009 of file PolyLine.cpp.

References AppendCorner(), and Bezier2Poly().

1010 {
1011  std::vector<wxPoint> bezier_points;
1012 
1013  bezier_points = Bezier2Poly( x1, y1, x2, y2, x3, y3, x4, y4 );
1014 
1015  for( unsigned int i = 0; i < bezier_points.size(); i++ )
1016  AppendCorner( bezier_points[i].x, bezier_points[i].y );
1017 }
void AppendCorner(int x, int y)
Definition: PolyLine.cpp:199
std::vector< wxPoint > Bezier2Poly(wxPoint c1, wxPoint c2, wxPoint c3, wxPoint c4)
Function Bezier2Poly convert a Bezier curve to a polyline.
void CPolyLine::AppendCorner ( int  x,
int  y 
)

Definition at line 199 of file PolyLine.cpp.

References CPOLYGONS_LIST::Append(), CPolyPt::end_contour, m_CornersList, and UnHatch().

Referenced by AppendArc(), AppendBezier(), ZONE_CONTAINER::AppendCorner(), Chamfer(), and Fillet().

200 {
201  UnHatch();
202  CPolyPt poly_pt( x, y );
203  poly_pt.end_contour = false;
204 
205  // add entries for new corner
206  m_CornersList.Append( poly_pt );
207 }
void UnHatch()
Definition: PolyLine.cpp:545
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
void Append(const CPOLYGONS_LIST &aList)
Definition: PolyLine.h:160
CPolyLine * CPolyLine::Chamfer ( unsigned int  aDistance)

Function Chamfer returns a chamfered version of a polygon.

Parameters
aDistanceis the chamfering distance.
Returns
CPolyLine* - Pointer to new polygon.

Definition at line 285 of file PolyLine.cpp.

References AppendCorner(), CloseLastContour(), Copy(), CPolyLine(), GetContourEnd(), GetContoursCount(), GetContourStart(), GetHatchStyle(), GetLayer(), KiROUND(), m_CornersList, RemoveNullSegments(), and Start().

Referenced by ZONE_CONTAINER::BuildFilledSolidAreasPolygons().

286 {
287  // Null segments create serious issues in calculations.
288  // remove them:
290 
291  CPolyLine* newPoly = new CPolyLine;
292 
293  if( !aDistance )
294  {
295  newPoly->Copy( this );
296  return newPoly;
297  }
298 
299  int polycount = GetContoursCount();
300 
301  for( int contour = 0; contour < polycount; contour++ )
302  {
303  unsigned int startIndex = GetContourStart( contour );
304  unsigned int endIndex = GetContourEnd( contour );
305 
306  for( unsigned int index = startIndex; index <= endIndex; index++ )
307  {
308  // Current vertex
309  int x1 = m_CornersList[index].x;
310  int y1 = m_CornersList[index].y;
311  double xa, ya; // Previous vertex
312  double xb, yb; // Next vertex
313 
314  if( index == startIndex )
315  {
316  xa = m_CornersList[endIndex].x - x1;
317  ya = m_CornersList[endIndex].y - y1;
318  }
319  else
320  {
321  xa = m_CornersList[index - 1].x - x1;
322  ya = m_CornersList[index - 1].y - y1;
323  }
324 
325  if( index == endIndex )
326  {
327  xb = m_CornersList[startIndex].x - x1;
328  yb = m_CornersList[startIndex].y - y1;
329  }
330  else
331  {
332  xb = m_CornersList[index + 1].x - x1;
333  yb = m_CornersList[index + 1].y - y1;
334  }
335 
336  double lena = hypot( xa, ya );
337  double lenb = hypot( xb, yb );
338  double distance = aDistance;
339 
340  // Chamfer one half of an edge at most
341  if( 0.5 * lena < distance )
342  distance = 0.5 * lena;
343 
344  if( 0.5 * lenb < distance )
345  distance = 0.5 * lenb;
346 
347  int nx1 = KiROUND( distance * xa / lena );
348  int ny1 = KiROUND( distance * ya / lena );
349 
350  if( index == startIndex )
351  newPoly->Start( GetLayer(), x1 + nx1, y1 + ny1, GetHatchStyle() );
352  else
353  newPoly->AppendCorner( x1 + nx1, y1 + ny1 );
354 
355  int nx2 = KiROUND( distance * xb / lenb );
356  int ny2 = KiROUND( distance * yb / lenb );
357  newPoly->AppendCorner( x1 + nx2, y1 + ny2 );
358  }
359 
360  newPoly->CloseLastContour();
361  }
362 
363  return newPoly;
364 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void Copy(const CPolyLine *src)
Definition: PolyLine.cpp:929
void Start(LAYER_NUM layer, int x, int y, int hatch)
Definition: PolyLine.cpp:186
enum HATCH_STYLE GetHatchStyle() const
Definition: PolyLine.h:399
void AppendCorner(int x, int y)
Definition: PolyLine.cpp:199
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
int RemoveNullSegments()
Function RemoveNullSegments Removes corners which create a null segment edge (i.e.
Definition: PolyLine.cpp:77
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
LAYER_NUM GetLayer() const
Definition: PolyLine.h:337
void CloseLastContour()
function CloseLastContour Set the .end_contour member of the last corner of the last contour to true ...
Definition: PolyLine.h:254
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
void CPolyLine::CloseLastContour ( )
inline

function CloseLastContour Set the .end_contour member of the last corner of the last contour to true

Definition at line 254 of file PolyLine.h.

References CPOLYGONS_LIST::CloseLastContour(), and m_CornersList.

Referenced by ZONE_CONTAINER::AddPolygon(), PCAD2KICAD::PCB_POLYGON::AddToBoard(), AppendArc(), Chamfer(), PCB_EDIT_FRAME::End_Zone(), Fillet(), EAGLE_PLUGIN::loadPlain(), EAGLE_PLUGIN::loadSignals(), and ZONE_CREATE_HELPER::performZoneCutout().

255  {
257  }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
void CloseLastContour()
function CloseLastContour Set the .end_contour member of the last corner in list to true ...
Definition: PolyLine.h:197
void CPolyLine::Copy ( const CPolyLine src)

Definition at line 929 of file PolyLine.cpp.

References CPOLYGONS_LIST::Append(), m_CornersList, m_flags, m_hatchPitch, m_hatchStyle, m_layer, CPOLYGONS_LIST::RemoveAllContours(), and UnHatch().

Referenced by Chamfer(), CPolyLine(), Fillet(), and ZONE_CONTAINER::operator=().

930 {
931  UnHatch();
932  m_layer = src->m_layer;
933  m_hatchStyle = src->m_hatchStyle;
934  m_hatchPitch = src->m_hatchPitch;
935  m_flags = src->m_flags;
938 }
void UnHatch()
Definition: PolyLine.cpp:545
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
LAYER_NUM m_layer
Definition: PolyLine.h:480
enum HATCH_STYLE m_hatchStyle
Definition: PolyLine.h:481
int m_flags
Definition: PolyLine.h:485
void RemoveAllContours(void)
Definition: PolyLine.h:143
void Append(const CPOLYGONS_LIST &aList)
Definition: PolyLine.h:160
int m_hatchPitch
Definition: PolyLine.h:482
void CPolyLine::DeleteCorner ( int  ic)

Function DeleteCorner remove the given corner.

if it is the last point of a contour keep the controur closed by modifying the previous corner

Parameters
ic= the index of the corner to delete

Definition at line 222 of file PolyLine.cpp.

References CPOLYGONS_LIST::DeleteCorner(), GetClosed(), GetContour(), GetContourEnd(), GetContoursCount(), GetContourSize(), m_CornersList, RemoveContour(), and UnHatch().

Referenced by Abort_Zone_Move_Corner_Or_Outlines(), PCB_EDIT_FRAME::Delete_LastCreatedCorner(), PCB_EDIT_FRAME::Remove_Zone_Corner(), POINT_EDITOR::removeCorner(), RemoveNullSegments(), and PCB_EDIT_FRAME::Start_Move_Zone_Corner().

223 {
224  UnHatch();
225  int icont = GetContour( ic );
226  int iend = GetContourEnd( icont );
227  bool closed = icont < GetContoursCount() - 1 || GetClosed();
228 
229  if( !closed )
230  {
231  // open contour, must be last contour
233  }
234  else
235  {
236  // closed contour
238 
239  if( ic == iend )
240  m_CornersList[ic - 1].end_contour = true;
241  }
242 
243  if( closed && GetContourSize( icont ) < 3 )
244  {
245  // delete the entire contour
246  RemoveContour( icont );
247  }
248 }
void UnHatch()
Definition: PolyLine.cpp:545
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
void RemoveContour(int icont)
Function RemoveContour.
Definition: PolyLine.cpp:252
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
int GetContourSize(int icont)
Function GetContourSize.
Definition: PolyLine.cpp:690
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
void DeleteCorner(int aIdx)
Definition: PolyLine.h:148
bool GetClosed()
Definition: PolyLine.cpp:696
int GetContour(int ic)
Function GetContour.
Definition: PolyLine.cpp:627
int CPolyLine::Distance ( const wxPoint aPoint)

Function Distance Calculates the distance between a point and the zone:

Parameters
aPointthe coordinate of the point.
Returns
int = distance between the point and outline. 0 if the point is inside

Definition at line 1089 of file PolyLine.cpp.

References GetContourEnd(), GetContoursCount(), GetContourStart(), GetPointToLineSegmentDistance(), GetX(), GetY(), KiROUND(), TestPointInside(), wxPoint::x, and wxPoint::y.

Referenced by AppendArc(), DRC::doTrackKeepoutDrc(), and DRC::testKeepoutAreas().

1090 {
1091  // We calculate the dist between the point and each outline segment
1092  // If the point is inside the outline, the dist is 0.
1093  if( TestPointInside( aPoint.x, aPoint.y ) )
1094  return 0;
1095 
1096  int distance = INT_MAX;
1097  int polycount = GetContoursCount();
1098 
1099  for( int icont = 0; icont < polycount; icont++ )
1100  {
1101  int ic_start = GetContourStart( icont );
1102  int ic_end = GetContourEnd( icont );
1103 
1104  // now test spacing between area outline and segment
1105  for( int ic2 = ic_start; ic2 <= ic_end; ic2++ )
1106  {
1107  int bx1 = GetX( ic2 );
1108  int by1 = GetY( ic2 );
1109  int bx2, by2;
1110 
1111  if( ic2 == ic_end )
1112  {
1113  bx2 = GetX( ic_start );
1114  by2 = GetY( ic_start );
1115  }
1116  else
1117  {
1118  bx2 = GetX( ic2 + 1 );
1119  by2 = GetY( ic2 + 1 );
1120  }
1121 
1122  int d = KiROUND( GetPointToLineSegmentDistance( aPoint.x, aPoint.y,
1123  bx1, by1, bx2, by2 ) );
1124 
1125  if( distance > d )
1126  distance = d;
1127 
1128  if( distance <= 0 )
1129  return 0;
1130  }
1131  }
1132 
1133  return distance;
1134 }
double GetPointToLineSegmentDistance(int x, int y, int xi, int yi, int xf, int yf)
Function GetPointToLineSegmentDistance Get distance between line segment and point.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
int GetY(int ic) const
Definition: PolyLine.h:385
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
int GetX(int ic) const
Definition: PolyLine.h:384
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
bool TestPointInside(int x, int y)
Definition: PolyLine.cpp:899
int CPolyLine::Distance ( wxPoint  aStart,
wxPoint  aEnd,
int  aWidth 
)

Function Distance Calculates the distance between a segment and the zone:

Parameters
aStartthe starting point of the segment.
aEndthe ending point of the segment.
aWidththe width of the segment.
Returns
int = distance between the segment and outline. 0 if segment intersects or is inside

Definition at line 1029 of file PolyLine.cpp.

References GetClearanceBetweenSegments(), GetContourEnd(), GetContoursCount(), GetContourStart(), GetX(), GetY(), TestPointInside(), wxPoint::x, and wxPoint::y.

1030 {
1031  // We calculate the min dist between the segment and each outline segment
1032  // However, if the segment to test is inside the outline, and does not cross
1033  // any edge, it can be seen outside the polygon.
1034  // Therefore test if a segment end is inside ( testing only one end is enough )
1035  if( TestPointInside( aStart.x, aStart.y ) )
1036  return 0;
1037 
1038  int distance = INT_MAX;
1039  int polycount = GetContoursCount();
1040 
1041  for( int icont = 0; icont < polycount; icont++ )
1042  {
1043  int ic_start = GetContourStart( icont );
1044  int ic_end = GetContourEnd( icont );
1045 
1046  // now test spacing between area outline and segment
1047  for( int ic2 = ic_start; ic2 <= ic_end; ic2++ )
1048  {
1049  int bx1 = GetX( ic2 );
1050  int by1 = GetY( ic2 );
1051  int bx2, by2;
1052 
1053  if( ic2 == ic_end )
1054  {
1055  bx2 = GetX( ic_start );
1056  by2 = GetY( ic_start );
1057  }
1058  else
1059  {
1060  bx2 = GetX( ic2 + 1 );
1061  by2 = GetY( ic2 + 1 );
1062  }
1063 
1064  int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, 0,
1065  aStart.x, aStart.y, aEnd.x, aEnd.y,
1066  aWidth,
1067  1, // min clearance, should be > 0
1068  NULL, NULL );
1069 
1070  if( distance > d )
1071  distance = d;
1072 
1073  if( distance <= 0 )
1074  return 0;
1075  }
1076  }
1077 
1078  return distance;
1079 }
int GetY(int ic) const
Definition: PolyLine.h:385
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
int GetClearanceBetweenSegments(int x1i, int y1i, int x1f, int y1f, int w1, int x2i, int y2i, int x2f, int y2f, int w2, int max_cl, int *x, int *y)
int GetX(int ic) const
Definition: PolyLine.h:384
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
bool TestPointInside(int x, int y)
Definition: PolyLine.cpp:899
CPolyLine * CPolyLine::Fillet ( unsigned int  aRadius,
unsigned int  aSegments 
)

Function Fillet returns a filleted version of a polygon.

Parameters
aRadiusis the fillet radius.
aSegmentsis the number of segments / fillet.
Returns
CPolyLine* - Pointer to new polygon.

Definition at line 367 of file PolyLine.cpp.

References AppendCorner(), CloseLastContour(), Copy(), CPolyLine(), GetContourEnd(), GetContoursCount(), GetContourStart(), GetHatchStyle(), GetLayer(), KiROUND(), m_CornersList, RemoveNullSegments(), and Start().

Referenced by ZONE_CONTAINER::BuildFilledSolidAreasPolygons().

368 {
369  // Null segments create serious issues in calculations.
370  // remove them:
372 
373  CPolyLine* newPoly = new CPolyLine;
374 
375  if( !aRadius )
376  {
377  newPoly->Copy( this );
378  return newPoly;
379  }
380 
381  int polycount = GetContoursCount();
382 
383  for( int contour = 0; contour < polycount; contour++ )
384  {
385  unsigned int startIndex = GetContourStart( contour );
386  unsigned int endIndex = GetContourEnd( contour );
387 
388  for( unsigned int index = startIndex; index <= endIndex; index++ )
389  {
390  // Current vertex
391  int x1 = m_CornersList[index].x;
392  int y1 = m_CornersList[index].y;
393  double xa, ya; // Previous vertex
394  double xb, yb; // Next vertex
395 
396  if( index == startIndex )
397  {
398  xa = m_CornersList[endIndex].x - x1;
399  ya = m_CornersList[endIndex].y - y1;
400  }
401  else
402  {
403  xa = m_CornersList[index - 1].x - x1;
404  ya = m_CornersList[index - 1].y - y1;
405  }
406 
407  if( index == endIndex )
408  {
409  xb = m_CornersList[startIndex].x - x1;
410  yb = m_CornersList[startIndex].y - y1;
411  }
412  else
413  {
414  xb = m_CornersList[index + 1].x - x1;
415  yb = m_CornersList[index + 1].y - y1;
416  }
417 
418  double lena = hypot( xa, ya );
419  double lenb = hypot( xb, yb );
420  double cosine = ( xa * xb + ya * yb ) / ( lena * lenb );
421 
422  double radius = aRadius;
423  double denom = sqrt( 2.0 / ( 1 + cosine ) - 1 );
424 
425  // Do nothing in case of parallel edges
426  if( !std::isfinite( denom ) )
427  continue;
428 
429  // Limit rounding distance to one half of an edge
430  if( 0.5 * lena * denom < radius )
431  radius = 0.5 * lena * denom;
432 
433  if( 0.5 * lenb * denom < radius )
434  radius = 0.5 * lenb * denom;
435 
436  // Calculate fillet arc absolute center point (xc, yx)
437  double k = radius / sqrt( .5 * ( 1 - cosine ) );
438  double lenab = sqrt( ( xa / lena + xb / lenb ) * ( xa / lena + xb / lenb ) +
439  ( ya / lena + yb / lenb ) * ( ya / lena + yb / lenb ) );
440  double xc = x1 + k * ( xa / lena + xb / lenb ) / lenab;
441  double yc = y1 + k * ( ya / lena + yb / lenb ) / lenab;
442 
443  // Calculate arc start and end vectors
444  k = radius / sqrt( 2 / ( 1 + cosine ) - 1 );
445  double xs = x1 + k * xa / lena - xc;
446  double ys = y1 + k * ya / lena - yc;
447  double xe = x1 + k * xb / lenb - xc;
448  double ye = y1 + k * yb / lenb - yc;
449 
450  // Cosine of arc angle
451  double argument = ( xs * xe + ys * ye ) / ( radius * radius );
452 
453  if( argument < -1 ) // Just in case...
454  argument = -1;
455  else if( argument > 1 )
456  argument = 1;
457 
458  double arcAngle = acos( argument );
459 
460  // Calculate the number of segments
461  double tempSegments = (double) aSegments * ( arcAngle / ( 2 * M_PI ) );
462 
463  if( tempSegments - (int) tempSegments > 0 )
464  tempSegments++;
465 
466  unsigned int segments = (unsigned int) tempSegments;
467 
468  double deltaAngle = arcAngle / segments;
469  double startAngle = atan2( -ys, xs );
470 
471  // Flip arc for inner corners
472  if( xa * yb - ya * xb <= 0 )
473  deltaAngle *= -1;
474 
475  double nx = xc + xs;
476  double ny = yc + ys;
477 
478  if( index == startIndex )
479  newPoly->Start( GetLayer(), KiROUND( nx ), KiROUND( ny ), GetHatchStyle() );
480  else
481  newPoly->AppendCorner( KiROUND( nx ), KiROUND( ny ) );
482 
483  for( unsigned int j = 0; j < segments; j++ )
484  {
485  nx = xc + cos( startAngle + (j + 1) * deltaAngle ) * radius;
486  ny = yc - sin( startAngle + (j + 1) * deltaAngle ) * radius;
487  newPoly->AppendCorner( KiROUND( nx ), KiROUND( ny ) );
488  }
489  }
490 
491  newPoly->CloseLastContour();
492  }
493 
494  return newPoly;
495 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
void Copy(const CPolyLine *src)
Definition: PolyLine.cpp:929
void Start(LAYER_NUM layer, int x, int y, int hatch)
Definition: PolyLine.cpp:186
enum HATCH_STYLE GetHatchStyle() const
Definition: PolyLine.h:399
void AppendCorner(int x, int y)
Definition: PolyLine.cpp:199
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
int RemoveNullSegments()
Function RemoveNullSegments Removes corners which create a null segment edge (i.e.
Definition: PolyLine.cpp:77
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
LAYER_NUM GetLayer() const
Definition: PolyLine.h:337
void CloseLastContour()
function CloseLastContour Set the .end_contour member of the last corner of the last contour to true ...
Definition: PolyLine.h:254
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
const EDA_RECT CPolyLine::GetBoundingBox ( )
Returns
the full bounding box of polygons

Definition at line 551 of file PolyLine.cpp.

References CPOLYGONS_LIST::GetCornersCount(), m_CornersList, max, min, EDA_RECT::SetEnd(), and EDA_RECT::SetOrigin().

Referenced by BOARD::CombineAllAreasInNet(), ZONE_CONTAINER::HitTest(), IsPolygonSelfIntersecting(), and BOARD::TestAreaIntersection().

552 {
553  int xmin = INT_MAX;
554  int ymin = INT_MAX;
555  int xmax = INT_MIN;
556  int ymax = INT_MIN;
557 
558  for( unsigned i = 0; i< m_CornersList.GetCornersCount(); i++ )
559  {
560  xmin = std::min( xmin, m_CornersList[i].x );
561  xmax = std::max( xmax, m_CornersList[i].x );
562  ymin = std::min( ymin, m_CornersList[i].y );
563  ymax = std::max( ymax, m_CornersList[i].y );
564  }
565 
566  EDA_RECT r;
567  r.SetOrigin( wxPoint( xmin, ymin ) );
568  r.SetEnd( wxPoint( xmax, ymax ) );
569 
570  return r;
571 }
void SetOrigin(const wxPoint &pos)
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
void SetEnd(int x, int y)
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
#define min(a, b)
Definition: auxiliary.h:85
const EDA_RECT CPolyLine::GetBoundingBox ( int  icont)
Returns
the bounding box of a given polygon
Parameters
icont= the index of the polygon contour (0 = main contour, 1 ... n = other contours, usually holes)

Definition at line 574 of file PolyLine.cpp.

References GetContourEnd(), GetContourStart(), m_CornersList, max, min, EDA_RECT::SetEnd(), and EDA_RECT::SetOrigin().

575 {
576  int xmin = INT_MAX;
577  int ymin = INT_MAX;
578  int xmax = INT_MIN;
579  int ymax = INT_MIN;
580  int istart = GetContourStart( icont );
581  int iend = GetContourEnd( icont );
582 
583  for( int i = istart; i<=iend; i++ )
584  {
585  xmin = std::min( xmin, m_CornersList[i].x );
586  xmax = std::max( xmax, m_CornersList[i].x );
587  ymin = std::min( ymin, m_CornersList[i].y );
588  ymax = std::max( ymax, m_CornersList[i].y );
589  }
590 
591  EDA_RECT r;
592  r.SetOrigin( wxPoint( xmin, ymin ) );
593  r.SetEnd( wxPoint( xmax, ymax ) );
594 
595  return r;
596 }
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
void SetOrigin(const wxPoint &pos)
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
void SetEnd(int x, int y)
#define max(a, b)
Definition: auxiliary.h:86
Class EDA_RECT handles the component boundary box.
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
#define min(a, b)
Definition: auxiliary.h:85
bool CPolyLine::GetClosed ( )
Returns
true if the last corner in corners list is flagged end_contour

Definition at line 696 of file PolyLine.cpp.

References CPOLYGONS_LIST::GetCornersCount(), and m_CornersList.

Referenced by DeleteCorner(), Hatch(), and TestPointInside().

697 {
698  if( m_CornersList.GetCornersCount() == 0 )
699  return false;
700  else
701  return m_CornersList[m_CornersList.GetCornersCount() - 1].end_contour;
702 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
int CPolyLine::GetContour ( int  ic)

Function GetContour.

Returns
the contour number containing the corner ic
Parameters
ic= the index of the corner in the corner list

Definition at line 627 of file PolyLine.cpp.

References m_CornersList.

Referenced by PCB_EDIT_FRAME::Delete_Zone_Contour(), DeleteCorner(), ZONE_CONTAINER::GetMsgPanelInfo(), ZONE_CONTAINER::GetSelectMenuText(), IsCutoutContour(), and ZONE_CONTAINER::MoveEdge().

628 {
629  int ncont = 0;
630 
631  for( int i = 0; i<ic; i++ )
632  {
633  if( m_CornersList[i].end_contour )
634  ncont++;
635  }
636 
637  return ncont;
638 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
int CPolyLine::GetContourEnd ( int  icont)

Function GetContourEnd.

Returns
the index of the last corner (in corners list) of a contour
Parameters
icont= the index of the contour

Definition at line 664 of file PolyLine.cpp.

References GetContoursCount(), CPOLYGONS_LIST::GetCornersCount(), and m_CornersList.

Referenced by Chamfer(), DeleteCorner(), Distance(), DRC::doEdgeZoneDrc(), Fillet(), GetBoundingBox(), GetContourSize(), IsPolygonSelfIntersecting(), RemoveContour(), BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines(), BOARD::TestAreaIntersection(), and TestPointInside().

665 {
666  if( icont < 0 )
667  return 0;
668 
669  if( icont == GetContoursCount() - 1 )
670  return m_CornersList.GetCornersCount() - 1;
671 
672  int ncont = 0;
673 
674  for( unsigned i = 0; i<m_CornersList.GetCornersCount(); i++ )
675  {
676  if( m_CornersList[i].end_contour )
677  {
678  if( ncont == icont )
679  return i;
680 
681  ncont++;
682  }
683  }
684 
685  wxASSERT( 0 );
686  return 0;
687 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
int CPolyLine::GetContoursCount ( ) const

Function GetContoursCount.

Returns
the number of polygons stored in list (number of corners flagged "end_contour"

Definition at line 599 of file PolyLine.cpp.

References CPOLYGONS_LIST::GetContoursCount(), and m_CornersList.

Referenced by Chamfer(), DeleteCorner(), Distance(), DRC::doEdgeZoneDrc(), Fillet(), GetContourEnd(), IsPolygonSelfIntersecting(), RemoveContour(), BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines(), BOARD::TestAreaIntersection(), and TestPointInside().

600 {
602 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:606
int CPolyLine::GetContourSize ( int  icont)

Function GetContourSize.

Returns
the corners count of a contour
Parameters
icont= the index of the contour

Definition at line 690 of file PolyLine.cpp.

References GetContourEnd(), and GetContourStart().

Referenced by DeleteCorner().

691 {
692  return GetContourEnd( icont ) - GetContourStart( icont ) + 1;
693 }
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
int CPolyLine::GetContourStart ( int  icont)

Function GetContourStart.

Returns
the index of the first corner (in corners list) of a contour
Parameters
icont= the index of the contour

Definition at line 641 of file PolyLine.cpp.

References CPOLYGONS_LIST::GetCornersCount(), and m_CornersList.

Referenced by Chamfer(), Distance(), DRC::doEdgeZoneDrc(), Fillet(), GetBoundingBox(), GetContourSize(), IsPolygonSelfIntersecting(), ZONE_CONTAINER::MoveEdge(), RemoveContour(), BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines(), BOARD::TestAreaIntersection(), and TestPointInside().

642 {
643  if( icont == 0 )
644  return 0;
645 
646  int ncont = 0;
647 
648  for( unsigned i = 0; i<m_CornersList.GetCornersCount(); i++ )
649  {
650  if( m_CornersList[i].end_contour )
651  {
652  ncont++;
653 
654  if( ncont == icont )
655  return i + 1;
656  }
657  }
658 
659  wxASSERT( 0 );
660  return 0;
661 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
static int CPolyLine::GetDefaultHatchPitchMils ( )
inlinestatic

Definition at line 397 of file PolyLine.h.

Referenced by PCAD2KICAD::PCB_POLYGON::AddToBoard(), EAGLE_PLUGIN::loadPlain(), LEGACY_PLUGIN::loadZONE_CONTAINER(), and PCB_PARSER::parseZONE_CONTAINER().

397 { return 20; } // default hatch pitch value in mils
int CPolyLine::GetHatchPitch ( ) const
inline

Definition at line 396 of file PolyLine.h.

References m_hatchPitch.

Referenced by ImportSettings(), and ZONE_CONTAINER::operator=().

396 { return m_hatchPitch; }
int m_hatchPitch
Definition: PolyLine.h:482
enum HATCH_STYLE CPolyLine::GetHatchStyle ( ) const
inline

Definition at line 399 of file PolyLine.h.

References m_hatchStyle.

Referenced by Chamfer(), Fillet(), ZONE_CONTAINER::GetHatchStyle(), ImportSettings(), and ZONE_CONTAINER::operator=().

399 { return m_hatchStyle; }
enum HATCH_STYLE m_hatchStyle
Definition: PolyLine.h:481
LAYER_NUM CPolyLine::GetLayer ( ) const
inline

Definition at line 337 of file PolyLine.h.

References m_layer.

Referenced by Chamfer(), Fillet(), Hatch(), and ImportSettings().

337 { return m_layer; }
LAYER_NUM m_layer
Definition: PolyLine.h:480
const wxPoint& CPolyLine::GetPos ( int  ic) const
inline
int CPolyLine::GetX ( int  ic) const
inline
int CPolyLine::GetY ( int  ic) const
inline
void CPolyLine::Hatch ( )

Definition at line 714 of file PolyLine.cpp.

References DIAGONAL_EDGE, DIAGONAL_FULL, FindLineSegmentIntersection(), GetClosed(), CPOLYGONS_LIST::GetCornersCount(), GetLayer(), KiROUND(), m_CornersList, m_HatchLines, m_hatchPitch, m_hatchStyle, MAXPTS, NO_HATCH, and sort_ends_by_descending_X().

Referenced by BOARD::CombineAreas(), PCB_EDIT_FRAME::duplicateZone(), InsertCorner(), ZONE_CONTAINER::Mirror(), ZONE_CONTAINER::Move(), MoveCorner(), ZONE_CONTAINER::MoveEdge(), MoveOrigin(), BOARD::NormalizeAreaPolygon(), RemoveContour(), ZONE_CONTAINER::Rotate(), SetHatch(), and POINT_EDITOR::updateItem().

715 {
716  m_HatchLines.clear();
717 
718  if( m_hatchStyle == NO_HATCH || m_hatchPitch == 0 )
719  return;
720 
721  if( !GetClosed() ) // If not closed, the poly is beeing created and not finalised. Not not hatch
722  return;
723 
724  // define range for hatch lines
725  int min_x = m_CornersList[0].x;
726  int max_x = m_CornersList[0].x;
727  int min_y = m_CornersList[0].y;
728  int max_y = m_CornersList[0].y;
729 
730  for( unsigned ic = 1; ic < m_CornersList.GetCornersCount(); ic++ )
731  {
732  if( m_CornersList[ic].x < min_x )
733  min_x = m_CornersList[ic].x;
734 
735  if( m_CornersList[ic].x > max_x )
736  max_x = m_CornersList[ic].x;
737 
738  if( m_CornersList[ic].y < min_y )
739  min_y = m_CornersList[ic].y;
740 
741  if( m_CornersList[ic].y > max_y )
742  max_y = m_CornersList[ic].y;
743  }
744 
745  // Calculate spacing between 2 hatch lines
746  int spacing;
747 
748  if( m_hatchStyle == DIAGONAL_EDGE )
749  spacing = m_hatchPitch;
750  else
751  spacing = m_hatchPitch * 2;
752 
753  // set the "length" of hatch lines (the length on horizontal axis)
754  double hatch_line_len = m_hatchPitch;
755 
756  // To have a better look, give a slope depending on the layer
757  LAYER_NUM layer = GetLayer();
758  int slope_flag = (layer & 1) ? 1 : -1; // 1 or -1
759  double slope = 0.707106 * slope_flag; // 45 degrees slope
760  int max_a, min_a;
761 
762  if( slope_flag == 1 )
763  {
764  max_a = KiROUND( max_y - slope * min_x );
765  min_a = KiROUND( min_y - slope * max_x );
766  }
767  else
768  {
769  max_a = KiROUND( max_y - slope * max_x );
770  min_a = KiROUND( min_y - slope * min_x );
771  }
772 
773  min_a = (min_a / spacing) * spacing;
774 
775  // calculate an offset depending on layer number,
776  // for a better look of hatches on a multilayer board
777  int offset = (layer * 7) / 8;
778  min_a += offset;
779 
780  // now calculate and draw hatch lines
781  int nc = m_CornersList.GetCornersCount();
782 
783  // loop through hatch lines
784  #define MAXPTS 200 // Usually we store only few values per one hatch line
785  // depending on the compexity of the zone outline
786 
787  static std::vector <wxPoint> pointbuffer;
788  pointbuffer.clear();
789  pointbuffer.reserve( MAXPTS + 2 );
790 
791  for( int a = min_a; a < max_a; a += spacing )
792  {
793  // get intersection points for this hatch line
794 
795  // Note: because we should have an even number of intersections with the
796  // current hatch line and the zone outline (a closed polygon,
797  // or a set of closed polygons), if an odd count is found
798  // we skip this line (should not occur)
799  pointbuffer.clear();
800  int i_start_contour = 0;
801 
802  for( int ic = 0; ic<nc; ic++ )
803  {
804  double x, y, x2, y2;
805  int ok;
806 
807  if( m_CornersList[ic].end_contour ||
808  ( ic == (int) (m_CornersList.GetCornersCount() - 1) ) )
809  {
810  ok = FindLineSegmentIntersection( a, slope,
811  m_CornersList[ic].x, m_CornersList[ic].y,
812  m_CornersList[i_start_contour].x,
813  m_CornersList[i_start_contour].y,
814  &x, &y, &x2, &y2 );
815  i_start_contour = ic + 1;
816  }
817  else
818  {
819  ok = FindLineSegmentIntersection( a, slope,
820  m_CornersList[ic].x, m_CornersList[ic].y,
821  m_CornersList[ic + 1].x, m_CornersList[ic + 1].y,
822  &x, &y, &x2, &y2 );
823  }
824 
825  if( ok )
826  {
827  wxPoint point( KiROUND( x ), KiROUND( y ) );
828  pointbuffer.push_back( point );
829  }
830 
831  if( ok == 2 )
832  {
833  wxPoint point( KiROUND( x2 ), KiROUND( y2 ) );
834  pointbuffer.push_back( point );
835  }
836 
837  if( pointbuffer.size() >= MAXPTS ) // overflow
838  {
839  wxASSERT( 0 );
840  break;
841  }
842  }
843 
844  // ensure we have found an even intersection points count
845  // because intersections are the ends of segments
846  // inside the polygon(s) and a segment has 2 ends.
847  // if not, this is a strange case (a bug ?) so skip this hatch
848  if( pointbuffer.size() % 2 != 0 )
849  continue;
850 
851  // sort points in order of descending x (if more than 2) to
852  // ensure the starting point and the ending point of the same segment
853  // are stored one just after the other.
854  if( pointbuffer.size() > 2 )
855  sort( pointbuffer.begin(), pointbuffer.end(), sort_ends_by_descending_X );
856 
857  // creates lines or short segments inside the complex polygon
858  for( unsigned ip = 0; ip < pointbuffer.size(); ip += 2 )
859  {
860  double dx = pointbuffer[ip + 1].x - pointbuffer[ip].x;
861 
862  // Push only one line for diagonal hatch,
863  // or for small lines < twice the line len
864  // else push 2 small lines
865  if( m_hatchStyle == DIAGONAL_FULL || fabs( dx ) < 2 * hatch_line_len )
866  {
867  m_HatchLines.push_back( CSegment( pointbuffer[ip], pointbuffer[ip + 1] ) );
868  }
869  else
870  {
871  double dy = pointbuffer[ip + 1].y - pointbuffer[ip].y;
872  slope = dy / dx;
873 
874  if( dx > 0 )
875  dx = hatch_line_len;
876  else
877  dx = -hatch_line_len;
878 
879  double x1 = pointbuffer[ip].x + dx;
880  double x2 = pointbuffer[ip + 1].x - dx;
881  double y1 = pointbuffer[ip].y + dx * slope;
882  double y2 = pointbuffer[ip + 1].y - dx * slope;
883 
884  m_HatchLines.push_back( CSegment( pointbuffer[ip].x,
885  pointbuffer[ip].y,
886  KiROUND( x1 ), KiROUND( y1 ) ) );
887 
888  m_HatchLines.push_back( CSegment( pointbuffer[ip + 1].x,
889  pointbuffer[ip + 1].y,
890  KiROUND( x2 ), KiROUND( y2 ) ) );
891  }
892  }
893  }
894 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
std::vector< CSegment > m_HatchLines
Definition: PolyLine.h:488
enum HATCH_STYLE m_hatchStyle
Definition: PolyLine.h:481
bool sort_ends_by_descending_X(const wxPoint &ref, const wxPoint &tst)
Definition: PolyLine.cpp:708
bool FindLineSegmentIntersection(double a, double b, int xi, int yi, int xf, int yf, double *x1, double *y1, double *x2, double *y2, double *dist)
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
LAYER_NUM GetLayer() const
Definition: PolyLine.h:337
#define MAXPTS
bool GetClosed()
Definition: PolyLine.cpp:696
int m_hatchPitch
Definition: PolyLine.h:482
int CPolyLine::HitTestForCorner ( const wxPoint aPos,
int  aDistMax 
) const

Function HitTestForCorner test is the point aPos is near (< aDistMax ) a corner.

Parameters
aPos= the reference point
aDistMax= the max distance between a vertex and the corner
Returns
int = the index of corner of the, or -1 if not found.

Definition at line 1182 of file PolyLine.cpp.

References abs, delta, dist, CPOLYGONS_LIST::GetCornersCount(), CPOLYGONS_LIST::GetX(), CPOLYGONS_LIST::GetY(), m_CornersList, max, wxPoint::x, and wxPoint::y.

Referenced by ZONE_CONTAINER::HitTestForCorner().

1183 {
1184  int corner = -1; // Set to not found
1185  wxPoint delta;
1186  unsigned lim = m_CornersList.GetCornersCount();
1187 
1188  for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
1189  {
1190  delta.x = aPos.x - m_CornersList.GetX( item_pos );
1191  delta.y = aPos.y - m_CornersList.GetY( item_pos );
1192 
1193  // Calculate a distance:
1194  int dist = std::max( abs( delta.x ), abs( delta.y ) );
1195 
1196  if( dist < aDistMax ) // this corner is a candidate:
1197  {
1198  corner = item_pos;
1199  aDistMax = dist;
1200  }
1201  }
1202 
1203  return corner;
1204 }
static const int dist[10][10]
Definition: dist.cpp:57
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
#define abs(a)
Definition: auxiliary.h:84
static const int delta[8][2]
Definition: solve.cpp:112
#define max(a, b)
Definition: auxiliary.h:86
int GetY(int ic) const
Definition: PolyLine.h:128
int GetX(int ic) const
Definition: PolyLine.h:126
int CPolyLine::HitTestForEdge ( const wxPoint aPos,
int  aDistMax 
) const

Function HitTestForEdge test is the point aPos is near (< aDistMax ) a vertex.

Parameters
aPos= the reference point
aDistMax= the max distance between a vertex and the reference point
Returns
int = the index of the first corner of the vertex, or -1 if not found.

Definition at line 1140 of file PolyLine.cpp.

References dist, CPOLYGONS_LIST::GetCornersCount(), GetPointToLineSegmentDistance(), CPOLYGONS_LIST::GetX(), CPOLYGONS_LIST::GetY(), CPOLYGONS_LIST::IsEndContour(), KiROUND(), m_CornersList, wxPoint::x, and wxPoint::y.

Referenced by ZONE_CONTAINER::HitTestForEdge().

1141 {
1142  unsigned lim = m_CornersList.GetCornersCount();
1143  int corner = -1; // Set to not found
1144  unsigned first_corner_pos = 0;
1145 
1146  for( unsigned item_pos = 0; item_pos < lim; item_pos++ )
1147  {
1148  unsigned end_segm = item_pos + 1;
1149 
1150  /* the last corner of the current outline is tested
1151  * the last segment of the current outline starts at current corner, and ends
1152  * at the first corner of the outline
1153  */
1154  if( m_CornersList.IsEndContour ( item_pos ) || end_segm >= lim )
1155  {
1156  unsigned tmp = first_corner_pos;
1157  first_corner_pos = end_segm; // first_corner_pos is now the beginning of the next outline
1158  end_segm = tmp; // end_segm is the beginning of the current outline
1159  }
1160 
1161  // test the dist between segment and ref point
1163  aPos.x, aPos.y,
1164  m_CornersList.GetX( item_pos ),
1165  m_CornersList.GetY( item_pos ),
1166  m_CornersList.GetX( end_segm ),
1167  m_CornersList.GetY( end_segm ) ) );
1168 
1169  if( dist < aDistMax )
1170  {
1171  corner = item_pos;
1172  aDistMax = dist;
1173  }
1174  }
1175 
1176  return corner;
1177 }
double GetPointToLineSegmentDistance(int x, int y, int xi, int yi, int xf, int yf)
Function GetPointToLineSegmentDistance Get distance between line segment and point.
bool IsEndContour(int ic) const
Definition: PolyLine.h:131
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
static const int dist[10][10]
Definition: dist.cpp:57
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
int GetY(int ic) const
Definition: PolyLine.h:128
int GetX(int ic) const
Definition: PolyLine.h:126
void CPolyLine::ImportSettings ( const CPolyLine aPoly)

Function ImportSettings Copy settings (layer, hatch styles) from aPoly.

Parameters
aPolyis the CPolyLine to import settings

Definition at line 176 of file PolyLine.cpp.

References GetHatchPitch(), GetHatchStyle(), GetLayer(), SetHatchPitch(), SetHatchStyle(), and SetLayer().

Referenced by NormalizeAreaOutlines().

177 {
178  SetLayer( aPoly->GetLayer() );
179  SetHatchStyle( aPoly->GetHatchStyle() );
180  SetHatchPitch( aPoly->GetHatchPitch() );
181 }
void SetHatchPitch(int pitch)
Definition: PolyLine.h:424
enum HATCH_STYLE GetHatchStyle() const
Definition: PolyLine.h:399
int GetHatchPitch() const
Definition: PolyLine.h:396
LAYER_NUM GetLayer() const
Definition: PolyLine.h:337
void SetHatchStyle(enum HATCH_STYLE style)
Definition: PolyLine.h:419
void SetLayer(LAYER_NUM aLayer)
Definition: PolyLine.h:336
void CPolyLine::InsertCorner ( int  ic,
int  x,
int  y 
)

Function InsertCorner insert a new corner between two existing corners.

Parameters
ic= index for the insertion point: the corner is inserted AFTER ic
x,y= coordinates corner to insert

Definition at line 518 of file PolyLine.cpp.

References CPOLYGONS_LIST::Append(), CPOLYGONS_LIST::GetCornersCount(), Hatch(), CPOLYGONS_LIST::InsertCorner(), m_CornersList, and UnHatch().

Referenced by POINT_EDITOR::addCorner(), PCB_EDIT_FRAME::Process_Special_Functions(), and PCB_EDIT_FRAME::Start_Move_Zone_Corner().

519 {
520  UnHatch();
521 
522  if( (unsigned) (ic) >= m_CornersList.GetCornersCount() )
523  {
524  m_CornersList.Append( CPolyPt( x, y ) );
525  }
526  else
527  {
528  m_CornersList.InsertCorner(ic, CPolyPt( x, y ) );
529  }
530 
531  if( (unsigned) (ic + 1) < m_CornersList.GetCornersCount() )
532  {
533  if( m_CornersList[ic].end_contour )
534  {
535  m_CornersList[ic + 1].end_contour = true;
536  m_CornersList[ic].end_contour = false;
537  }
538  }
539 
540  Hatch();
541 }
void UnHatch()
Definition: PolyLine.cpp:545
void Hatch()
Definition: PolyLine.cpp:714
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
void Append(const CPOLYGONS_LIST &aList)
Definition: PolyLine.h:160
void InsertCorner(int aPosition, const CPolyPt &aItem)
Definition: PolyLine.h:179
bool CPolyLine::IsCutoutContour ( int  aCornerIdx)
Returns
true if the corner aCornerIdx is on a hole inside the main outline and false if it is on the main outline

Definition at line 945 of file PolyLine.cpp.

References GetContour().

Referenced by PCB_EDIT_FRAME::createPopUpMenuForZones().

946 {
947  int ncont = GetContour( aCornerIdx );
948 
949  if( ncont == 0 ) // the first contour is the main outline, not an hole
950  return false;
951 
952  return true;
953 }
int GetContour(int ic)
Function GetContour.
Definition: PolyLine.cpp:627
bool CPolyLine::IsEndContour ( int  ic) const
inline

Function IsEndContour.

Returns
true if a corner is flagged end_contour
Parameters
ic=the index (in corners list) of the corner

Definition at line 392 of file PolyLine.h.

References CPOLYGONS_LIST::IsEndContour(), and m_CornersList.

Referenced by KIGFX::PCB_PAINTER::draw(), and EDIT_POINTS_FACTORY::Make().

392 { return m_CornersList.IsEndContour( ic ); }
bool IsEndContour(int ic) const
Definition: PolyLine.h:131
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
bool CPolyLine::IsPolygonSelfIntersecting ( )

Function IsPolygonSelfIntersecting Test a CPolyLine for self-intersection of vertex (all contours).

Returns
: false if no intersecting sides true if intersecting sides When a CPolyLine is self intersectic, it need to be normalized. (converted to non intersecting polygons)

Definition at line 1217 of file PolyLine.cpp.

References FindSegmentIntersections(), GetBoundingBox(), GetContourEnd(), GetContoursCount(), GetContourStart(), GetX(), and GetY().

Referenced by BOARD::NormalizeAreaPolygon().

1218 {
1219  // first, check for sides intersecting other sides
1220  int n_cont = GetContoursCount();
1221 
1222  // make bounding rect for each contour
1223  std::vector<EDA_RECT> cr;
1224  cr.reserve( n_cont );
1225 
1226  for( int icont = 0; icont<n_cont; icont++ )
1227  cr.push_back( GetBoundingBox( icont ) );
1228 
1229  for( int icont = 0; icont<n_cont; icont++ )
1230  {
1231  int is_start = GetContourStart( icont );
1232  int is_end = GetContourEnd( icont );
1233 
1234  for( int is = is_start; is<=is_end; is++ )
1235  {
1236  int is_prev = is - 1;
1237 
1238  if( is_prev < is_start )
1239  is_prev = is_end;
1240 
1241  int is_next = is + 1;
1242 
1243  if( is_next > is_end )
1244  is_next = is_start;
1245 
1246  int x1i = GetX( is );
1247  int y1i = GetY( is );
1248  int x1f = GetX( is_next );
1249  int y1f = GetY( is_next );
1250 
1251  // check for intersection with any other sides
1252  for( int icont2 = icont; icont2 < n_cont; icont2++ )
1253  {
1254  if( !cr[icont].Intersects( cr[icont2] ) )
1255  {
1256  // rectangles don't overlap, do nothing
1257  }
1258  else
1259  {
1260  int is2_start = GetContourStart( icont2 );
1261  int is2_end = GetContourEnd( icont2 );
1262 
1263  for( int is2 = is2_start; is2<=is2_end; is2++ )
1264  {
1265  int is2_prev = is2 - 1;
1266 
1267  if( is2_prev < is2_start )
1268  is2_prev = is2_end;
1269 
1270  int is2_next = is2 + 1;
1271 
1272  if( is2_next > is2_end )
1273  is2_next = is2_start;
1274 
1275  if( icont != icont2
1276  || ( is2 != is && is2 != is_prev && is2 != is_next &&
1277  is != is2_prev && is != is2_next )
1278  )
1279  {
1280  int x2i = GetX( is2 );
1281  int y2i = GetY( is2 );
1282  int x2f = GetX( is2_next );
1283  int y2f = GetY( is2_next );
1284  int ret = FindSegmentIntersections( x1i, y1i, x1f, y1f,
1285  x2i, y2i, x2f, y2f );
1286  if( ret )
1287  {
1288  // intersection between non-adjacent sides
1289  return true;
1290  }
1291  }
1292  }
1293  }
1294  }
1295  }
1296  }
1297 
1298  return false;
1299 }
const EDA_RECT GetBoundingBox()
Definition: PolyLine.cpp:551
int GetY(int ic) const
Definition: PolyLine.h:385
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
int GetX(int ic) const
Definition: PolyLine.h:384
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
bool FindSegmentIntersections(int xi, int yi, int xf, int yf, int xi2, int yi2, int xf2, int yf2)
void CPolyLine::MoveCorner ( int  ic,
int  x,
int  y 
)

Definition at line 211 of file PolyLine.cpp.

References Hatch(), m_CornersList, and UnHatch().

Referenced by Abort_Zone_Move_Corner_Or_Outlines(), and Show_Zone_Corner_Or_Outline_While_Move_Mouse().

212 {
213  UnHatch();
214  m_CornersList[ic].x = x;
215  m_CornersList[ic].y = y;
216  Hatch();
217 }
void UnHatch()
Definition: PolyLine.cpp:545
void Hatch()
Definition: PolyLine.cpp:714
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
void CPolyLine::MoveOrigin ( int  x_off,
int  y_off 
)

Definition at line 956 of file PolyLine.cpp.

References GetCornersCount(), GetX(), GetY(), Hatch(), SetX(), SetY(), and UnHatch().

957 {
958  UnHatch();
959 
960  for( int ic = 0; ic < GetCornersCount(); ic++ )
961  {
962  SetX( ic, GetX( ic ) + x_off );
963  SetY( ic, GetY( ic ) + y_off );
964  }
965 
966  Hatch();
967 }
void UnHatch()
Definition: PolyLine.cpp:545
int GetY(int ic) const
Definition: PolyLine.h:385
void SetX(int ic, int x)
Definition: PolyLine.h:409
void Hatch()
Definition: PolyLine.cpp:714
void SetY(int ic, int y)
Definition: PolyLine.h:414
int GetX(int ic) const
Definition: PolyLine.h:384
int GetCornersCount() const
Definition: PolyLine.h:339
int CPolyLine::NormalizeAreaOutlines ( std::vector< CPolyLine * > *  aNewPolygonList)

Function NormalizeAreaOutlines Convert a self-intersecting polygon to one (or more) non self-intersecting polygon(s) Removes null segments.

Parameters
aNewPolygonList= a std::vector<CPolyLine*> reference where to store new CPolyLine needed by the normalization
Returns
the polygon count (always >= 1, because there is at least one polygon) There are new polygons only if the polygon count is > 1

Definition at line 117 of file PolyLine.cpp.

References SHAPE_POLY_SET::AddOutline(), SHAPE_POLY_SET::BooleanSubtract(), ConvertPolyListToPolySet(), ConvertPolySetToPolyList(), SHAPE_POLY_SET::CPolygon(), CPolyLine(), ImportSettings(), m_CornersList, SHAPE_POLY_SET::NewOutline(), SHAPE_POLY_SET::OutlineCount(), SHAPE_POLY_SET::PM_FAST, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE, SHAPE_POLY_SET::Polygon(), RemoveAllContours(), RemoveNullSegments(), and SHAPE_POLY_SET::Simplify().

Referenced by BOARD::NormalizeAreaPolygon().

118 {
120 
121  // We are expecting only one main outline, but this main outline can have holes
122  // if holes: combine holes and remove them from the main outline.
123  // Note also we are using SHAPE_POLY_SET::PM_STRICTLY_SIMPLE in polygon
124  // calculations, but it is not mandatory. It is used mainly
125  // because there is usually only very few vertices in area outlines
126  SHAPE_POLY_SET::POLYGON& outline = polySet.Polygon( 0 );
127  SHAPE_POLY_SET holesBuffer;
128 
129  // Move holes stored in outline to holesBuffer:
130  // The first SHAPE_LINE_CHAIN is the main outline, others are holes
131  while( outline.size() > 1 )
132  {
133  holesBuffer.AddOutline( outline.back() );
134  outline.pop_back();
135  }
136 
138 
139  // If any hole, substract it to main outline
140  if( holesBuffer.OutlineCount() )
141  {
142  holesBuffer.Simplify( SHAPE_POLY_SET::PM_FAST);
143  polySet.BooleanSubtract( holesBuffer, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
144  }
145 
147 
148  // Note: we can have more than outline, because a self intersecting outline will be
149  // broken to non intersecting polygons, and removing holes can also create a few polygons
150  for( int ii = 0; ii < polySet.OutlineCount(); ii++ )
151  {
152  CPolyLine* polyline = this;
153 
154  if( ii > 0 )
155  {
156  polyline = new CPolyLine;
157  polyline->ImportSettings( this );
158  aNewPolygonList->push_back( polyline );
159  }
160 
161  SHAPE_POLY_SET pnew;
162  pnew.NewOutline();
163  pnew.Polygon( 0 ) = polySet.CPolygon( ii );
164 
165  polyline->m_CornersList = ConvertPolySetToPolyList( pnew );
166  polyline->RemoveNullSegments();
167  }
168 
169  return polySet.OutlineCount();
170 }
std::vector< SHAPE_LINE_CHAIN > POLYGON
represents a single polygon outline with holes.
const CPOLYGONS_LIST ConvertPolySetToPolyList(const SHAPE_POLY_SET &aPolyset)
Definition: PolyLine.cpp:1347
void RemoveAllContours(void)
function RemoveAllContours removes all corners from the list.
Definition: PolyLine.cpp:499
const SHAPE_POLY_SET ConvertPolyListToPolySet(const CPOLYGONS_LIST &aList)
Definition: PolyLine.cpp:1301
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
int OutlineCount() const
Returns the number of outlines in the set
int RemoveNullSegments()
Function RemoveNullSegments Removes corners which create a null segment edge (i.e.
Definition: PolyLine.cpp:77
Class SHAPE_POLY_SET.
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
int NewOutline()
Creates a new empty polygon in the set and returns its index
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index
const POLYGON & CPolygon(int aIndex) const
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
void ImportSettings(const CPolyLine *aPoly)
Function ImportSettings Copy settings (layer, hatch styles) from aPoly.
Definition: PolyLine.cpp:176
void CPolyLine::RemoveAllContours ( void  )

function RemoveAllContours removes all corners from the list.

Others params are not changed

Definition at line 499 of file PolyLine.cpp.

References m_CornersList, and CPOLYGONS_LIST::RemoveAllContours().

Referenced by NormalizeAreaOutlines(), ZONE_CONTAINER::operator=(), and ZONE_CONTAINER::RemoveAllContours().

507 {
509 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
void RemoveAllContours(void)
Definition: PolyLine.h:143
void CPolyLine::RemoveContour ( int  icont)

Function RemoveContour.

Parameters
icont= contour number to remove remove a contour only if there is more than 1 contour

Definition at line 252 of file PolyLine.cpp.

References CPOLYGONS_LIST::DeleteCorner(), GetContourEnd(), GetContoursCount(), GetContourStart(), Hatch(), m_CornersList, and UnHatch().

Referenced by PCB_EDIT_FRAME::Delete_Zone_Contour(), and DeleteCorner().

260 {
261  UnHatch();
262  int istart = GetContourStart( icont );
263  int iend = GetContourEnd( icont );
264 
265  int polycount = GetContoursCount();
266 
267  if( icont == 0 && polycount == 1 )
268  {
269  // remove the only contour
270  wxASSERT( 0 );
271  }
272  else
273  {
274  // remove closed contour
275  for( int ic = iend; ic>=istart; ic-- )
276  {
278  }
279  }
280 
281  Hatch();
282 }
void UnHatch()
Definition: PolyLine.cpp:545
void Hatch()
Definition: PolyLine.cpp:714
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
void DeleteCorner(int aIdx)
Definition: PolyLine.h:148
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
int CPolyLine::RemoveNullSegments ( )

Function RemoveNullSegments Removes corners which create a null segment edge (i.e.

when 2 successive corners are at the same location)

Returns
the count of removed corners.

Definition at line 77 of file PolyLine.cpp.

References DeleteCorner(), CPOLYGONS_LIST::GetCornersCount(), and m_CornersList.

Referenced by Chamfer(), PCB_EDIT_FRAME::End_Zone(), Fillet(), and NormalizeAreaOutlines().

78 {
79  int removed = 0;
80  unsigned startcountour = 0;
81 
82  for( unsigned icnt = 1; icnt < m_CornersList.GetCornersCount(); icnt ++ )
83  {
84  unsigned last = icnt-1;
85  if( m_CornersList[icnt].end_contour )
86  {
87  last = startcountour;
88  startcountour = icnt+1;
89  }
90 
91  if( ( m_CornersList[last].x == m_CornersList[icnt].x ) &&
92  ( m_CornersList[last].y == m_CornersList[icnt].y ) )
93  {
94  DeleteCorner( icnt );
95  icnt--;
96  removed ++;
97  }
98 
99  if( m_CornersList[icnt].end_contour )
100  {
101  startcountour = icnt+1;
102  icnt++;
103  }
104  }
105 
106  return removed;
107 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
unsigned GetCornersCount() const
Definition: PolyLine.h:146
void DeleteCorner(int ic)
Function DeleteCorner remove the given corner.
Definition: PolyLine.cpp:222
void CPolyLine::SetHatch ( int  aHatchStyle,
int  aHatchPitch,
bool  aRebuildHatch 
)
inline

Definition at line 400 of file PolyLine.h.

References Hatch(), m_hatchStyle, and SetHatchPitch().

Referenced by PCAD2KICAD::PCB_POLYGON::AddToBoard(), ZONE_SETTINGS::ExportSetting(), EAGLE_PLUGIN::loadPlain(), and EAGLE_PLUGIN::loadSignals().

401  {
402  SetHatchPitch( aHatchPitch );
403  m_hatchStyle = (enum HATCH_STYLE) aHatchStyle;
404 
405  if( aRebuildHatch )
406  Hatch();
407  }
void SetHatchPitch(int pitch)
Definition: PolyLine.h:424
void Hatch()
Definition: PolyLine.cpp:714
enum HATCH_STYLE m_hatchStyle
Definition: PolyLine.h:481
void CPolyLine::SetHatchPitch ( int  pitch)
inline

Definition at line 424 of file PolyLine.h.

References m_hatchPitch.

Referenced by ImportSettings(), ZONE_CONTAINER::operator=(), and SetHatch().

424 { m_hatchPitch = pitch; }
int m_hatchPitch
Definition: PolyLine.h:482
void CPolyLine::SetHatchStyle ( enum HATCH_STYLE  style)
inline

Definition at line 419 of file PolyLine.h.

References m_hatchStyle.

Referenced by ImportSettings(), EAGLE_PLUGIN::loadSignals(), ZONE_CONTAINER::operator=(), ZONE_CONTAINER::SetHatchStyle(), and Start().

420  {
421  m_hatchStyle = style;
422  }
enum HATCH_STYLE m_hatchStyle
Definition: PolyLine.h:481
void CPolyLine::SetLayer ( LAYER_NUM  aLayer)
inline

Definition at line 336 of file PolyLine.h.

References m_layer.

Referenced by ZONE_SETTINGS::ExportSetting(), and ImportSettings().

336 { m_layer = aLayer; }
LAYER_NUM m_layer
Definition: PolyLine.h:480
void CPolyLine::SetX ( int  ic,
int  x 
)
inline

Definition at line 409 of file PolyLine.h.

References m_CornersList, and CPOLYGONS_LIST::SetX().

Referenced by MoveOrigin(), ZONE_CONTAINER::Rotate(), ZONE_CONTAINER::SetCornerPosition(), and POINT_EDITOR::updateItem().

410  {
411  m_CornersList.SetX( ic, x );
412  }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
void SetX(int ic, int aValue)
Definition: PolyLine.h:127
void CPolyLine::SetY ( int  ic,
int  y 
)
inline

Definition at line 414 of file PolyLine.h.

References m_CornersList, and CPOLYGONS_LIST::SetY().

Referenced by MoveOrigin(), ZONE_CONTAINER::Rotate(), ZONE_CONTAINER::SetCornerPosition(), and POINT_EDITOR::updateItem().

415  {
416  m_CornersList.SetY( ic, y );
417  }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
void SetY(int ic, int aValue)
Definition: PolyLine.h:129
void CPolyLine::Start ( LAYER_NUM  layer,
int  x,
int  y,
int  hatch 
)

Definition at line 186 of file PolyLine.cpp.

References CPOLYGONS_LIST::Append(), CPolyPt::end_contour, m_CornersList, m_layer, and SetHatchStyle().

Referenced by ZONE_CONTAINER::AddPolygon(), PCAD2KICAD::PCB_POLYGON::AddToBoard(), PCB_EDIT_FRAME::Begin_Zone(), Chamfer(), Fillet(), BOARD::InsertArea(), EAGLE_PLUGIN::loadPlain(), and EAGLE_PLUGIN::loadSignals().

187 {
188  m_layer = layer;
189  SetHatchStyle( (enum HATCH_STYLE) hatch );
190  CPolyPt poly_pt( x, y );
191  poly_pt.end_contour = false;
192 
193  m_CornersList.Append( poly_pt );
194 }
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
LAYER_NUM m_layer
Definition: PolyLine.h:480
void SetHatchStyle(enum HATCH_STYLE style)
Definition: PolyLine.h:419
void Append(const CPOLYGONS_LIST &aList)
Definition: PolyLine.h:160
bool CPolyLine::TestPointInside ( int  x,
int  y 
)

Definition at line 899 of file PolyLine.cpp.

References GetClosed(), GetContourEnd(), GetContoursCount(), GetContourStart(), m_CornersList, and TestPointInsidePolygon().

Referenced by Distance(), DRC::doEdgeZoneDrc(), ZONE_CONTAINER::HitTestInsideZone(), BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines(), and BOARD::TestAreaIntersection().

900 {
901  if( !GetClosed() )
902  {
903  wxASSERT( 0 );
904  }
905 
906  // Test all polygons.
907  // Since the first is the main outline, and other are holes,
908  // if the tested point is inside only one contour, it is inside the whole polygon
909  // (in fact inside the main outline, and outside all holes).
910  // if inside 2 contours (the main outline + an hole), it is outside the poly.
911  int polycount = GetContoursCount();
912  bool inside = false;
913 
914  for( int icont = 0; icont < polycount; icont++ )
915  {
916  int istart = GetContourStart( icont );
917  int iend = GetContourEnd( icont );
918 
919  // test point inside the current polygon
920  if( TestPointInsidePolygon( m_CornersList, istart, iend, px, py ) )
921  inside = not inside;
922  }
923 
924  return inside;
925 }
int GetContourEnd(int icont)
Function GetContourEnd.
Definition: PolyLine.cpp:664
CPOLYGONS_LIST m_CornersList
Definition: PolyLine.h:487
bool TestPointInsidePolygon(const CPOLYGONS_LIST &aPolysList, int aIdxstart, int aIdxend, int aRefx, int aRefy)
Function TestPointInsidePolygon test if a point is inside or outside a polygon.
int GetContoursCount() const
Function GetContoursCount.
Definition: PolyLine.cpp:599
bool GetClosed()
Definition: PolyLine.cpp:696
int GetContourStart(int icont)
Function GetContourStart.
Definition: PolyLine.cpp:641
void CPolyLine::UnHatch ( )

Definition at line 545 of file PolyLine.cpp.

References m_HatchLines.

Referenced by AppendCorner(), Copy(), DeleteCorner(), InsertCorner(), MoveCorner(), MoveOrigin(), BOARD::NormalizeAreaPolygon(), RemoveContour(), and ~CPolyLine().

546 {
547  m_HatchLines.clear();
548 }
std::vector< CSegment > m_HatchLines
Definition: PolyLine.h:488

Member Data Documentation

int CPolyLine::m_flags
private

Definition at line 485 of file PolyLine.h.

Referenced by Copy(), and CPolyLine().

int CPolyLine::m_hatchPitch
private

Definition at line 482 of file PolyLine.h.

Referenced by Copy(), CPolyLine(), GetHatchPitch(), Hatch(), and SetHatchPitch().

enum HATCH_STYLE CPolyLine::m_hatchStyle
private

Definition at line 481 of file PolyLine.h.

Referenced by Copy(), CPolyLine(), GetHatchStyle(), Hatch(), SetHatch(), and SetHatchStyle().

LAYER_NUM CPolyLine::m_layer
private

Definition at line 480 of file PolyLine.h.

Referenced by Copy(), CPolyLine(), GetLayer(), SetLayer(), and Start().


The documentation for this class was generated from the following files: