KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_eda_shape.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18
20
21#include <cmath>
22
23#include <base_units.h>
24#include <eda_shape.h>
25#include <math/util.h>
27#include <qa_utils/geometry/geometry.h> // For KI_TEST::IsVecWithinTol
28#include <geometry/shape_arc.h> // For SHAPE_ARC::DefaultAccuracyForPCB()
31#include <render_settings.h>
32#include <stroke_params.h>
33
34
35BOOST_AUTO_TEST_SUITE( EdaShape )
36
38{
39public:
40 EDA_SHAPE_MOCK( SHAPE_T aShapeType ) : EDA_SHAPE( aShapeType, 0, FILL_T::NO_FILL ){};
41
42 void Mirror( const SEG& aAxis ) { mirror( aAxis ); }
43
44 BOX2I BBox() const { return getBoundingBox(); }
45};
46
47
48static void checkVectorClose( const VECTOR2D& aActual, const VECTOR2D& aExpected, double aTolerance = 1e-6 )
49{
50 BOOST_CHECK_SMALL( aActual.x - aExpected.x, aTolerance );
51 BOOST_CHECK_SMALL( aActual.y - aExpected.y, aTolerance );
52}
53
54
55static void checkVectorEqual( const VECTOR2I& aActual, const VECTOR2I& aExpected )
56{
57 BOOST_CHECK_EQUAL( aActual.x, aExpected.x );
58 BOOST_CHECK_EQUAL( aActual.y, aExpected.y );
59}
60
61
62static void checkAngleClose( const EDA_ANGLE& aActual, double aExpectedDegrees, double aTolerance = 1e-6 )
63{
64 BOOST_CHECK_SMALL( aActual.AsDegrees() - aExpectedDegrees, aTolerance );
65}
66
67
68static void checkAngleInRange( const EDA_ANGLE& aActual, double aMinDegrees, double aMaxDegrees )
69{
70 BOOST_CHECK_MESSAGE( aActual.AsDegrees() > aMinDegrees && aActual.AsDegrees() < aMaxDegrees,
71 "Expected angle " << aActual.AsDegrees() << " to be between " << aMinDegrees << " and "
72 << aMaxDegrees );
73}
74
75
76static void deleteShapes( std::vector<SHAPE*>& aShapes )
77{
78 for( SHAPE* shape : aShapes )
79 delete shape;
80
81 aShapes.clear();
82}
83
84
94
95
96static const std::vector<SET_ANGLE_END_CASE> set_angle_end_cases =
97{
98 {
99 "Issue 13626: clockwise semicircle",
100 {-428880000, 117229160 },
101 {-430060565, 113472820 },
102 180.0,
103 {-431241130, 109716480 },
104 false
105 },
106 {
107 "Issue 13626: anticlockwise arc",
108 { -431241130, 109716480 },
109 { -434923630, 112954230 },
110 -138.46654568595355,
111 { -439827050, 112936200 },
112 true
113 }
114};
115
116
117BOOST_AUTO_TEST_CASE( SetAngleAndEnd )
118{
119 for( const auto& c : set_angle_end_cases )
120 {
121 BOOST_TEST_INFO_SCOPE( c.m_CaseName );
122
124 shape.SetStart( c.m_Start );
125 shape.SetCenter( c.m_Center );
126
127 shape.SetArcAngleAndEnd( EDA_ANGLE( c.m_Angle, DEGREES_T ), true );
128
129 BOOST_CHECK_EQUAL( shape.EndsSwapped(), c.m_ExpectedStartEndSwapped );
130
131 const VECTOR2I newEnd = shape.EndsSwapped() ? shape.GetStart() : shape.GetEnd();
132
135 (newEnd) ( c.m_ExpectedEndBeforeSwap ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
136 }
137}
138
139
152
153static const std::vector<SET_ARC_GEOMETRY_CASE> set_arc_geometry_cases = {
154 {
155 // Test that when setting an arc by start/mid/end, the winding
156 // direction is correctly determined (in 15694, this was in FP_SHAPE,
157 // but the logic has since been merged with EDA_SHAPE).
158 "Issue 15694: clockwise arc",
159 { 10000000, 0 },
160 { 0, 10000000 },
161 { -10000000, 0 },
162 { 0, 0 },
163 10000000,
164 false,
165 { -10000000, 0 }, // unchanged
166 180.0,
167 },
168 {
169 "Issue 15694: anticlockwise arc",
170 { -10000000, 0 },
171 { 0, 10000000 },
172 { 10000000, 0 },
173 { 0, 0 },
174 10000000,
175 true,
176 { 10000000, 0 }, // the start is the end after swapping
177 180.0, // angle is positive after swapping
178 },
179};
180
181BOOST_AUTO_TEST_CASE( SetArcGeometry )
182{
183 const double angle_tol = 0.1;
184
185 for( const auto& c : set_arc_geometry_cases )
186 {
187 BOOST_TEST_INFO_SCOPE( c.m_CaseName );
188
190
191 shape.SetArcGeometry( c.m_Start, c.m_Mid, c.m_End );
192
193 const VECTOR2I center = shape.getCenter();
194
197 (center) ( c.m_ExpectedCenter ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
198
199 const int radius = shape.GetRadius();
200
203 (radius) ( c.m_ExpectedRadius ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
204
205 BOOST_CHECK_EQUAL( shape.EndsSwapped(), c.m_ExpectedStartEndSwapped );
206
207 const VECTOR2I newEnd = shape.EndsSwapped() ? shape.GetStart() : shape.GetEnd();
208
211 (newEnd) ( c.m_ExpectedEndAfterSwap ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
212
213 const EDA_ANGLE angle = shape.GetArcAngle();
214
217 ( angle.AsDegrees() )( c.m_ExpectedAngleAfterSwapDeg )( 360.0 )( angle_tol ) );
218
219 // Check that the centre is still correct
220 }
221}
222
227BOOST_AUTO_TEST_CASE( SetArcGeometryKeepsMidWhenEndsSwap )
228{
229 // On the circle but away from the half-angle point, so a recomputed mid cannot match it
230 const VECTOR2I mid( 6000000, 8000000 );
231
232 for( bool swap : { false, true } )
233 {
234 BOOST_TEST_INFO_SCOPE( ( swap ? "swapped" : "unswapped" ) );
235
237
238 if( swap )
239 shape.SetArcGeometry( { -10000000, 0 }, mid, { 10000000, 0 } );
240 else
241 shape.SetArcGeometry( { 10000000, 0 }, mid, { -10000000, 0 } );
242
244 BOOST_CHECK_EQUAL( shape.GetArcMid(), mid );
245 }
246}
247
248
255BOOST_AUTO_TEST_CASE( ArcEditKeepsSmallSchematicRadius )
256{
257 // 50 mil radius arc in schematic IUs, well under the buggy 100 mil floor.
258 const int radius = schIUScale.MilsToIU( 50 );
259 const VECTOR2I center( 0, 0 );
260 const VECTOR2I start( radius, 0 );
261 const VECTOR2I end( 0, radius );
262 const VECTOR2I mid( KiROUND( radius / std::sqrt( 2.0 ) ),
263 KiROUND( radius / std::sqrt( 2.0 ) ) );
264
266 arc.SetArcGeometry( start, mid, end );
267
268 BOOST_REQUIRE_LT( arc.GetRadius(), schIUScale.MilsToIU( 100 ) );
269
270 // Drag the endpoint a few IU; with the bug the radius snaps up to 100 mil.
271 const VECTOR2I newEnd( 5, radius );
272
273 KI_ARC_EDIT::EditArcEndpointKeepCenter( arc, center, start, mid, newEnd, newEnd, schIUScale );
274 BOOST_CHECK_LT( arc.GetRadius(), schIUScale.MilsToIU( 100 ) );
275
276 // Same for the mid-point helper, which has its own minimum-radius clamp.
277 const VECTOR2I smallerMid( KiROUND( ( radius - 100 ) / std::sqrt( 2.0 ) ),
278 KiROUND( ( radius - 100 ) / std::sqrt( 2.0 ) ) );
279
281 arc2.SetArcGeometry( start, mid, end );
282
283 KI_ARC_EDIT::EditArcMidKeepCenter( arc2, center, start, mid, end, smallerMid, schIUScale );
284 BOOST_CHECK_LT( arc2.GetRadius(), schIUScale.MilsToIU( 100 ) );
285}
286
287
295BOOST_AUTO_TEST_CASE( PolygonBehaviorSurvivesAssignment )
296{
298
299 SHAPE_POLY_SET& poly = shape.GetPolyShape();
300 poly.NewOutline();
301 poly.Append( { 0, 0 } );
302 poly.Append( { 1000000, 0 } );
303 poly.Append( { 1000000, 1000000 } );
304
305 EDA_POLYGON_POINT_EDIT_BEHAVIOR behavior( shape );
306
307 EDIT_POINTS points( nullptr );
308 behavior.MakePoints( points );
309 BOOST_CHECK_EQUAL( points.PointsSize(), 3u );
310
311 EDA_SHAPE_MOCK copy( shape );
312 shape = copy;
313
314 // After assignment, shape.m_poly is a fresh allocation.
315 // The behavior must still work (not use-after-free).
316 EDIT_POINTS points2( nullptr );
317 behavior.MakePoints( points2 );
318 BOOST_CHECK_EQUAL( points2.PointsSize(), 3u );
319
320 BOOST_CHECK( behavior.UpdatePoints( points ) );
321}
322
323
324BOOST_AUTO_TEST_CASE( PolygonBehaviorSignalsRebuildWhenShapeMorphs )
325{
327
328 SHAPE_POLY_SET& poly = shape.GetPolyShape();
329 poly.NewOutline();
330 poly.Append( { 0, 0 } );
331 poly.Append( { 1000000, 0 } );
332 poly.Append( { 1000000, 1000000 } );
333 poly.Append( { 0, 1000000 } );
334
335 EDA_POLYGON_POINT_EDIT_BEHAVIOR behavior( shape );
336
337 EDIT_POINTS points( nullptr );
338 behavior.MakePoints( points );
339 BOOST_CHECK( behavior.UpdatePoints( points ) );
340
342 shape.SetStart( { 0, 0 } );
343 shape.SetEnd( { 1000000, 1000000 } );
344
345 BOOST_CHECK( !behavior.UpdatePoints( points ) );
346}
347
348
349BOOST_AUTO_TEST_CASE( GetPolyPointsPreservesOrderAcrossOutlines )
350{
351 // GetPolyPoints flattens every outline of the poly shape into a single
352 // ordered vector. Verify the count and order are preserved across multiple
353 // outlines so the single up-front reserve does not alter behavior.
355
356 SHAPE_POLY_SET& poly = shape.GetPolyShape();
357
358 poly.NewOutline();
359 poly.Append( { 0, 0 } );
360 poly.Append( { 1000, 0 } );
361 poly.Append( { 1000, 1000 } );
362
363 poly.NewOutline();
364 poly.Append( { 5000, 5000 } );
365 poly.Append( { 6000, 5000 } );
366
367 const std::vector<VECTOR2I> expected = {
368 { 0, 0 }, { 1000, 0 }, { 1000, 1000 }, { 5000, 5000 }, { 6000, 5000 }
369 };
370
371 const std::vector<VECTOR2I> points = shape.GetPolyPoints();
372
373 BOOST_REQUIRE_EQUAL( points.size(), expected.size() );
374
375 for( size_t ii = 0; ii < expected.size(); ++ii )
376 {
377 BOOST_CHECK_EQUAL( points[ii].x, expected[ii].x );
378 BOOST_CHECK_EQUAL( points[ii].y, expected[ii].y );
379 }
380}
381
382
383BOOST_AUTO_TEST_CASE( EllipseBasicAccessors )
384{
385 // Construct a closed ellipse EDA_SHAPE and round-trip every accessor.
387 e.SetEllipseCenter( VECTOR2I( 100, 200 ) );
388 e.SetEllipseMajorRadius( 500 );
389 e.SetEllipseMinorRadius( 300 );
391
397 BOOST_CHECK_CLOSE( e.GetEllipseRotation().AsDegrees(), 30.0, 1e-6 );
398
399 // Closed ellipse reports itself as a closed shape.
400 BOOST_CHECK( e.IsClosed() );
401}
402
403
404BOOST_AUTO_TEST_CASE( EllipseArcIsOpenCurve )
405{
406 // Elliptical arcs are open
407 // IsClosed() must return false.
409 arc.SetEllipseCenter( VECTOR2I( 0, 0 ) );
410 arc.SetEllipseMajorRadius( 500 );
411 arc.SetEllipseMinorRadius( 300 );
414 arc.SetEllipseEndAngle( EDA_ANGLE( 180.0, DEGREES_T ) );
415
417 BOOST_CHECK( !arc.IsClosed() );
418
419 // Start/end angles round trip through the accessors.
420 BOOST_CHECK_CLOSE( arc.GetEllipseStartAngle().AsDegrees(), 0.0, 1e-6 );
421 BOOST_CHECK_CLOSE( arc.GetEllipseEndAngle().AsDegrees(), 180.0, 1e-6 );
422}
423
424
425BOOST_AUTO_TEST_CASE( EllipsePerimeterForCircleCase )
426{
427 // An ellipse with MajorRadius == MinorRadius is a circle.
428 // Ramanujan's approximation returns 2Ï€r for this case.
430 e.SetEllipseCenter( VECTOR2I( 0, 0 ) );
431 e.SetEllipseMajorRadius( 1000 );
432 e.SetEllipseMinorRadius( 1000 );
434
435 const double expected = 2.0 * M_PI * 1000.0;
436 BOOST_CHECK_CLOSE( e.GetLength(), expected, 1e-6 );
437}
438
439
440BOOST_AUTO_TEST_CASE( EllipseMakeEffectiveShapesNonEmpty )
441{
442 // MakeEffectiveShapes converts the ellipse into primitive shapes that DRC
443 // the router, and exporters consume. Verify it returns at least one shape
444
446 e.SetEllipseCenter( VECTOR2I( 0, 0 ) );
447 e.SetEllipseMajorRadius( 500 );
448 e.SetEllipseMinorRadius( 300 );
450
451 std::vector<SHAPE*> shapes = e.MakeEffectiveShapes();
452 BOOST_CHECK( !shapes.empty() );
453
454 for( SHAPE* s : shapes )
455 delete s;
456}
457
458
459BOOST_AUTO_TEST_CASE( ShortenSegmentForEndingsTrimsStartAndEnd )
460{
461 VECTOR2I start( 0, 0 );
462 VECTOR2I end( 1000, 0 );
463 LINE_ENDING startEnding( LINE_ENDING_STYLE::ARROW, 100, 100 );
464 LINE_ENDING endEnding( LINE_ENDING_STYLE::CIRCLE, 200, 200 );
465
466 BOOST_CHECK( EDA_SHAPE::ShortenSegmentForEndings( start, end, startEnding, endEnding, 20 ) );
467 BOOST_CHECK_EQUAL( start.x, 100 );
468 BOOST_CHECK_EQUAL( start.y, 0 );
469 BOOST_CHECK_EQUAL( end.x, 900 );
470 BOOST_CHECK_EQUAL( end.y, 0 );
471}
472
473
474BOOST_AUTO_TEST_CASE( SegmentOpenArrowLeavesBody )
475{
476 VECTOR2I start( 0, 0 );
477 VECTOR2I end( 1000, 0 );
478 LINE_ENDING startEnding( LINE_ENDING_STYLE::ARROW_OPEN, 500, 500 );
479 LINE_ENDING endEnding;
480
481 BOOST_CHECK( EDA_SHAPE::ShortenSegmentForEndings( start, end, startEnding, endEnding, 20 ) );
482 BOOST_CHECK_EQUAL( start.x, 0 );
483 BOOST_CHECK_EQUAL( start.y, 0 );
484 BOOST_CHECK_EQUAL( end.x, 1000 );
485 BOOST_CHECK_EQUAL( end.y, 0 );
486}
487
488
489BOOST_AUTO_TEST_CASE( SegmentShorteningRejectsOverrun )
490{
491 VECTOR2I start( 0, 0 );
492 VECTOR2I end( 1000, 0 );
493 LINE_ENDING startEnding( LINE_ENDING_STYLE::ARROW, 600, 100 );
494 LINE_ENDING endEnding( LINE_ENDING_STYLE::ARROW, 500, 100 );
495
496 BOOST_CHECK( !EDA_SHAPE::ShortenSegmentForEndings( start, end, startEnding, endEnding, 20 ) );
497 BOOST_CHECK_EQUAL( start.x, 0 );
498 BOOST_CHECK_EQUAL( start.y, 0 );
499 BOOST_CHECK_EQUAL( end.x, 0 );
500 BOOST_CHECK_EQUAL( end.y, 0 );
501}
502
503
504BOOST_AUTO_TEST_CASE( SegmentEndingTangentsPointOutward )
505{
507 shape.SetStart( { 0, 0 } );
508 shape.SetEnd( { 1000, 0 } );
509
510 EDA_ANGLE startTangent;
511 EDA_ANGLE endTangent;
512 shape.GetEndingTangents( startTangent, endTangent, 20 );
513
514 checkAngleClose( startTangent, 180.0 );
515 checkAngleClose( endTangent, 0.0 );
516}
517
518
519BOOST_AUTO_TEST_CASE( OpenArrowBezierTangentsUseDepth )
520{
522 shape.SetStart( { 0, 0 } );
523 shape.SetBezierC1( { 1000, 0 } );
524 shape.SetBezierC2( { 0, 1000 } );
525 shape.SetEnd( { 1000, 1000 } );
527 shape.SetStartEndingLength( 300 );
528 shape.SetStartEndingWidth( 300 );
530 shape.SetEndEndingLength( 300 );
531 shape.SetEndEndingWidth( 300 );
532
533 EDA_ANGLE startTangent;
534 EDA_ANGLE endTangent;
535 shape.GetEndingTangents( startTangent, endTangent, 20 );
536
537 checkAngleInRange( startTangent, -180.0, -90.0 );
538 checkAngleInRange( endTangent, 0.0, 90.0 );
539}
540
541
542BOOST_AUTO_TEST_CASE( LineEndingEndpointsUseShapeOwnedSources )
543{
544 VECTOR2I start;
546
548 segment.SetStart( { 0, 10 } );
549 segment.SetEnd( { 100, 20 } );
550
551 BOOST_CHECK( segment.GetLineEndingEndpoints( start, end ) );
552 checkVectorEqual( start, { 0, 10 } );
553 checkVectorEqual( end, { 100, 20 } );
554
556 arc.SetStart( { 10, 0 } );
557 arc.SetEnd( { 20, 30 } );
558
559 BOOST_CHECK( arc.GetLineEndingEndpoints( start, end ) );
560 checkVectorEqual( start, { 10, 0 } );
561 checkVectorEqual( end, { 20, 30 } );
562
564 bezier.SetStart( { 0, 0 } );
565 bezier.SetBezierC1( { 20, 0 } );
566 bezier.SetBezierC2( { 80, 100 } );
567 bezier.SetEnd( { 100, 100 } );
568 bezier.RebuildBezierToSegmentsPointsList( 1 );
569
570 BOOST_CHECK( bezier.GetLineEndingEndpoints( start, end ) );
571 checkVectorEqual( start, { 0, 0 } );
572 checkVectorEqual( end, { 100, 100 } );
573
574 EDA_SHAPE_MOCK polyShape( SHAPE_T::POLY );
575 SHAPE_POLY_SET poly;
576 poly.NewOutline();
577 poly.Outline( 0 ).SetClosed( false );
578 poly.Append( { 5, 5 } );
579 poly.Append( { 50, 10 } );
580 poly.Append( { 100, 20 } );
581 polyShape.SetPolyShape( poly );
582
583 BOOST_CHECK( polyShape.GetLineEndingEndpoints( start, end ) );
584 checkVectorEqual( start, { 5, 5 } );
585 checkVectorEqual( end, { 100, 20 } );
586}
587
588
589BOOST_AUTO_TEST_CASE( LineEndingEndpointsRejectInvalidPolys )
590{
591 VECTOR2I start;
593
594 EDA_SHAPE_MOCK emptyPoly( SHAPE_T::POLY );
595 BOOST_CHECK( !emptyPoly.GetLineEndingEndpoints( start, end ) );
596
597 EDA_SHAPE_MOCK onePointPoly( SHAPE_T::POLY );
598 SHAPE_POLY_SET poly;
599 poly.NewOutline();
600 poly.Append( { 5, 5 } );
601 onePointPoly.SetPolyShape( poly );
602
603 BOOST_CHECK( !onePointPoly.GetLineEndingEndpoints( start, end ) );
604}
605
606
607BOOST_AUTO_TEST_CASE( EffectiveShapesIncludeClosedEnding )
608{
610 shape.SetStart( { 0, 0 } );
611 shape.SetEnd( { 1000, 0 } );
613 shape.SetEndEndingLength( 400 );
614 shape.SetEndEndingWidth( 400 );
615
616 std::vector<SHAPE*> shapes = shape.MakeLineEndingEffectiveShapes( 20 );
617
618 BOOST_REQUIRE_EQUAL( shapes.size(), 1 );
619
620 BOX2I bbox = shapes[0]->BBox();
621 BOOST_CHECK( bbox.GetLeft() <= 800 );
622 BOOST_CHECK( bbox.GetRight() >= 1200 );
623 BOOST_CHECK( bbox.GetTop() <= -200 );
624 BOOST_CHECK( bbox.GetBottom() >= 200 );
625
626 deleteShapes( shapes );
627}
628
629
630BOOST_AUTO_TEST_CASE( EffectiveShapesIncludeOpenArrowLegs )
631{
633 shape.SetStart( { 0, 0 } );
634 shape.SetEnd( { 1000, 0 } );
636 shape.SetEndEndingLength( 300 );
637 shape.SetEndEndingWidth( 200 );
638 shape.SetEndEndingStrokeWidth( 70 );
639
640 std::vector<SHAPE*> shapes = shape.MakeLineEndingEffectiveShapes( 20 );
641
642 BOOST_REQUIRE_EQUAL( shapes.size(), 2 );
643
644 for( SHAPE* shapePtr : shapes )
645 {
646 const SHAPE_SEGMENT* leg = dynamic_cast<const SHAPE_SEGMENT*>( shapePtr );
647 BOOST_REQUIRE( leg );
648 BOOST_CHECK_EQUAL( leg->GetWidth(), 70 );
649 }
650
651 deleteShapes( shapes );
652}
653
654
655BOOST_AUTO_TEST_CASE( BBoxIncludesCenteredEnding )
656{
658 shape.SetStart( { 0, 0 } );
659 shape.SetEnd( { 1000, 0 } );
661 shape.SetEndEndingLength( 400 );
662 shape.SetEndEndingWidth( 400 );
663
664 BOX2I bbox;
665
666 BOOST_CHECK( shape.GetLineEndingsBoundingBox( bbox, 20 ) );
667 BOOST_CHECK( bbox.GetLeft() <= 800 );
668 BOOST_CHECK( bbox.GetRight() >= 1200 );
669 BOOST_CHECK( bbox.GetTop() <= -200 );
670 BOOST_CHECK( bbox.GetBottom() >= 200 );
671}
672
673
674BOOST_AUTO_TEST_CASE( BBoxUsesRotatedEndingGeometry )
675{
677 shape.SetStart( { 0, 0 } );
678 shape.SetEnd( { 1000, 1000 } );
680 shape.SetEndEndingLength( 400 );
681 shape.SetEndEndingWidth( 400 );
682
683 BOX2I bbox;
684
685 BOOST_CHECK( shape.GetLineEndingsBoundingBox( bbox, 20 ) );
686 BOOST_CHECK( bbox.GetLeft() <= 718 );
687 BOOST_CHECK( bbox.GetRight() >= 1282 );
688 BOOST_CHECK( bbox.GetTop() <= 718 );
689 BOOST_CHECK( bbox.GetBottom() >= 1282 );
690}
691
692
693BOOST_AUTO_TEST_CASE( PolygonConversionAppendsEndings )
694{
696 shape.SetStart( { 0, 0 } );
697 shape.SetEnd( { 1000, 0 } );
698 shape.SetWidth( 20 );
700 shape.SetEndEndingLength( 400 );
701 shape.SetEndEndingWidth( 400 );
702
703 SHAPE_POLY_SET body;
704 SHAPE_POLY_SET withEnding;
705
706 shape.TransformShapeToPolygon( body, 0, 1, ERROR_OUTSIDE );
707 shape.TransformShapeToPolygon( withEnding, 0, 1, ERROR_OUTSIDE );
708 shape.TransformLineEndingsToPolygon( withEnding, 0, 1, ERROR_OUTSIDE, shape.GetWidth() );
709
710 BOX2I bodyBBox = body.BBox();
711 BOX2I endingBBox = withEnding.BBox();
712
713 BOOST_CHECK( endingBBox.GetRight() > bodyBBox.GetRight() );
714 BOOST_CHECK( endingBBox.GetTop() < bodyBBox.GetTop() );
715 BOOST_CHECK( endingBBox.GetBottom() > bodyBBox.GetBottom() );
716}
717
718
719BOOST_AUTO_TEST_CASE( EffectiveShapesShortenArrowBody )
720{
722 shape.SetStart( { 0, 0 } );
723 shape.SetEnd( { 1000, 0 } );
724 shape.SetWidth( 20 );
726 shape.SetEndEndingLength( 200 );
727 shape.SetEndEndingWidth( 200 );
728
729 std::vector<SHAPE*> shapes = shape.MakeEffectiveShapesWithLineEndings( shape.GetWidth() );
730 const SHAPE_SEGMENT* body = nullptr;
731
732 for( SHAPE* shapePtr : shapes )
733 {
734 if( const SHAPE_SEGMENT* segment = dynamic_cast<const SHAPE_SEGMENT*>( shapePtr ) )
735 {
736 body = segment;
737 break;
738 }
739 }
740
741 BOOST_REQUIRE( body );
742 checkVectorEqual( body->GetStart(), { 0, 0 } );
743 checkVectorEqual( body->GetEnd(), { 800, 0 } );
744
745 deleteShapes( shapes );
746}
747
748
749BOOST_AUTO_TEST_CASE( StrokingShapesShortenArrowBodyOnly )
750{
752 shape.SetStart( { 0, 0 } );
753 shape.SetEnd( { 1000, 0 } );
754 shape.SetWidth( 20 );
756 shape.SetEndEndingLength( 200 );
757 shape.SetEndEndingWidth( 200 );
758
759 std::vector<SHAPE*> shapes = shape.MakeEffectiveShapesForStroking( shape.GetWidth() );
760
761 BOOST_REQUIRE_EQUAL( shapes.size(), 1 );
762
763 const SHAPE_SEGMENT* body = dynamic_cast<const SHAPE_SEGMENT*>( shapes.front() );
764 BOOST_REQUIRE( body );
765 checkVectorEqual( body->GetStart(), { 0, 0 } );
766 checkVectorEqual( body->GetEnd(), { 800, 0 } );
767
768 deleteShapes( shapes );
769}
770
771
772BOOST_AUTO_TEST_CASE( StrokingShapesRejectConsumedSegmentBody )
773{
775 shape.SetStart( { 0, 0 } );
776 shape.SetEnd( { 1000, 0 } );
777 shape.SetWidth( 20 );
779 shape.SetStartEndingLength( 600 );
780 shape.SetStartEndingWidth( 200 );
782 shape.SetEndEndingLength( 500 );
783 shape.SetEndEndingWidth( 200 );
784
785 std::vector<SHAPE*> shapes = shape.MakeEffectiveShapesForStroking( shape.GetWidth() );
786
787 BOOST_CHECK( shapes.empty() );
788
789 deleteShapes( shapes );
790}
791
792
793BOOST_AUTO_TEST_CASE( EffectiveShapesHitEndpointSquare )
794{
796 shape.SetStart( { 0, 0 } );
797 shape.SetEnd( { 1000, 0 } );
798 shape.SetWidth( 100 );
800 shape.SetStartEndingLength( 400 );
801 shape.SetStartEndingWidth( 400 );
802
803 std::vector<SHAPE*> shapes = shape.MakeEffectiveShapesWithLineEndings( shape.GetWidth() );
804 SHAPE_SEGMENT probe( VECTOR2I( 0, -150 ), VECTOR2I( 0, 150 ), 20 );
805 bool collides = false;
806
807 for( SHAPE* shapePtr : shapes )
808 {
809 if( shapePtr->Collide( probe.GetSeg(), 0 ) )
810 {
811 collides = true;
812 break;
813 }
814 }
815
816 BOOST_CHECK( collides );
817
818 deleteShapes( shapes );
819}
820
821
822BOOST_AUTO_TEST_CASE( PolygonConversionShortensArrowBody )
823{
825 shape.SetStart( { 0, 0 } );
826 shape.SetEnd( { 1000, 0 } );
827 shape.SetWidth( 100 );
829 shape.SetEndEndingLength( 200 );
830 shape.SetEndEndingWidth( 200 );
831
832 SHAPE_POLY_SET unshortenedBodyPlusEnding;
833 SHAPE_POLY_SET shortenedBodyPlusEnding;
834
835 shape.TransformShapeToPolygon( unshortenedBodyPlusEnding, 0, 1, ERROR_OUTSIDE );
836 shape.TransformLineEndingsToPolygon( unshortenedBodyPlusEnding, 0, 1, ERROR_OUTSIDE, shape.GetWidth() );
837 shape.TransformWithLineEndingsToPolygon( shortenedBodyPlusEnding, 0, 1, ERROR_OUTSIDE );
838
839 BOOST_CHECK_GT( unshortenedBodyPlusEnding.BBox().GetRight(), 1000 );
840 BOOST_CHECK_LE( shortenedBodyPlusEnding.BBox().GetRight(), 1001 );
841}
842
843
844BOOST_AUTO_TEST_CASE( ShortenArcForEndingsKeepsPositiveSweep )
845{
848 shape.SetStartEndingLength( 100 );
849 shape.SetStartEndingWidth( 100 );
851 shape.SetEndEndingLength( 200 );
852 shape.SetEndEndingWidth( 100 );
853
854 EDA_ANGLE startAngle( 10.0, DEGREES_T );
855 EDA_ANGLE arcAngle( 90.0, DEGREES_T );
856 constexpr double radius = 1000.0;
857 constexpr double radToDeg = 180.0 / M_PI;
858
859 BOOST_CHECK( shape.ShortenArcForEndings( startAngle, arcAngle, radius, 20 ) );
860 checkAngleClose( startAngle, 10.0 + 100.0 / radius * radToDeg );
861 checkAngleClose( arcAngle, 90.0 - 300.0 / radius * radToDeg );
862 BOOST_CHECK( arcAngle > ANGLE_0 );
863}
864
865
866BOOST_AUTO_TEST_CASE( ShortenArcForEndingsKeepsNegativeSweep )
867{
870 shape.SetStartEndingLength( 100 );
871 shape.SetStartEndingWidth( 100 );
873 shape.SetEndEndingLength( 200 );
874 shape.SetEndEndingWidth( 100 );
875
876 EDA_ANGLE startAngle( 170.0, DEGREES_T );
877 EDA_ANGLE arcAngle( -90.0, DEGREES_T );
878 constexpr double radius = 1000.0;
879 constexpr double radToDeg = 180.0 / M_PI;
880
881 BOOST_CHECK( shape.ShortenArcForEndings( startAngle, arcAngle, radius, 20 ) );
882 checkAngleClose( startAngle, 170.0 - 100.0 / radius * radToDeg );
883 checkAngleClose( arcAngle, -90.0 + 300.0 / radius * radToDeg );
884 BOOST_CHECK( arcAngle < ANGLE_0 );
885}
886
887
888BOOST_AUTO_TEST_CASE( ArcShorteningRejectsOverrun )
889{
892 shape.SetStartEndingLength( 100 );
893 shape.SetStartEndingWidth( 100 );
895 shape.SetEndEndingLength( 100 );
896 shape.SetEndEndingWidth( 100 );
897
898 EDA_ANGLE startAngle( 30.0, DEGREES_T );
899 EDA_ANGLE arcAngle( 10.0, DEGREES_T );
900
901 BOOST_CHECK( !shape.ShortenArcForEndings( startAngle, arcAngle, 1000.0, 20 ) );
902 checkAngleClose( startAngle, 30.0 );
903 checkAngleClose( arcAngle, 0.0 );
904}
905
906
907BOOST_AUTO_TEST_CASE( BezierNoEndingsReturnsSource )
908{
910 shape.SetStart( { 0, 0 } );
911 shape.SetBezierC1( { 300, 0 } );
912 shape.SetBezierC2( { 700, 0 } );
913 shape.SetEnd( { 1000, 0 } );
914
915 std::optional<BEZIER<double>> curve = shape.ShortenedBezierCurve( 20 );
916
917 BOOST_REQUIRE( curve );
918 checkVectorClose( curve->Start, { 0, 0 } );
919 checkVectorClose( curve->C1, { 300, 0 } );
920 checkVectorClose( curve->C2, { 700, 0 } );
921 checkVectorClose( curve->End, { 1000, 0 } );
922}
923
924
925BOOST_AUTO_TEST_CASE( BezierCurveTrimsBothEnds )
926{
928 shape.SetStart( { 0, 0 } );
929 shape.SetBezierC1( { 300, 0 } );
930 shape.SetBezierC2( { 700, 0 } );
931 shape.SetEnd( { 1000, 0 } );
933 shape.SetStartEndingLength( 100 );
934 shape.SetStartEndingWidth( 100 );
936 shape.SetEndEndingLength( 200 );
937 shape.SetEndEndingWidth( 100 );
938
939 std::optional<BEZIER<double>> curve = shape.ShortenedBezierCurve( 20 );
940
941 BOOST_REQUIRE( curve );
942 checkVectorClose( curve->Start, { 100, 0 }, 1e-3 );
943 checkVectorClose( curve->End, { 800, 0 }, 1e-3 );
944}
945
946
947BOOST_AUTO_TEST_CASE( BezierCurveRejectsOverrun )
948{
950 shape.SetStart( { 0, 0 } );
951 shape.SetBezierC1( { 300, 0 } );
952 shape.SetBezierC2( { 700, 0 } );
953 shape.SetEnd( { 1000, 0 } );
955 shape.SetStartEndingLength( 600 );
956 shape.SetStartEndingWidth( 100 );
958 shape.SetEndEndingLength( 500 );
959 shape.SetEndEndingWidth( 100 );
960
961 BOOST_CHECK( !shape.ShortenedBezierCurve( 20 ) );
962}
963
964
965BOOST_AUTO_TEST_CASE( ShortenedBezierPolylineUsesShortenedCurve )
966{
968 shape.SetStart( { 0, 0 } );
969 shape.SetBezierC1( { 300, 0 } );
970 shape.SetBezierC2( { 700, 0 } );
971 shape.SetEnd( { 1000, 0 } );
973 shape.SetStartEndingLength( 100 );
974 shape.SetStartEndingWidth( 100 );
976 shape.SetEndEndingLength( 200 );
977 shape.SetEndEndingWidth( 100 );
978
979 std::vector<VECTOR2D> points = shape.ShortenedBezierPolyline( 20 );
980
981 BOOST_REQUIRE_GE( points.size(), 2 );
982 checkVectorClose( points.front(), { 100, 0 }, 1e-3 );
983 checkVectorClose( points.back(), { 800, 0 }, 1e-3 );
984}
985
986
987BOOST_AUTO_TEST_CASE( BezierPolylineRejectsOverrun )
988{
990 shape.SetStart( { 0, 0 } );
991 shape.SetBezierC1( { 300, 0 } );
992 shape.SetBezierC2( { 700, 0 } );
993 shape.SetEnd( { 1000, 0 } );
995 shape.SetStartEndingLength( 600 );
996 shape.SetStartEndingWidth( 100 );
998 shape.SetEndEndingLength( 500 );
999 shape.SetEndEndingWidth( 100 );
1000
1001 BOOST_CHECK( shape.ShortenedBezierPolyline( 20 ).empty() );
1002}
1003
1004
1005// Minimal concrete RENDER_SETTINGS; STROKE_PARAMS::Stroke only reads the dash/gap ratios.
1007{
1008public:
1009 KIGFX::COLOR4D GetColor( const KIGFX::VIEW_ITEM* aItem, int aLayer ) const override
1010 {
1011 return KIGFX::COLOR4D::BLACK;
1012 }
1013
1014 const KIGFX::COLOR4D& GetBackgroundColor() const override { return m_color; }
1015 void SetBackgroundColor( const KIGFX::COLOR4D& aColor ) override { m_color = aColor; }
1016 const KIGFX::COLOR4D& GetGridColor() override { return m_color; }
1017 const KIGFX::COLOR4D& GetCursorColor() override { return m_color; }
1018
1019private:
1021};
1022
1023
1024// A dashed Bezier with endings must still be stroked as ONE chain: loose segments would
1025// restart the dash pattern at every tessellation vertex (issue #25110) and draw near-solid.
1026BOOST_AUTO_TEST_CASE( StrokingShortenedBezierDashes )
1027{
1029 shape.SetStart( { 0, 0 } );
1030 shape.SetBezierC1( { 30000, 20000 } );
1031 shape.SetBezierC2( { 70000, -20000 } );
1032 shape.SetEnd( { 100000, 0 } );
1033 shape.SetWidth( 100 );
1035 shape.SetStartEndingLength( 2000 );
1036 shape.SetStartEndingWidth( 1000 );
1038 shape.SetEndEndingLength( 3000 );
1039 shape.SetEndEndingWidth( 1000 );
1040
1041 std::vector<SHAPE*> shapes = shape.MakeEffectiveShapesForStroking( shape.GetWidth() );
1042
1043 // The shortened body must come back as a single chain.
1044 BOOST_REQUIRE_EQUAL( shapes.size(), 1 );
1045
1046 const SHAPE_LINE_CHAIN* chain = dynamic_cast<const SHAPE_LINE_CHAIN*>( shapes.front() );
1048 BOOST_REQUIRE_GE( chain->SegmentCount(), 2 );
1049
1050 double chainLength = 0.0;
1051
1052 for( int ii = 0; ii < chain->SegmentCount(); ++ii )
1053 chainLength += VECTOR2D( chain->CSegment( ii ).B - chain->CSegment( ii ).A ).EuclideanNorm();
1054
1055 // Stroke it dashed and glue touching pieces back into runs (a dash spanning a vertex
1056 // arrives as several touching pieces).
1058 std::vector<SEG> pieces;
1059
1061 [&pieces]( const VECTOR2I& a, const VECTOR2I& b )
1062 {
1063 pieces.emplace_back( a, b );
1064 } );
1065
1066 std::vector<double> runs;
1067 double drawn = 0.0;
1068
1069 for( size_t ii = 0; ii < pieces.size(); )
1070 {
1071 double length = VECTOR2D( pieces[ii].B - pieces[ii].A ).EuclideanNorm();
1072 VECTOR2I end = pieces[ii].B;
1073 size_t jj = ii + 1;
1074
1075 while( jj < pieces.size() && pieces[jj].A == end )
1076 {
1077 length += VECTOR2D( pieces[jj].B - pieces[jj].A ).EuclideanNorm();
1078 end = pieces[jj].B;
1079 jj++;
1080 }
1081
1082 runs.push_back( length );
1083 drawn += length;
1084 ii = jj;
1085 }
1086
1087 BOOST_REQUIRE_MESSAGE( runs.size() > 5, "expected many dashes, got " << runs.size() << " run(s)" );
1088
1089 // If the pattern restarted at every tessellation vertex the curve would come out nearly
1090 // solid; the drawn length must instead match the dash/gap duty cycle.
1091 double dash = settings.GetDashLength( shape.GetWidth() );
1092 double gap = settings.GetGapLength( shape.GetWidth() );
1093 double expected = chainLength * dash / ( dash + gap );
1094
1095 BOOST_CHECK_MESSAGE( std::abs( drawn - expected ) < 0.05 * chainLength,
1096 "dashes should cover " << expected << " IU of the " << chainLength
1097 << " IU shortened body, they cover " << drawn );
1098
1099 deleteShapes( shapes );
1100}
1101
1102
1103BOOST_AUTO_TEST_CASE( PolyShorteningTrimsEnds )
1104{
1107 shape.SetStartEndingLength( 100 );
1108 shape.SetStartEndingWidth( 100 );
1110 shape.SetEndEndingLength( 200 );
1111 shape.SetEndEndingWidth( 200 );
1112
1113 VECTOR2D first( 0, 0 );
1114 VECTOR2D second( 1000, 0 );
1115 VECTOR2D penultimate( 1000, 1000 );
1116 VECTOR2D last( 1000, 2000 );
1117
1118 BOOST_CHECK( shape.ShortenPolyForEndings( first, last, second, penultimate, 20 ) );
1119
1120 checkVectorClose( first, { 100, 0 } );
1121 checkVectorClose( last, { 1000, 1900 } );
1122}
1123
1124
1125BOOST_AUTO_TEST_CASE( ShortenPolyForEndingsLeavesOpenArrowBody )
1126{
1129 shape.SetStartEndingLength( 500 );
1130 shape.SetStartEndingWidth( 500 );
1131
1132 VECTOR2D first( 0, 0 );
1133 VECTOR2D second( 1000, 0 );
1134 VECTOR2D penultimate( 1000, 1000 );
1135 VECTOR2D last( 1000, 2000 );
1136
1137 BOOST_CHECK( shape.ShortenPolyForEndings( first, last, second, penultimate, 20 ) );
1138
1139 checkVectorClose( first, { 0, 0 } );
1140 checkVectorClose( last, { 1000, 2000 } );
1141}
1142
1143
1144BOOST_AUTO_TEST_CASE( BodyPolyPointsShortenFirstOpenOutline )
1145{
1147
1149 shape.SetStartEndingLength( 100 );
1150 shape.SetStartEndingWidth( 100 );
1151
1152 SHAPE_LINE_CHAIN outline;
1153 outline.Append( VECTOR2I( 0, 0 ) );
1154 outline.Append( VECTOR2I( 1000, 0 ) );
1155 outline.Append( VECTOR2I( 1000, 1000 ) );
1156 outline.SetClosed( true );
1157 shape.SetPolyShape( outline );
1158 std::vector<VECTOR2I> pts;
1159
1160 // Closed poly; line endings should be ignored and no shortening done
1161 BOOST_CHECK( shape.GetShortenedBodyPolyPoints( outline, 0, pts, 20 ) );
1162 BOOST_REQUIRE_EQUAL( pts.size(), 3 );
1163 checkVectorEqual( pts.front(), { 0, 0 } );
1164 checkVectorEqual( pts.back(), { 1000, 1000 } );
1165
1166 shape.GetPolyShape().Outline( 0 ).SetClosed( false );
1167
1168 BOOST_CHECK( shape.GetShortenedBodyPolyPoints( outline, 0, pts, 20 ) );
1169 BOOST_REQUIRE_EQUAL( pts.size(), 3 );
1170 checkVectorEqual( pts.front(), { 100, 0 } );
1171 checkVectorEqual( pts.back(), { 1000, 1000 } );
1172
1173 BOOST_CHECK( shape.GetShortenedBodyPolyPoints( outline, 1, pts, 20 ) );
1174 BOOST_REQUIRE_EQUAL( pts.size(), 3 );
1175 checkVectorEqual( pts.front(), { 0, 0 } );
1176 checkVectorEqual( pts.back(), { 1000, 1000 } );
1177}
1178
BOX2I getBoundingBox(BOARD_ITEM *aItem)
@ ERROR_OUTSIDE
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:130
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr coord_type GetBottom() const
Definition box2.h:225
double AsDegrees() const
Definition eda_angle.h:115
"Standard" polygon editing behavior for EDA_SHAPE polygons.
void MakePoints(EDIT_POINTS &aPoints) override
Construct the initial set of edit points for the item and append to the given list.
bool UpdatePoints(EDIT_POINTS &aPoints) override
Update the list of the edit points for the item.
EDA_SHAPE_MOCK(SHAPE_T aShapeType)
BOX2I BBox() const
void Mirror(const SEG &aAxis)
static bool ShortenSegmentForEndings(VECTOR2I &aStart, VECTOR2I &aEnd, const LINE_ENDING &aStartEnding, const LINE_ENDING &aEndEnding, int aLineWidth)
Shorten a segment body for line endings.
EDA_ANGLE GetArcAngle() const
virtual void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:338
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false, bool includeFill=false) const
Convert the shape to a closed polygon.
int GetEllipseMinorRadius() const
Definition eda_shape.h:404
const VECTOR2I & GetEllipseCenter() const
Definition eda_shape.h:386
bool GetLineEndingsBoundingBox(BOX2I &aBBox, int aLineWidth) const
virtual void SetCenter(const VECTOR2I &aCenter)
VECTOR2I getCenter() const
void mirror(const SEG &aAxis)
std::vector< SHAPE * > MakeEffectiveShapesWithLineEndings(int aLineWidth) const
Make effective geometry for the shape body shortened for line endings plus the line-ending geometry i...
void SetEndEndingLength(int aLength)
Definition eda_shape.h:204
void SetStartEndingStyle(LINE_ENDING_STYLE aStyle)
Definition eda_shape.h:193
EDA_ANGLE GetEllipseEndAngle() const
Definition eda_shape.h:432
void SetEndEndingWidth(int aWidth)
Definition eda_shape.h:206
int GetEllipseMajorRadius() const
Definition eda_shape.h:395
std::vector< VECTOR2I > GetPolyPoints() const
Duplicate the polygon outlines into a flat list of VECTOR2I points.
void TransformWithLineEndingsToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const
Convert the shape body shortened for line endings plus line-ending geometry to polygons.
void TransformLineEndingsToPolygon(SHAPE_POLY_SET &aBuffer, int aClearance, int aError, ERROR_LOC aErrorLoc, int aLineWidth) const
Append only the line-ending geometry associated with this shape to a polygon set.
virtual std::vector< SHAPE * > MakeEffectiveShapes(bool aEdgeOnly=false) const
Make a set of SHAPE objects representing the EDA_SHAPE.
Definition eda_shape.h:566
bool ShortenPolyForEndings(VECTOR2D &aFirst, VECTOR2D &aLast, const VECTOR2D &aSecond, const VECTOR2D &aPenultimate, int aLineWidth) const
SHAPE_POLY_SET & GetPolyShape()
void GetEndingTangents(EDA_ANGLE &aStartTangent, EDA_ANGLE &aEndTangent, int aLineWidth=0) const
Compute outward-facing tangent angles at the start and end of the shape.
EDA_ANGLE GetEllipseRotation() const
Definition eda_shape.h:413
void SetEndEndingStyle(LINE_ENDING_STYLE aStyle)
Definition eda_shape.h:196
virtual void SetEllipseEndAngle(const EDA_ANGLE &aA)
Definition eda_shape.h:425
int GetRadius() const
SHAPE_T GetShape() const
Definition eda_shape.h:178
std::vector< SHAPE * > MakeEffectiveShapesForStroking(int aLineWidth=-1) const
Make a set of SHAPE objects to hand to STROKE_PARAMS::Stroke().
virtual void SetBezierC2(const VECTOR2I &aPt)
Definition eda_shape.h:376
bool GetShortenedBodyPolyPoints(const SHAPE_LINE_CHAIN &aOutline, int aOutlineIdx, std::vector< VECTOR2I > &aPoints, int aLineWidth) const
Copy an outline and apply line-ending body shortening when applicable.
virtual void SetBezierC1(const VECTOR2I &aPt)
Definition eda_shape.h:373
bool GetLineEndingEndpoints(VECTOR2I &aStartPoint, VECTOR2I &aEndPoint) const
Return the source endpoints used to place line endings.
virtual void SetEllipseRotation(const EDA_ANGLE &aA)
Definition eda_shape.h:406
EDA_SHAPE(SHAPE_T aType, int aLineWidth, FILL_T aFill)
Definition eda_shape.cpp:56
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:334
bool IsClosed() const
virtual void SetEllipseCenter(const VECTOR2I &aPt)
Definition eda_shape.h:379
void SetStartEndingLength(int aLength)
Definition eda_shape.h:199
void SetEndEndingStrokeWidth(int aWidth)
Definition eda_shape.h:211
virtual void SetEllipseMinorRadius(int aR)
Definition eda_shape.h:397
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:284
virtual void SetEllipseMajorRadius(int aR)
Definition eda_shape.h:388
virtual void SetShape(SHAPE_T aShape)
Definition eda_shape.h:177
std::vector< SHAPE * > MakeLineEndingEffectiveShapes(int aLineWidth) const
Make the line-ending geometry associated with this shape.
void SetStartEndingWidth(int aWidth)
Definition eda_shape.h:201
EDA_ANGLE GetEllipseStartAngle() const
Definition eda_shape.h:423
bool EndsSwapped() const
Have the start and end points been swapped since they were set?
Definition eda_shape.h:461
virtual void SetEllipseStartAngle(const EDA_ANGLE &aA)
Definition eda_shape.h:416
virtual void SetArcGeometry(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Set the three controlling points for an arc.
double GetLength() const
std::optional< BEZIER< double > > ShortenedBezierCurve(int aLineWidth) const
Return the cubic Bezier curve shortened for line endings.
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
virtual int GetWidth() const
Definition eda_shape.h:166
bool ShortenArcForEndings(EDA_ANGLE &aStartAngle, EDA_ANGLE &aArcAngle, double aRadius, int aLineWidth) const
Shorten an arc body for line endings.
std::vector< VECTOR2D > ShortenedBezierPolyline(int aLineWidth) const
Return the flattened Bezier polyline after line-ending shortening.
virtual void SetWidth(int aWidth)
virtual void SetPolyShape(const SHAPE_POLY_SET &aShape)
Definition eda_shape.h:529
virtual void SetStart(const VECTOR2I &aStart)
Definition eda_shape.h:288
VECTOR2I GetArcMid() const
EDIT_POINTS is a VIEW_ITEM that manages EDIT_POINTs and EDIT_LINEs and draws them.
unsigned int PointsSize() const
Return number of stored EDIT_POINTs.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
static const COLOR4D BLACK
Definition color4d.h:404
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
double GetGapLength(int aLineWidth) const
double GetDashLength(int aLineWidth) const
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
Decorative shape (arrowhead, circle, square) at the start or end of a graphic line,...
Definition line_ending.h:62
Definition seg.h:38
static int DefaultAccuracyForPCB()
Definition shape_arc.h:283
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.
void Append(int aX, int aY, bool aAllowDuplication=false)
Append a new point at the end of the line chain.
Represent a set of closed polygons.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int NewOutline()
Creates a new empty polygon in the set and returns its index.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
const SEG & GetSeg() const
VECTOR2I GetEnd() const override
VECTOR2I GetStart() const override
int GetWidth() const override
An abstract shape on 2D plane.
Definition shape.h:124
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
const KIGFX::COLOR4D & GetGridColor() override
Return current grid color settings.
KIGFX::COLOR4D GetColor(const KIGFX::VIEW_ITEM *aItem, int aLayer) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
void SetBackgroundColor(const KIGFX::COLOR4D &aColor) override
Set the background color.
const KIGFX::COLOR4D & GetBackgroundColor() const override
Return current background color settings.
const KIGFX::COLOR4D & GetCursorColor() override
Return current cursor color settings.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:281
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
@ DEGREES_T
Definition eda_angle.h:30
FILL_T
Definition eda_fill.h:29
@ NO_FILL
Definition eda_fill.h:30
SHAPE_T
Definition eda_shape.h:55
@ ELLIPSE
Definition eda_shape.h:63
@ SEGMENT
Definition eda_shape.h:57
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:58
@ ELLIPSE_ARC
Definition eda_shape.h:64
void EditArcEndpointKeepCenter(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor, const EDA_IU_SCALE &aIuScale)
Move an arc endpoint around the existing center, pulling the opposite endpoint along to keep the radi...
void EditArcMidKeepCenter(EDA_SHAPE &aArc, const VECTOR2I &aCenter, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, const VECTOR2I &aCursor, const EDA_IU_SCALE &aIuScale)
Move the mid point of an arc while keeping the center, rotating the endpoints onto the new radius.
bool IsWithinWrapped(T aValue, T aNominal, T aWrap, T aError)
Check if a value is within a tolerance of a nominal value, wrapping to a given val.
Definition numeric.h:39
bool IsWithin(T aValue, T aNominal, T aError)
Check if a value is within a tolerance of a nominal value.
Definition numeric.h:57
bool IsVecWithinTol(const VEC &aVec, const VEC &aExp, typename VEC::coord_type aTol)
Check that both x and y of a vector are within expected error.
Definition geometry.h:51
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:461
VECTOR2I m_ExpectedEndBeforeSwap
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE_MESSAGE(dc.CacheTableInfo(table, { "part_id", "val" }), dc.GetLastError())
BOOST_REQUIRE(res.columns()==1)
static void deleteShapes(std::vector< SHAPE * > &aShapes)
static void checkAngleClose(const EDA_ANGLE &aActual, double aExpectedDegrees, double aTolerance=1e-6)
static void checkAngleInRange(const EDA_ANGLE &aActual, double aMinDegrees, double aMaxDegrees)
static void checkVectorClose(const VECTOR2D &aActual, const VECTOR2D &aExpected, double aTolerance=1e-6)
static const std::vector< SET_ARC_GEOMETRY_CASE > set_arc_geometry_cases
BOOST_AUTO_TEST_CASE(SetAngleAndEnd)
static void checkVectorEqual(const VECTOR2I &aActual, const VECTOR2I &aExpected)
static const std::vector< SET_ANGLE_END_CASE > set_angle_end_cases
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
SHAPE_ARC arc2(c.m_arc2.GenerateArc())
VECTOR2I center
const SHAPE_LINE_CHAIN chain
int radius
BOOST_CHECK_PREDICATE(ArePolylineEndPointsNearCircle,(chain)(c.m_geom.m_center_point)(radius)(accuracy+epsilon))
VECTOR2I end
#define M_PI
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707