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 <drc.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.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 WHEN_OUTSIDE   return true
 
#define WHEN_INSIDE
 

Functions

bool poly2polyDRC (wxPoint *aTref, int aTrefCount, wxPoint *aTcompare, int aTcompareCount, int aDist)
 DRC control: these functions make a DRC between pads, tracks and pads versus tracks. More...
 
bool poly2segmentDRC (wxPoint *aTref, int aTrefCount, wxPoint aSegStart, wxPoint aSegEnd, int aDist)
 
bool convex2pointDRC (wxPoint *aTref, int aTrefCount, wxPoint aPcompare, int aDist)
 
static int USCALE (unsigned arg, unsigned num, unsigned den)
 

Macro Definition Documentation

#define WHEN_INSIDE

Referenced by DRC::checkLine().

#define WHEN_OUTSIDE   return true

Referenced by DRC::checkLine().

Function Documentation

bool convex2pointDRC ( wxPoint aTref,
int  aTrefCount,
wxPoint  aPcompare,
int  aDist 
)

Definition at line 117 of file drc_clearance_test_functions.cpp.

References TestPointInsidePolygon(), and TestSegmentHit().

118 {
119  /* Test if aPcompare point is contained in the polygon.
120  * This case is not covered by the following check if this point is inside the polygon
121  */
122  if( TestPointInsidePolygon( aTref, aTrefCount, aPcompare ) )
123  {
124  return false;
125  }
126 
127  // Test distance between aPcompare and each segment of the polygon:
128  for( int ii = 0, jj = aTrefCount - 1; ii < aTrefCount; jj = ii, ii++ ) // for all edge in polygon
129  {
130  if( TestSegmentHit( aPcompare, aTref[ii], aTref[jj], aDist ) )
131  return false;
132  }
133 
134  return true;
135 }
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.
bool TestSegmentHit(const wxPoint &aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist)
Function TestSegmentHit test for hit on line segment i.e.
Definition: trigo.cpp:122
bool poly2polyDRC ( wxPoint aTref,
int  aTrefCount,
wxPoint aTcompare,
int  aTcompareCount,
int  aDist 
)

DRC control: these functions make a DRC between pads, tracks and pads versus tracks.

Definition at line 56 of file drc_clearance_test_functions.cpp.

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

Referenced by DRC::checkClearancePadToPad().

58 {
59  /* Test if one polygon is contained in the other and thus the polygon overlap.
60  * This case is not covered by the following check if one polygone is
61  * completely contained in the other (because edges don't intersect)!
62  */
63  if( TestPointInsidePolygon( aTref, aTrefCount, aTcompare[0] ) )
64  return false;
65 
66  if( TestPointInsidePolygon( aTcompare, aTcompareCount, aTref[0] ) )
67  return false;
68 
69  for( int ii = 0, jj = aTrefCount - 1; ii < aTrefCount; jj = ii, ii++ )
70  { // for all edges in aTref
71  for( int kk = 0, ll = aTcompareCount - 1; kk < aTcompareCount; ll = kk, kk++ )
72  { // for all edges in aTcompare
73  double d;
75  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
76  aTcompare[kk].x, aTcompare[kk].y, aTcompare[ll].x, aTcompare[ll].y,
77  NULL, NULL, &d );
78 
79  if( intersect || ( d < aDist ) )
80  return false;
81  }
82  }
83 
84  return true;
85 }
bool TestForIntersectionOfStraightLineSegments(int x1i, int y1i, int x1f, int y1f, int x2i, int y2i, int x2f, int y2f, int *x, int *y, double *d)
Function TestForIntersectionOfStraightLineSegments Test for intersection of line segments If lines ar...
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.
static bool intersect(const SEGMENT_WITH_NORMALS &aSeg, const SFVEC2F &aStart, const SFVEC2F &aEnd)
Definition: cpolygon2d.cpp:293
bool poly2segmentDRC ( wxPoint aTref,
int  aTrefCount,
wxPoint  aSegStart,
wxPoint  aSegEnd,
int  aDist 
)

Definition at line 89 of file drc_clearance_test_functions.cpp.

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

Referenced by DRC::checkClearanceSegmToPad().

90 {
91  /* Test if the segment is contained in the polygon.
92  * This case is not covered by the following check if the segment is
93  * completely contained in the polygon (because edges don't intersect)!
94  */
95  if( TestPointInsidePolygon( aTref, aTrefCount, aSegStart ) )
96  return false;
97 
98  for( int ii = 0, jj = aTrefCount-1; ii < aTrefCount; jj = ii, ii++ )
99  { // for all edges in polygon
100  double d;
102  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
103  aSegStart.x, aSegStart.y, aSegEnd.x, aSegEnd.y,
104  NULL, NULL, &d );
105 
106  if( intersect || ( d < aDist) )
107  return false;
108  }
109 
110  return true;
111 }
bool TestForIntersectionOfStraightLineSegments(int x1i, int y1i, int x1f, int y1f, int x2i, int y2i, int x2f, int y2f, int *x, int *y, double *d)
Function TestForIntersectionOfStraightLineSegments Test for intersection of line segments If lines ar...
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.
static bool intersect(const SEGMENT_WITH_NORMALS &aSeg, const SFVEC2F &aStart, const SFVEC2F &aEnd)
Definition: cpolygon2d.cpp:293
static int USCALE ( unsigned  arg,
unsigned  num,
unsigned  den 
)
inlinestatic

Definition at line 1369 of file drc_clearance_test_functions.cpp.

References KiROUND().

Referenced by DRC::checkLine().

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