38std::shared_ptr<PNS_LOG_VIEWER_OVERLAY>
overlay;
42 int aClearance,
int* aDistance =
nullptr,
VECTOR2I* aPt1 =
nullptr )
48 int dist = std::numeric_limits<int>::max();
81 int* aDistance =
nullptr,
VECTOR2I* aPt1 =
nullptr )
85 int tmp = std::numeric_limits<int>::max();
106 for(
int j = 0; j < aLhs.
HoleCount( i ); i++ )
108 if(
collide( aLhs.
CHole( i, j ), aRhs, aClearance, &tmp, &pt1 ) )
134 std::vector<VECTOR2I> ips;
139 minDistSeg.
A = minDistSeg.
B = ips[0];
144 std::vector<VECTOR2I> ptsA;
145 std::vector<VECTOR2I> ptsB;
147 bool cocentered = ( mediatrix.
A == mediatrix.
B );
157 ptsA.push_back( a1.
GetP0() );
158 ptsA.push_back( a1.
GetP1() );
159 ptsB.push_back( a2.
GetP0() );
160 ptsB.push_back( a2.
GetP1() );
170 double minDist = std::numeric_limits<double>::max();
171 bool minDistFound =
false;
181 if( dist < clearance )
183 if( !minDistFound || dist < minDist )
186 minDistSeg =
SEG( ptA, ptB );
201 Pgm().
App().SetTopWindow( frame );
206 double cx, cy, sx, sy, ca, w;
209 const ARC_DATA test_data [] =
211 {73.843527, 74.355869, 71.713528, 72.965869, -76.36664803, 0.2},
212 {71.236473, 74.704131, 73.366472, 76.094131, -76.36664803, 0.2},
213 {82.542335, 74.825975, 80.413528, 73.435869, -76.4, 0.2},
214 {76.491192, 73.839894, 78.619999, 75.23, -76.4, 0.2},
215 {89.318807, 74.810106, 87.19, 73.42, -76.4, 0.2},
216 {87.045667, 74.632941, 88.826472, 75.794131, -267.9, 0.2},
217 {94.665667, 73.772941, 96.446472, 74.934131, -267.9, 0.2},
218 {94.750009, 73.74012, 93.6551, 73.025482, -255.5, 0.2},
219 {72.915251, 80.493054, 73.570159, 81.257692, -260.5, 0.2},
220 {73.063537, 82.295989, 71.968628, 81.581351, -255.5, 0.2},
221 {79.279991, 80.67988, 80.3749, 81.394518, -255.5, 0.2},
222 {79.279991, 80.67988, 80.3749, 81.694518, -255.5, 0.2 },
223 {88.495265, 81.766089, 90.090174, 82.867869, -255.5, 0.2},
224 {86.995265, 81.387966, 89.090174, 82.876887, -255.5, 0.2},
225 {96.149734, 81.792126, 94.99, 83.37, -347.2, 0.2},
226 {94.857156, 81.240589, 95.91, 83.9, -288.5, 0.2},
227 {72.915251, 86.493054, 73.970159, 87.257692, -260.5, 0.2},
228 {73.063537, 88.295989, 71.968628, 87.581351, -255.5, 0.2},
229 {78.915251, 86.393054, 79.970159, 87.157692, 99.5, 0.2},
230 {79.063537, 88.295989, 77.968628, 87.581351, -255.5, 0.2},
231 {85.915251, 86.993054, 86.970159, 87.757692, 99.5, 0.2},
232 {86.063537, 88.295989, 84.968628, 87.581351, -255.5, 0.2},
233 {94.6551, 88.295989, 95.6551, 88.295989, 90.0, 0.2 },
234 {94.6551, 88.295989, 95.8551, 88.295989, 90.0, 0.2 },
235 {73.77532, 93.413654, 75.70532, 93.883054, 60.0, 0.1 },
236 {73.86532, 93.393054, 75.86532, 93.393054, 90.0, 0.3 },
237 {79.87532, 93.413654, 81.64532, 94.113054, 60.0, 0.1 },
238 {79.87532, 93.413654, 81.86532, 93.393054, 90.0, 0.3 }
246 overlay->SetLineWidth( 10000 );
248 std::vector<SHAPE_ARC> arcs;
249 int n_arcs =
sizeof( test_data ) /
sizeof( ARC_DATA );
253 for(
int i = 0; i < n_arcs; i++ )
255 const ARC_DATA& d = test_data[i];
261 arcs.push_back( arc );
312 printf(
"Read %zu arcs\n", arcs.size() );
317 for(
int i = 0; i < arcs.size(); i+= 2 )
320 std::vector<VECTOR2I> ips;
321 bool collides =
collideArc2Arc( arcs[i], arcs[i+1], 0, closestDist );
322 int ni = arcs[i].Intersect( arcs[i+1], &ips );
324 overlay->SetLineWidth( 10000.0 );
327 for(
int j = 0; j < ni; j++ )
328 overlay->AnnotatedPoint( ips[j], arcs[i].GetWidth() );
333 overlay->Line( closestDist.
A, closestDist.
B );
334 overlay->SetLineWidth( 10000 );
335 overlay->SetGlyphSize( { 100000, 100000 } );
336 overlay->BitmapText( wxString::Format(
"dist=%d", closestDist.
Length() ),
337 closestDist.
A +
VECTOR2I( 0, -arcs[i].GetWidth() ),
341 overlay->SetLineWidth( 10000 );
343 overlay->AnnotatedPoint( arcs[i].GetP0(), arcs[i].GetWidth() / 2 );
344 overlay->AnnotatedPoint( arcs[i + 1].GetP0(), arcs[i + 1].GetWidth() / 2 );
345 overlay->AnnotatedPoint( arcs[i].GetArcMid(), arcs[i].GetWidth() / 2 );
346 overlay->AnnotatedPoint( arcs[i + 1].GetArcMid(), arcs[i + 1].GetWidth() / 2 );
347 overlay->AnnotatedPoint( arcs[i].GetP1(), arcs[i].GetWidth() / 2 );
348 overlay->AnnotatedPoint( arcs[i + 1].GetP1(), arcs[i + 1].GetWidth() / 2 );
359 overlay->AnnotatedPolyset( pad1Outline,
"Raw Pads" );
361 overlay->AnnotatedPolyset( pad2Outline );
363 overlay->AnnotatedPolyset( xorPad1ToPad2,
"XOR Pads" );
364 overlay->AnnotatedPolyset( andPad1ToPad2,
"AND Pads" );
366 wxLogDebug( wxS(
"Pad 1 has %d outlines." ),
369 wxLogDebug( wxS(
"Pad 2 has %d outlines." ),
373 int dist = std::numeric_limits<int>::max();
375 collide( pad1Outline, pad2Outline.
Outline( 0 ), dist, &dist, &pt1 );
377 wxLogDebug( wxS(
"Nearest distance between pad 1 and pad 2 is %0.6f mm at X=%0.6f mm, "
383 overlay->SetGlyphSize( { 100000, 100000 } );
397 VECTOR2I( 197822958, 136722959 ), 250000 );
408 Pgm().
App().SetTopWindow( frame );
422 overlay->SetLineWidth( 80000.0 );
425 for(
int i = 0; i < lc.PointCount(); ++i )
427 int mult = ( i % 2 ) ? 1 : -1;
429 overlay->SetGlyphSize( { 800000, 800000 } );
430 overlay->BitmapText( wxString::Format(
"x=%d, y=%d",
432 lc.GetPoint( i ).y ),
440 vp.
Merge( lc.BBox() );
452 "Geometry/drawing playground",
constexpr EDA_IU_SCALE pcbIUScale
const Vec & GetOrigin() const
const SizeVec & GetSize() const
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
const BOX2I GetBoundingBox() const override
The bounding box is cached, so this will be efficient most of the time.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc=ERROR_INSIDE, bool ignoreLineWidth=false) const override
Convert the pad shape to a closed polygon.
void SetDrillSizeX(const int aX)
void SetSizeX(const int aX)
void SetDrillSizeY(const int aY)
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const override
Return a SHAPE_SEGMENT object representing the pad's hole.
bool TransformHoleToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc=ERROR_INSIDE) const
Build the corner list of the polygonal drill shape in the board coordinate system.
void SetSizeY(const int aY)
virtual wxApp & App()
Returns a bare naked wxApp which may come from wxPython, SINGLE_TOP, or kicad.exe.
int Length() const
Return the length (this).
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
const VECTOR2I & GetP1() const
int IntersectLine(const SEG &aSeg, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aSeg, treating aSeg as an infinite line.
bool Collide(const SEG &aSeg, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if the boundary of shape (this) lies closer to the segment aSeg than aClearance,...
int Intersect(const SHAPE_ARC &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and aArc.
const VECTOR2I & GetP0() const
const VECTOR2I & GetCenter() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetClosed(bool aClosed)
Mark the line chain as closed (i.e.
int PointCount() const
Return the number of points (vertices) in this line chain.
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const override
Check if point aP lies closer to us than aClearance.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
int SegmentCount() const
Return the number of segments in this line chain.
const SEG CSegment(int aIndex) const
Return a constant copy of the aIndex segment in the line chain.
Represent a set of closed polygons.
void BooleanXor(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset exclusive or For aFastMode meaning, see function booleanOp.
void BooleanIntersection(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset intersection For aFastMode meaning, see function booleanOp.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Return the number of outlines in the set.
void Move(const VECTOR2I &aVector) override
static bool Register(const KI_TEST::UTILITY_PROGRAM &aProgInfo)
Register a utility program factory function against an ID string.
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
PGM_BASE & Pgm()
The global Program "get" accessor.
int playground_main_func(int argc, char *argv[])
int drawShapes(int argc, char *argv[])
static bool collide(const SHAPE_LINE_CHAIN &aLhs, const SHAPE_LINE_CHAIN &aRhs, int aClearance, int *aDistance=nullptr, VECTOR2I *aPt1=nullptr)
bool collideArc2Arc(const SHAPE_ARC &a1, const SHAPE_ARC &a2, int clearance, SEG &minDistSeg)
std::shared_ptr< PNS_LOG_VIEWER_OVERLAY > overlay
constexpr double IUTomm(int iu) const
constexpr int mmToIU(double mm) const
double EuclideanNorm(const VECTOR2I &vector)
VECTOR2< double > VECTOR2D