54 BOOST_CHECK_EQUAL( base_chain.CShapes().size(), base_chain.CPoints().size() );
55 BOOST_CHECK_EQUAL( arc_insert1.CShapes().size(), arc_insert1.CPoints().size() );
56 BOOST_CHECK_EQUAL( arc_insert2.
CShapes().size(), arc_insert2.
CPoints().size() );
64 BOOST_CHECK_EQUAL( base_chain.CShapes().size(), base_chain.CPoints().size() );
66 base_chain.Replace( 0, 2, chain_insert );
68 BOOST_CHECK_EQUAL( base_chain.CShapes().size(), base_chain.CPoints().size() );
86 BOOST_CHECK_EQUAL( base_chain.PointCount(), 11 );
88 base_chain.Insert( 9,
VECTOR2I( 250000, 0 ) );
90 BOOST_CHECK_EQUAL( base_chain.PointCount(), 12 );
91 BOOST_CHECK_EQUAL( base_chain.ArcCount(), 2 );
93 base_chain.Replace( 5, 6, chain_insert );
95 BOOST_CHECK_EQUAL( base_chain.PointCount(), 13 );
96 BOOST_CHECK_EQUAL( base_chain.ArcCount(), 3 );
98 base_chain.Replace( 4, 6,
VECTOR2I( 550000, 0 ) );
100 BOOST_CHECK_EQUAL( base_chain.PointCount(), 11 );
101 BOOST_CHECK_EQUAL( base_chain.ArcCount(), 3 );
104 base_chain.SetClosed(
true );
105 double areaPriorToArcRemoval = base_chain.Area();
106 base_chain.ClearArcs();
109 BOOST_CHECK_EQUAL( base_chain.CPoints().size(), base_chain.CShapes().size() );
110 BOOST_CHECK_EQUAL( base_chain.PointCount(), 11 );
111 BOOST_CHECK_EQUAL( base_chain.ArcCount(), 0 );
112 BOOST_CHECK_EQUAL( base_chain.Area(), areaPriorToArcRemoval );
122 SHAPE_ARC( { -859598, 2559876 }, { -1632771, 1022403 }, { -3170244, 249230 }, 0 ) );
125 SHAPE_ARC( { -3170244, -1657832 }, { -292804, -317564 }, { 1047464, 2559876 }, 0 ) );
134 BOOST_CHECK_EQUAL( chain.
CPoints().size(), chain.
CShapes().size() );
144 chain.
Append( { 100, 100 } );
145 chain.
Append( { 100, 100 }, true );
146 chain.
Append( { 200, 100 } );
153 BOOST_CHECK_EQUAL( chain.
CPoints().size(), chain.
CShapes().size() );
175 BOOST_CHECK_EQUAL( chain.
IsSharedPt( 0 ),
false );
176 BOOST_CHECK_EQUAL( chain.
IsArcEnd( 0 ),
false );
177 BOOST_CHECK_EQUAL( chain.
IsArcStart( 0 ),
true );
180 BOOST_CHECK_EQUAL( chain.
IsSharedPt( 6 ),
true );
181 BOOST_CHECK_EQUAL( chain.
IsArcEnd( 6 ),
true );
182 BOOST_CHECK_EQUAL( chain.
IsArcStart( 6 ),
true );
186 BOOST_CHECK_EQUAL( chain.
IsSharedPt( endIndex ),
false );
187 BOOST_CHECK_EQUAL( chain.
IsArcEnd( endIndex ),
true );
188 BOOST_CHECK_EQUAL( chain.
IsArcStart( endIndex ),
false );
192 BOOST_CHECK_EQUAL( chain.
IsPtOnArc( i ),
true );
201 BOOST_CHECK_EQUAL( chain.
IsSharedPt( 0 ),
true );
202 BOOST_CHECK_EQUAL( chain.
IsArcEnd( 0 ),
true );
203 BOOST_CHECK_EQUAL( chain.
IsArcStart( 0 ),
true );
206 BOOST_CHECK_EQUAL( chain.
IsSharedPt( 6 ),
true );
207 BOOST_CHECK_EQUAL( chain.
IsArcEnd( 6 ),
true );
208 BOOST_CHECK_EQUAL( chain.
IsArcStart( 6 ),
true );
212 BOOST_CHECK_EQUAL( chain.
IsSharedPt( endIndex ),
false );
213 BOOST_CHECK_EQUAL( chain.
IsArcEnd( endIndex ),
false );
214 BOOST_CHECK_EQUAL( chain.
IsArcStart( endIndex ),
false );
226 BOOST_CHECK_EQUAL( chain.PointCount(), 2 );
229 BOOST_CHECK_EQUAL( chain.PointCount(), 9 );
231 chain.Append( seg2.
A );
232 chain.Append( seg2.
B );
233 BOOST_CHECK_EQUAL( chain.PointCount(), 11 );
239 BOOST_CHECK_EQUAL( chainCopy.
Split(
VECTOR2I( 400000, 0 ) ), -1 );
240 BOOST_CHECK_EQUAL( chainCopy.
PointCount(), chain.PointCount() );
241 BOOST_CHECK_EQUAL( chainCopy.
ArcCount(), chain.ArcCount() );
248 BOOST_CHECK_EQUAL( chainCopy.
Split( splitPoint ), 1 );
250 BOOST_CHECK_EQUAL( chainCopy.
GetPoint( 1 ), splitPoint );
251 BOOST_CHECK_EQUAL( chainCopy.
PointCount(), chain.PointCount() + 1 );
252 BOOST_CHECK_EQUAL( chainCopy.
ArcCount(), chain.ArcCount() );
259 BOOST_CHECK_EQUAL( chainCopy.
Split( splitPoint ), 1 );
261 BOOST_CHECK_EQUAL( chainCopy.
GetPoint( 1 ), splitPoint );
262 BOOST_CHECK_EQUAL( chainCopy.
PointCount(), chain.PointCount() );
263 BOOST_CHECK_EQUAL( chainCopy.
ArcCount(), chain.ArcCount() );
270 BOOST_CHECK_EQUAL( chainCopy.
Split( splitPoint ), 2 );
272 BOOST_CHECK_EQUAL( chainCopy.
GetPoint( 2 ), splitPoint );
273 BOOST_CHECK_EQUAL( chainCopy.
PointCount(), chain.PointCount() );
274 BOOST_CHECK_EQUAL( chainCopy.
ArcCount(), chain.ArcCount() );
281 BOOST_CHECK_EQUAL( chainCopy.
Split( splitPoint ), 3 );
283 BOOST_CHECK_EQUAL( chainCopy.
GetPoint( 3 ), splitPoint );
284 BOOST_CHECK_EQUAL( chainCopy.
IsSharedPt( 3 ),
true );
285 BOOST_CHECK_EQUAL( chainCopy.
PointCount(), chain.PointCount() + 1 );
286 BOOST_CHECK_EQUAL( chainCopy.
ArcCount(), chain.ArcCount() + 1 );
301 BOOST_CHECK_EQUAL( chain.PointCount(), 3 );
303 chain.Append( firstArc );
304 BOOST_CHECK_EQUAL( chain.PointCount(), 10 );
306 chain.Append( targetSegment.
A );
307 chain.Append( targetSegment.
B );
308 BOOST_CHECK_EQUAL( chain.PointCount(), 12 );
310 chain.Append( secondArc );
311 BOOST_CHECK_EQUAL( chain.PointCount(), 20 );
322 BOOST_CHECK_EQUAL( sliceResult.
ArcCount(), 1 );
324 BOOST_CHECK_EQUAL( secondArc.
GetP0(), sliceArc0.
GetP0() );
328 BOOST_CHECK_EQUAL( sliceResult.
PointCount(), 10 );
329 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 0 ), firstArc.
GetP1() );
330 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 1 ), targetSegment.
A );
331 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 2 ), targetSegment.
B );
332 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 3 ), sliceArc0.
GetP0() );
333 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( 3 ),
true );
335 for(
int i = 4; i <= 8; i++ )
336 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( i ),
false );
338 for(
int i = 3; i <= 7; i++ )
339 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( i ),
false );
341 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( 9 ),
true );
342 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 9 ), sliceArc0.
GetP1() );
353 BOOST_CHECK_EQUAL( sliceResult.
ArcCount(), 1 );
355 BOOST_CHECK_EQUAL( firstArc.
GetP1(), sliceArc0.
GetP1() );
359 BOOST_CHECK_EQUAL( sliceResult.
PointCount(), 8 );
360 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 0 ), sliceArc0.
GetP0() );
361 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( 0 ),
true );
363 for(
int i = 1; i <= 4; i++ )
364 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( i ),
false );
366 for(
int i = 0; i <= 3; i++ )
367 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( i ),
false );
369 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( 4 ),
true );
370 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 4 ), sliceArc0.
GetP1() );
372 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 5 ), targetSegment.
A );
373 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 6 ), targetSegment.
B );
374 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 7 ), secondArc.
GetP0() );
385 BOOST_CHECK_EQUAL( sliceResult.
ArcCount(), 1 );
389 BOOST_CHECK_EQUAL( firstArc.
GetP1(), sliceArc0.
GetP1() );
391 BOOST_CHECK_EQUAL( firstArc.
GetP1(), sliceArc0.
GetP1() );
393 BOOST_CHECK_EQUAL( sliceResult.
PointCount(), 7 );
394 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 0 ), sliceArc0.
GetP0() );
395 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( 0 ),
true );
397 for(
int i = 1; i <= 6; i++ )
398 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( i ),
false );
400 for(
int i = 0; i <= 5; i++ )
401 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( i ),
false );
403 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( 6 ),
true );
404 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 6 ), sliceArc0.
GetP1() );
415 BOOST_CHECK_EQUAL( sliceResult.
ArcCount(), 1 );
419 BOOST_CHECK_EQUAL( firstArc.
GetP1(), sliceArc0.
GetP1() );
421 BOOST_CHECK_EQUAL( firstArc.
GetP1(), sliceArc0.
GetP1() );
423 BOOST_CHECK_EQUAL( sliceResult.
PointCount(), 10 );
424 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 0 ), sliceArc0.
GetP0() );
425 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( 0 ),
true );
427 for(
int i = 1; i <= 6; i++ )
428 BOOST_CHECK_EQUAL( sliceResult.
IsArcStart( i ),
false );
430 for(
int i = 0; i <= 5; i++ )
431 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( i ),
false );
433 BOOST_CHECK_EQUAL( sliceResult.
IsArcEnd( 6 ),
true );
434 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 6 ), sliceArc0.
GetP1() );
436 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 7 ), targetSegment.
A );
437 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 8 ), targetSegment.
B );
438 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( 9 ), secondArc.
GetP0() );
447 BOOST_CHECK_EQUAL( sliceResult.
GetPoint( -1 ),
VECTOR2I( 400000, 400000 ) );
461 BOOST_CHECK_EQUAL( chain.PointCount(), 2 );
464 BOOST_CHECK_EQUAL( chain.PointCount(), 9 );
466 chain.Append( seg2.
A );
467 chain.Append( seg2.
B );
468 BOOST_CHECK_EQUAL( chain.PointCount(), 11 );
471 VECTOR2I ptOnArcCloseToStart( 297553, 31697 );
472 VECTOR2I ptOnArcCloseToEnd( 139709, 82983 );
474 BOOST_CHECK_EQUAL( chain.NearestPoint( ptOnArcCloseToStart,
true ), ptOnArcCloseToStart );
475 BOOST_CHECK_EQUAL( chain.NearestPoint( ptOnArcCloseToStart,
false ), arc.
GetP0() );
477 BOOST_CHECK_EQUAL( chain.NearestPoint( ptOnArcCloseToEnd,
true ), ptOnArcCloseToEnd );
478 BOOST_CHECK_EQUAL( chain.NearestPoint( ptOnArcCloseToEnd,
false ), arc.
GetP1() );
487 std::vector<VECTOR2I> linePts = {
488 { 206000000, 140110000 }, { 192325020, 140110000 }, { 192325020, 113348216 },
489 { 192251784, 113274980 }, { 175548216, 113274980 }, { 175474980, 113348216 },
490 { 175474980, 136694980 }, { 160774511, 121994511 }, { 160774511, 121693501 },
491 { 160086499, 121005489 }, { 159785489, 121005489 }, { 159594511, 120814511 },
492 { 160086499, 120814511 }, { 160774511, 120126499 }, { 160774511, 119153501 },
493 { 160086499, 118465489 }, { 159113501, 118465489 }, { 158425489, 119153501 },
494 { 158425489, 119645489 }, { 157325020, 118545020 }, { 157325020, 101925020 },
495 { 208674980, 101925020 }, { 208674980, 145474980 }, { 192325020, 145474980 },
496 { 192325020, 140110000 }
501 BOOST_CHECK_EQUAL( baseChain.
PointCount(), linePts.size() );
504 BOOST_CHECK_EQUAL( replaceChain.PointCount(), 1 );
506 baseChain.
Replace( 1, 23, replaceChain );
508 BOOST_CHECK_EQUAL( baseChain.
PointCount(), linePts.size() - ( 23 - 1 ) );
517BOOST_AUTO_TEST_SUITE_END()
const VECTOR2I & GetArcMid() const
const VECTOR2I & GetP1() const
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,...
static double DefaultAccuracyForPCB()
const VECTOR2I & GetP0() const
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsPtOnArc(size_t aPtIndex) const
const SHAPE_ARC & Arc(size_t aArc) const
SHAPE_LINE_CHAIN & Simplify(bool aRemoveColinear=true)
Simplify the line chain by removing colinear adjacent segments and duplicate vertices.
virtual const VECTOR2I GetPoint(int aIndex) const override
int Split(const VECTOR2I &aP, bool aExact=false)
Insert the point aP belonging to one of the our segments, splitting the adjacent segment in two.
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.
bool IsArcEnd(size_t aIndex) const
void Replace(int aStartIndex, int aEndIndex, const VECTOR2I &aP)
Replace points with indices in range [start_index, end_index] with a single point aP.
const SHAPE_LINE_CHAIN Slice(int aStartIndex, int aEndIndex=-1) const
Return a subset of this line chain containing the [start_index, end_index] range of points.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
const std::vector< std::pair< ssize_t, ssize_t > > & CShapes() const
const VECTOR2I & CLastPoint() const
Return the last point in the line chain.
bool IsArcStart(size_t aIndex) const
void SetWidth(int aWidth)
Set the width of all segments in the chain.
bool IsSharedPt(size_t aIndex) const
Test if a point is shared between multiple shapes.
const std::vector< VECTOR2I > & CPoints() const
static constexpr EDA_ANGLE & ANGLE_180
bool IsOutlineValid(const SHAPE_LINE_CHAIN &aChain)
Verify that a SHAPE_LINE_CHAIN has been assembled correctly by ensuring that the arc start and end po...
Numerical test predicates.
BOOST_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(ArcToPolyline)
NOTE: Collision of SHAPE_LINE_CHAIN with arcs is tested in test_shape_arc.cpp.
#define BOOST_TEST_CONTEXT(A)
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...