KiCad PCB EDA Suite
drc_clearance_test_functions.cpp File Reference
#include <fctsys.h>
#include <wxPcbStruct.h>
#include <trigo.h>
#include <pcbnew.h>
#include <drc_stuff.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>

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 116 of file drc_clearance_test_functions.cpp.

References TestPointInsidePolygon(), and TestSegmentHit().

117 {
118  /* Test if aPcompare point is contained in the polygon.
119  * This case is not covered by the following check if this point is inside the polygon
120  */
121  if( TestPointInsidePolygon( aTref, aTrefCount, aPcompare ) )
122  {
123  return false;
124  }
125 
126  // Test distance between aPcompare and each segment of the polygon:
127  for( int ii = 0, jj = aTrefCount - 1; ii < aTrefCount; jj = ii, ii++ ) // for all edge in polygon
128  {
129  if( TestSegmentHit( aPcompare, aTref[ii], aTref[jj], aDist ) )
130  return false;
131  }
132 
133  return true;
134 }
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:142
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 55 of file drc_clearance_test_functions.cpp.

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

Referenced by DRC::checkClearancePadToPad().

57 {
58  /* Test if one polygon is contained in the other and thus the polygon overlap.
59  * This case is not covered by the following check if one polygone is
60  * completely contained in the other (because edges don't intersect)!
61  */
62  if( TestPointInsidePolygon( aTref, aTrefCount, aTcompare[0] ) )
63  return false;
64 
65  if( TestPointInsidePolygon( aTcompare, aTcompareCount, aTref[0] ) )
66  return false;
67 
68  for( int ii = 0, jj = aTrefCount - 1; ii < aTrefCount; jj = ii, ii++ )
69  { // for all edges in aTref
70  for( int kk = 0, ll = aTcompareCount - 1; kk < aTcompareCount; ll = kk, kk++ )
71  { // for all edges in aTcompare
72  double d;
74  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
75  aTcompare[kk].x, aTcompare[kk].y, aTcompare[ll].x, aTcompare[ll].y,
76  NULL, NULL, &d );
77 
78  if( intersect || ( d < aDist ) )
79  return false;
80  }
81  }
82 
83  return true;
84 }
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 88 of file drc_clearance_test_functions.cpp.

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

Referenced by DRC::checkClearanceSegmToPad().

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

References KiROUND().

Referenced by DRC::checkLine().

1140 {
1141  int ii;
1142 
1143  ii = KiROUND( ( (double) arg * num ) / den );
1144  return ii;
1145 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:106