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/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>
#include <geometry/shape_rect.h>
#include <macros.h>

Go to the source code of this file.

Macros

#define THRESHOLD_DIST   Millimeter2iu( 0.001 )
 

Functions

bool poly2polyDRC (wxPoint *aTref, int aTrefCount, wxPoint *aTtest, int aTtestCount, int aAllowedDist, int *actualDist)
 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, int *aActual)
 

Macro Definition Documentation

◆ THRESHOLD_DIST

#define THRESHOLD_DIST   Millimeter2iu( 0.001 )

Function Documentation

◆ poly2polyDRC()

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

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

53 {
54  /* Test if one polygon is contained in the other and thus the polygon overlap.
55  * This case is not covered by the following check if one polygone is
56  * completely contained in the other (because edges don't intersect)!
57  */
58  if( TestPointInsidePolygon( aTref, aTrefCount, aTtest[0] ) )
59  {
60  *actualDist = 0;
61  return false;
62  }
63 
64  if( TestPointInsidePolygon( aTtest, aTtestCount, aTref[0] ) )
65  {
66  *actualDist = 0;
67  return false;
68  }
69 
70  for( int ii = 0, jj = aTrefCount - 1; ii < aTrefCount; jj = ii, ii++ )
71  {
72  // for all edges in aTref
73  for( int kk = 0, ll = aTtestCount - 1; kk < aTtestCount; ll = kk, kk++ )
74  {
75  // for all edges in aTtest
76  double d;
77  int intersect = TestForIntersectionOfStraightLineSegments(
78  aTref[ii].x, aTref[ii].y, aTref[jj].x, aTref[jj].y,
79  aTtest[kk].x, aTtest[kk].y, aTtest[ll].x, aTtest[ll].y,
80  nullptr, nullptr, &d );
81 
82  if( intersect )
83  {
84  *actualDist = 0;
85  return false;
86  }
87 
88  if( d < aAllowedDist )
89  {
90  *actualDist = KiROUND( d );
91  return false;
92  }
93  }
94  }
95 
96  return true;
97 }
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
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 intersect(), KiROUND(), and TestPointInsidePolygon().

Referenced by DRC::checkClearancePadToPad().

◆ poly2segmentDRC()

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

Definition at line 103 of file drc_clearance_test_functions.cpp.

105 {
106  /* Test if the segment is contained in the polygon.
107  * This case is not covered by the following check if the segment is
108  * completely contained in the polygon (because edges don't intersect)!
109  */
110  if( TestPointInsidePolygon( aTref, aTrefCount, aSegStart ) )
111  {
112  *aActual = 0;
113  return false;
114  }
115 
116  for( int ii = 0, jj = aTrefCount-1; ii < aTrefCount; jj = ii, ii++ )
117  { // for all edges in polygon
118  double d;
119 
120  if( TestForIntersectionOfStraightLineSegments( aTref[ii].x, aTref[ii].y, aTref[jj].x,
121  aTref[jj].y, aSegStart.x, aSegStart.y,
122  aSegEnd.x, aSegEnd.y, NULL, NULL, &d ) )
123  {
124  *aActual = 0;
125  return false;
126  }
127 
128  if( d < aDist )
129  {
130  *aActual = KiROUND( d );
131  return false;
132  }
133  }
134 
135  return true;
136 }
#define NULL
bool TestPointInsidePolygon(const wxPoint *aPolysList, int aCount, const wxPoint &aRefPoint)
Function TestPointInsidePolygon (overlaid) same as previous, but mainly use wxPoint.
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(), NULL, TestPointInsidePolygon(), wxPoint::x, and wxPoint::y.

Referenced by DRC::checkClearanceSegmToPad().