KiCad PCB EDA Suite
drc_clearance_test_functions.cpp File Reference
#include <fctsys.h>
#include <pcb_edit_frame.h>
#include <trigo.h>
#include <pcbnew.h>
#include <tools/drc.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <class_drawsegment.h>
#include <class_marker_pcb.h>
#include <math_for_graphics.h>
#include <polygon_test_point_inside.h>
#include <convert_basic_shapes_to_polygon.h>
#include <board_commit.h>

Go to the source code of this file.

Macros

#define PUSH_NEW_MARKER_3(a, b, c)   push_back( m_markerFactory.NewMarker( a, b, c ) )
 
#define PUSH_NEW_MARKER_4(a, b, c, d)   push_back( m_markerFactory.NewMarker( a, b, c, d ) )
 
#define WHEN_OUTSIDE   return true
 
#define WHEN_INSIDE
 

Functions

bool poly2polyDRC (wxPoint *aTref, int aTrefCount, wxPoint *aTtest, int aTtestCount, int aDist)
 compare 2 convex polygons and return true if distance > aDist (if no error DRC) i.e if for each edge of the first polygon distance from each edge of the other polygon is >= aDist More...
 
bool poly2segmentDRC (wxPoint *aTref, int aTrefCount, wxPoint aSegStart, wxPoint aSegEnd, int aDist)
 
static int USCALE (unsigned arg, unsigned num, unsigned den)
 

Macro Definition Documentation

◆ PUSH_NEW_MARKER_3

#define PUSH_NEW_MARKER_3 (   a,
  b,
 
)    push_back( m_markerFactory.NewMarker( a, b, c ) )

Definition at line 109 of file drc_clearance_test_functions.cpp.

◆ PUSH_NEW_MARKER_4

#define PUSH_NEW_MARKER_4 (   a,
  b,
  c,
 
)    push_back( m_markerFactory.NewMarker( a, b, c, d ) )

Definition at line 110 of file drc_clearance_test_functions.cpp.

◆ WHEN_INSIDE

#define WHEN_INSIDE

◆ WHEN_OUTSIDE

#define WHEN_OUTSIDE   return true

Function Documentation

◆ poly2polyDRC()

bool poly2polyDRC ( wxPoint *  aTref,
int  aTrefCount,
wxPoint *  aTtest,
int  aTtestCount,
int  aDist 
)

compare 2 convex polygons and return true if distance > aDist (if no error DRC) i.e if for each edge of the first polygon distance from each edge of the other polygon is >= aDist

Definition at line 48 of file drc_clearance_test_functions.cpp.

49 {
50  /* Test if one polygon is contained in the other and thus the polygon overlap.
51  * This case is not covered by the following check if one polygone is
52  * completely contained in the other (because edges don't intersect)!
53  */
54  if( TestPointInsidePolygon( aTref, aTrefCount, aTtest[0] ) )
55  return false;
56 
57  if( TestPointInsidePolygon( aTtest, aTtestCount, aTref[0] ) )
58  return false;
59 
60  for( int ii = 0, jj = aTrefCount - 1; ii < aTrefCount; jj = ii, ii++ )
61  {
62  // for all edges in aTref
63  for( int kk = 0, ll = aTtestCount - 1; kk < aTtestCount; ll = kk, kk++ )
64  {
65  // for all edges in aTtest
66  double d;
68  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
69  aTtest[kk].x, aTtest[kk].y, aTtest[ll].x, aTtest[ll].y,
70  nullptr, nullptr, &d );
71 
72  if( intersect || ( d < aDist ) )
73  return false;
74  }
75  }
76 
77  return true;
78 }
bool TestPointInsidePolygon(const wxPoint *aPolysList, int aCount, const wxPoint &aRefPoint)
Function TestPointInsidePolygon (overlaid) same as previous, but mainly use wxPoint.
static bool intersect(const SEGMENT_WITH_NORMALS &aSeg, const SFVEC2F &aStart, const SFVEC2F &aEnd)
Definition: cpolygon2d.cpp:293
bool TestForIntersectionOfStraightLineSegments(int x1i, int y1i, int x1f, int y1f, int x2i, int y2i, int x2f, int y2f, int *x=NULL, int *y=NULL, double *dist=NULL)
Function TestForIntersectionOfStraightLineSegments Test for intersection of line segments If lines ar...

References intersect(), TestForIntersectionOfStraightLineSegments(), and TestPointInsidePolygon().

Referenced by DRC::checkClearancePadToPad().

◆ poly2segmentDRC()

bool poly2segmentDRC ( wxPoint *  aTref,
int  aTrefCount,
wxPoint  aSegStart,
wxPoint  aSegEnd,
int  aDist 
)

Definition at line 84 of file drc_clearance_test_functions.cpp.

85 {
86  /* Test if the segment is contained in the polygon.
87  * This case is not covered by the following check if the segment is
88  * completely contained in the polygon (because edges don't intersect)!
89  */
90  if( TestPointInsidePolygon( aTref, aTrefCount, aSegStart ) )
91  return false;
92 
93  for( int ii = 0, jj = aTrefCount-1; ii < aTrefCount; jj = ii, ii++ )
94  { // for all edges in polygon
95  double d;
97  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
98  aSegStart.x, aSegStart.y, aSegEnd.x, aSegEnd.y,
99  NULL, NULL, &d );
100 
101  if( intersect || ( d < aDist) )
102  return false;
103  }
104 
105  return true;
106 }
bool TestPointInsidePolygon(const wxPoint *aPolysList, int aCount, const wxPoint &aRefPoint)
Function TestPointInsidePolygon (overlaid) same as previous, but mainly use wxPoint.
static bool intersect(const SEGMENT_WITH_NORMALS &aSeg, const SFVEC2F &aStart, const SFVEC2F &aEnd)
Definition: cpolygon2d.cpp:293
bool TestForIntersectionOfStraightLineSegments(int x1i, int y1i, int x1f, int y1f, int x2i, int y2i, int x2f, int y2f, int *x=NULL, int *y=NULL, double *dist=NULL)
Function TestForIntersectionOfStraightLineSegments Test for intersection of line segments If lines ar...

References intersect(), TestForIntersectionOfStraightLineSegments(), and TestPointInsidePolygon().

Referenced by DRC::checkClearanceSegmToPad().

◆ USCALE()

static int USCALE ( unsigned  arg,
unsigned  num,
unsigned  den 
)
inlinestatic

Definition at line 1375 of file drc_clearance_test_functions.cpp.

1376 {
1377  int ii;
1378  double result;
1379 
1380  // Trivial check first
1381  if( !arg || !num)
1382  return 0;
1383 
1384  // If arg and num are both non-zero but den is zero, we return effective infinite
1385  if( !den )
1386  return INT_MAX;
1387 
1388  result = ( (double) arg * num ) / den;
1389 
1390  // Ensure that our result doesn't overflow into the sign bit
1391  if( result > INT_MAX )
1392  return INT_MAX;
1393 
1394  ii = KiROUND( ( (double) arg * num ) / den );
1395  return ii;
1396 }
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:114

References KiROUND().

Referenced by DRC::checkLine().