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 <geometry/polygon_test_point_inside.h>
#include <convert_basic_shapes_to_polygon.h>
#include <board_commit.h>
#include <math/util.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 110 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 111 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 49 of file drc_clearance_test_functions.cpp.

50 {
51  /* Test if one polygon is contained in the other and thus the polygon overlap.
52  * This case is not covered by the following check if one polygone is
53  * completely contained in the other (because edges don't intersect)!
54  */
55  if( TestPointInsidePolygon( aTref, aTrefCount, aTtest[0] ) )
56  return false;
57 
58  if( TestPointInsidePolygon( aTtest, aTtestCount, aTref[0] ) )
59  return false;
60 
61  for( int ii = 0, jj = aTrefCount - 1; ii < aTrefCount; jj = ii, ii++ )
62  {
63  // for all edges in aTref
64  for( int kk = 0, ll = aTtestCount - 1; kk < aTtestCount; ll = kk, kk++ )
65  {
66  // for all edges in aTtest
67  double d;
68  int intersect = TestForIntersectionOfStraightLineSegments(
69  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
70  aTtest[kk].x, aTtest[kk].y, aTtest[ll].x, aTtest[ll].y,
71  nullptr, nullptr, &d );
72 
73  if( intersect || ( d < aDist ) )
74  return false;
75  }
76  }
77 
78  return true;
79 }
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:291

References intersect(), and TestPointInsidePolygon().

Referenced by DRC::checkClearancePadToPad().

◆ poly2segmentDRC()

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

Definition at line 85 of file drc_clearance_test_functions.cpp.

86 {
87  /* Test if the segment is contained in the polygon.
88  * This case is not covered by the following check if the segment is
89  * completely contained in the polygon (because edges don't intersect)!
90  */
91  if( TestPointInsidePolygon( aTref, aTrefCount, aSegStart ) )
92  return false;
93 
94  for( int ii = 0, jj = aTrefCount-1; ii < aTrefCount; jj = ii, ii++ )
95  { // for all edges in polygon
96  double d;
97  int intersect = TestForIntersectionOfStraightLineSegments(
98  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
99  aSegStart.x, aSegStart.y, aSegEnd.x, aSegEnd.y,
100  NULL, NULL, &d );
101 
102  if( intersect || ( d < aDist) )
103  return false;
104  }
105 
106  return true;
107 }
#define NULL
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:291

References intersect(), NULL, TestPointInsidePolygon(), wxPoint::x, and wxPoint::y.

Referenced by DRC::checkClearanceSegmToPad().

◆ USCALE()

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

Definition at line 1376 of file drc_clearance_test_functions.cpp.

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

References KiROUND().

Referenced by DRC::checkLine().