46std::shared_ptr<PNS_LOG_VIEWER_OVERLAY>
overlay;
50 int aClearance,
int* aDistance =
nullptr,
VECTOR2I* aPt1 =
nullptr )
56 int dist = std::numeric_limits<int>::max();
89 int* aDistance =
nullptr,
VECTOR2I* aPt1 =
nullptr )
93 int tmp = std::numeric_limits<int>::max();
114 for(
int j = 0; j < aLhs.
HoleCount( i ); i++ )
116 if(
collide( aLhs.
CHole( i, j ), aRhs, aClearance, &tmp, &pt1 ) )
142 std::vector<VECTOR2I> ips;
147 minDistSeg.
A = minDistSeg.
B = ips[0];
152 std::vector<VECTOR2I> ptsA;
153 std::vector<VECTOR2I> ptsB;
155 bool cocentered = ( mediatrix.
A == mediatrix.
B );
165 ptsA.push_back( a1.
GetP0() );
166 ptsA.push_back( a1.
GetP1() );
167 ptsB.push_back( a2.
GetP0() );
168 ptsB.push_back( a2.
GetP1() );
178 double minDist = std::numeric_limits<double>::max();
179 bool minDistFound =
false;
187 double dist = ( ptA - ptB ).EuclideanNorm() - a1.
GetWidth() / 2.0 - a2.
GetWidth() / 2.0;
189 if( dist < clearance )
191 if( !minDistFound || dist < minDist )
194 minDistSeg =
SEG( ptA, ptB );
209 Pgm().
App().SetTopWindow( frame );
214 double cx, cy, sx, sy, ca, w;
217 const ARC_DATA test_data [] =
219 {73.843527, 74.355869, 71.713528, 72.965869, -76.36664803, 0.2},
220 {71.236473, 74.704131, 73.366472, 76.094131, -76.36664803, 0.2},
221 {82.542335, 74.825975, 80.413528, 73.435869, -76.4, 0.2},
222 {76.491192, 73.839894, 78.619999, 75.23, -76.4, 0.2},
223 {89.318807, 74.810106, 87.19, 73.42, -76.4, 0.2},
224 {87.045667, 74.632941, 88.826472, 75.794131, -267.9, 0.2},
225 {94.665667, 73.772941, 96.446472, 74.934131, -267.9, 0.2},
226 {94.750009, 73.74012, 93.6551, 73.025482, -255.5, 0.2},
227 {72.915251, 80.493054, 73.570159, 81.257692, -260.5, 0.2},
228 {73.063537, 82.295989, 71.968628, 81.581351, -255.5, 0.2},
229 {79.279991, 80.67988, 80.3749, 81.394518, -255.5, 0.2},
230 {79.279991, 80.67988, 80.3749, 81.694518, -255.5, 0.2 },
231 {88.495265, 81.766089, 90.090174, 82.867869, -255.5, 0.2},
232 {86.995265, 81.387966, 89.090174, 82.876887, -255.5, 0.2},
233 {96.149734, 81.792126, 94.99, 83.37, -347.2, 0.2},
234 {94.857156, 81.240589, 95.91, 83.9, -288.5, 0.2},
235 {72.915251, 86.493054, 73.970159, 87.257692, -260.5, 0.2},
236 {73.063537, 88.295989, 71.968628, 87.581351, -255.5, 0.2},
237 {78.915251, 86.393054, 79.970159, 87.157692, 99.5, 0.2},
238 {79.063537, 88.295989, 77.968628, 87.581351, -255.5, 0.2},
239 {85.915251, 86.993054, 86.970159, 87.757692, 99.5, 0.2},
240 {86.063537, 88.295989, 84.968628, 87.581351, -255.5, 0.2},
241 {94.6551, 88.295989, 95.6551, 88.295989, 90.0, 0.2 },
242 {94.6551, 88.295989, 95.8551, 88.295989, 90.0, 0.2 },
243 {73.77532, 93.413654, 75.70532, 93.883054, 60.0, 0.1 },
244 {73.86532, 93.393054, 75.86532, 93.393054, 90.0, 0.3 },
245 {79.87532, 93.413654, 81.64532, 94.113054, 60.0, 0.1 },
246 {79.87532, 93.413654, 81.86532, 93.393054, 90.0, 0.3 }
254 overlay->SetLineWidth( 10000 );
256 std::vector<SHAPE_ARC> arcs;
257 int n_arcs =
sizeof( test_data ) /
sizeof( ARC_DATA );
261 for(
int i = 0; i < n_arcs; i++ )
263 const ARC_DATA& d = test_data[i];
269 arcs.push_back( arc );
320 printf(
"Read %zu arcs\n", arcs.size() );
325 for(
int i = 0; i < arcs.size(); i+= 2 )
328 std::vector<VECTOR2I> ips;
329 bool collides =
collideArc2Arc( arcs[i], arcs[i+1], 0, closestDist );
330 int ni = arcs[i].Intersect( arcs[i+1], &ips );
332 overlay->SetLineWidth( 10000.0 );
335 for(
int j = 0; j < ni; j++ )
336 overlay->AnnotatedPoint( ips[j], arcs[i].GetWidth() );
341 overlay->Line( closestDist.
A, closestDist.
B );
342 overlay->SetLineWidth( 10000 );
343 overlay->SetGlyphSize( { 100000, 100000 } );
344 overlay->BitmapText( wxString::Format(
"dist=%d", closestDist.
Length() ),
345 closestDist.
A +
VECTOR2I( 0, -arcs[i].GetWidth() ),
349 overlay->SetLineWidth( 10000 );
351 overlay->AnnotatedPoint( arcs[i].GetP0(), arcs[i].GetWidth() / 2 );
352 overlay->AnnotatedPoint( arcs[i + 1].GetP0(), arcs[i + 1].GetWidth() / 2 );
353 overlay->AnnotatedPoint( arcs[i].GetArcMid(), arcs[i].GetWidth() / 2 );
354 overlay->AnnotatedPoint( arcs[i + 1].GetArcMid(), arcs[i + 1].GetWidth() / 2 );
355 overlay->AnnotatedPoint( arcs[i].GetP1(), arcs[i].GetWidth() / 2 );
356 overlay->AnnotatedPoint( arcs[i + 1].GetP1(), arcs[i + 1].GetWidth() / 2 );
367 overlay->AnnotatedPolyset( pad1Outline,
"Raw Pads" );
369 overlay->AnnotatedPolyset( pad2Outline );
371 overlay->AnnotatedPolyset( xorPad1ToPad2,
"XOR Pads" );
372 overlay->AnnotatedPolyset( andPad1ToPad2,
"AND Pads" );
379 int dist = std::numeric_limits<int>::max();
381 collide( pad1Outline, pad2Outline.
Outline( 0 ), dist, &dist, &pt1 );
383 wxLogDebug(
tracePnsPlayground, wxS(
"Nearest distance between pad 1 and pad 2 is %0.6f mm "
384 "at X=%0.6f mm, Y=%0.6f mm." ),
389 overlay->SetGlyphSize( { 100000, 100000 } );
403 VECTOR2I( 197822958, 136722959 ), 250000 );
414 Pgm().
App().SetTopWindow( frame );
428 overlay->SetLineWidth( 80000.0 );
431 for(
int i = 0; i < lc.PointCount(); ++i )
433 int mult = ( i % 2 ) ? 1 : -1;
435 overlay->SetGlyphSize( { 800000, 800000 } );
436 overlay->BitmapText( wxString::Format(
"x=%d, y=%d",
438 lc.GetPoint( i ).y ),
446 vp.
Merge( lc.BBox() );
458 "Geometry/drawing playground",
constexpr EDA_IU_SCALE pcbIUScale
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
constexpr const Vec & GetOrigin() const
constexpr const SizeVec & GetSize() const
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.
int Intersect(const CIRCLE &aArc, std::vector< VECTOR2I > *aIpsBuffer) const
Find intersection points between this arc and a CIRCLE.
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,...
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
static const wxChar tracePnsPlayground[]
Flag to enable PNS playground debugging output.
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
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D