KiCad PCB EDA Suite
test_shape_arc.cpp File Reference

Go to the source code of this file.

Classes

struct  ARC_PROPERTIES
 All properties of an arc (depending on how it's constructed, some of these might be the same as the constructor params) More...
 
struct  ARC_CENTRE_PT_ANGLE
 Info to set up an arc by centre, start point and angle. More...
 
struct  ARC_CPA_CASE
 
struct  ARC_TAN_TAN_RADIUS
 Info to set up an arc by tangent to two segments and a radius. More...
 
struct  ARC_TTR_CASE
 
struct  ARC_START_END_CENTER
 Info to set up an arc start, end and center. More...
 
struct  ARC_SEC_CASE
 
struct  ARC_PT_COLLIDE_CASE
 
struct  ARC_SEG_COLLIDE_CASE
 
struct  ARC_DATA_MM
 
struct  ARC_ARC_COLLIDE_CASE
 
struct  ARC_TO_POLYLINE_CASE
 

Functions

static void CheckArcGeom (const SHAPE_ARC &aArc, const ARC_PROPERTIES &aProps, const int aSynErrIU=1)
 Check a SHAPE_ARC against a given set of geometric properties. More...
 
static void CheckArc (const SHAPE_ARC &aArc, const ARC_PROPERTIES &aProps, const int aSynErrIU=1)
 Check an arcs geometry and other class functions. More...
 
 BOOST_AUTO_TEST_CASE (NullCtor)
 Check correct handling of filter strings (as used by WX) More...
 
 BOOST_AUTO_TEST_CASE (BasicCPAGeom)
 
 BOOST_AUTO_TEST_CASE (BasicTTRGeom)
 
 BOOST_AUTO_TEST_CASE (BasicSECGeom)
 
 BOOST_AUTO_TEST_CASE (CollidePt)
 
 BOOST_AUTO_TEST_CASE (CollideSeg)
 
 BOOST_AUTO_TEST_CASE (CollideArc)
 
 BOOST_AUTO_TEST_CASE (CollideArcToShapeLineChain)
 
 BOOST_AUTO_TEST_CASE (CollideArcToPolygonApproximation)
 
bool ArePolylineEndPointsNearCircle (const SHAPE_LINE_CHAIN &aPolyline, const VECTOR2I &aCentre, int aRad, int aTolerance)
 Predicate for checking a polyline has all the points on (near) a circle of given centre and radius. More...
 
bool ArePolylineMidPointsNearCircle (const SHAPE_LINE_CHAIN &aPolyline, const VECTOR2I &aCentre, int aRad, int aTolerance)
 Predicate for checking a polyline has all the segment mid points on (near) a circle of given centre and radius. More...
 
 BOOST_AUTO_TEST_CASE (ArcToPolyline)
 

Variables

static const std::vector< ARC_CPA_CASEarc_cases
 
static const std::vector< ARC_TTR_CASEarc_ttr_cases
 
static const std::vector< ARC_SEC_CASEarc_sec_cases
 
static const std::vector< ARC_PT_COLLIDE_CASEarc_pt_collide_cases
 
static const std::vector< ARC_SEG_COLLIDE_CASEarc_seg_collide_cases
 
static const std::vector< ARC_ARC_COLLIDE_CASEarc_arc_collide_cases
 

Function Documentation

◆ ArePolylineEndPointsNearCircle()

bool ArePolylineEndPointsNearCircle ( const SHAPE_LINE_CHAIN aPolyline,
const VECTOR2I aCentre,
int  aRad,
int  aTolerance 
)

Predicate for checking a polyline has all the points on (near) a circle of given centre and radius.

Parameters
aPolylinethe polyline to check
aCentrethe circle centre
aRadthe circle radius
aTolerancethe tolerance for the endpoint-centre distance
Returns
true if predicate met

Definition at line 950 of file test_shape_arc.cpp.

952{
953 std::vector<VECTOR2I> points;
954
955 for( int i = 0; i < aPolyline.PointCount(); ++i )
956 {
957 points.push_back( aPolyline.CPoint( i ) );
958 }
959
960 return GEOM_TEST::ArePointsNearCircle( points, aCentre, aRad, aTolerance );
961}
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
bool ArePointsNearCircle(const std::vector< VECTOR2< T > > &aPoints, const VECTOR2< T > &aCentre, T aRad, T aTol)
Predicate for checking a set of points is within a certain tolerance of a circle.

References GEOM_TEST::ArePointsNearCircle(), SHAPE_LINE_CHAIN::CPoint(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by BOOST_AUTO_TEST_CASE().

◆ ArePolylineMidPointsNearCircle()

bool ArePolylineMidPointsNearCircle ( const SHAPE_LINE_CHAIN aPolyline,
const VECTOR2I aCentre,
int  aRad,
int  aTolerance 
)

Predicate for checking a polyline has all the segment mid points on (near) a circle of given centre and radius.

Parameters
aPolylinethe polyline to check
aCentrethe circle centre
aRadthe circle radius
aTolEndsthe tolerance for the midpoint-centre distance
Returns
true if predicate met

Definition at line 973 of file test_shape_arc.cpp.

975{
976 std::vector<VECTOR2I> points;
977
978 for( int i = 0; i < aPolyline.PointCount() - 1; ++i )
979 {
980 const VECTOR2I mid_pt = ( aPolyline.CPoint( i ) + aPolyline.CPoint( i + 1 ) ) / 2;
981 points.push_back( mid_pt );
982 }
983
984 return GEOM_TEST::ArePointsNearCircle( points, aCentre, aRad, aTolerance );
985}

References GEOM_TEST::ArePointsNearCircle(), SHAPE_LINE_CHAIN::CPoint(), and SHAPE_LINE_CHAIN::PointCount().

Referenced by BOOST_AUTO_TEST_CASE().

◆ BOOST_AUTO_TEST_CASE() [1/10]

BOOST_AUTO_TEST_CASE ( ArcToPolyline  )

Definition at line 988 of file test_shape_arc.cpp.

989{
990 const std::vector<ARC_TO_POLYLINE_CASE> cases = {
991 {
992 "Zero rad",
993 {
994 { 0, 0 },
995 { 0, 0 },
996 180,
997 },
998 },
999 {
1000 "Semicircle",
1001 {
1002 { 0, 0 },
1003 { -1000000, 0 },
1004 180,
1005 },
1006 },
1007 {
1008 // check that very small circles don't fall apart and that reverse angles
1009 // work too
1010 "Extremely small semicircle",
1011 {
1012 { 0, 0 },
1013 { -1000, 0 },
1014 -180,
1015 },
1016 },
1017 {
1018 // Make sure it doesn't only work for "easy" angles
1019 "Non-round geometry",
1020 {
1021 { 0, 0 },
1022 { 1234567, 0 },
1023 42.22,
1024 },
1025 },
1026 };
1027
1028 const int width = 0;
1029
1030 // Note: do not expect accuracies around 1 to work. We use integers internally so we're
1031 // liable to rounding errors. In PCBNew accuracy defaults to 5000 and we don't recommend
1032 // anything lower than 1000 (for performance reasons).
1033 const int accuracy = 100;
1034 const int epsilon = 1;
1035
1036 for( const auto& c : cases )
1037 {
1038 BOOST_TEST_CONTEXT( c.m_ctx_name )
1039 {
1040 const SHAPE_ARC this_arc{ c.m_geom.m_center_point, c.m_geom.m_start_point,
1041 EDA_ANGLE( c.m_geom.m_center_angle, DEGREES_T ), width };
1042
1043 const SHAPE_LINE_CHAIN chain = this_arc.ConvertToPolyline( accuracy );
1044
1045 BOOST_TEST_MESSAGE( "Polyline has " << chain.PointCount() << " points" );
1046
1047 // Start point (exactly) where expected
1048 BOOST_CHECK_EQUAL( chain.CPoint( 0 ), c.m_geom.m_start_point );
1049
1050 // End point (exactly) where expected
1051 BOOST_CHECK_EQUAL( chain.CPoint( -1 ), this_arc.GetP1() );
1052
1053 int radius = ( c.m_geom.m_center_point - c.m_geom.m_start_point ).EuclideanNorm();
1054
1055 // Other points within accuracy + epsilon (for rounding) of where they should be
1056 BOOST_CHECK_PREDICATE( ArePolylineEndPointsNearCircle,
1057 ( chain )( c.m_geom.m_center_point )( radius )( accuracy + epsilon ) );
1058
1059 BOOST_CHECK_PREDICATE( ArePolylineMidPointsNearCircle,
1060 ( chain )( c.m_geom.m_center_point )( radius )( accuracy + epsilon ) );
1061 }
1062 }
1063}
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
@ DEGREES_T
Definition: eda_angle.h:31
bool ArePolylineMidPointsNearCircle(const SHAPE_LINE_CHAIN &aPolyline, const VECTOR2I &aCentre, int aRad, int aTolerance)
Predicate for checking a polyline has all the segment mid points on (near) a circle of given centre a...
bool ArePolylineEndPointsNearCircle(const SHAPE_LINE_CHAIN &aPolyline, const VECTOR2I &aCentre, int aRad, int aTolerance)
Predicate for checking a polyline has all the points on (near) a circle of given centre and radius.
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:129
#define BOOST_TEST_CONTEXT(A)

References ArePolylineEndPointsNearCircle(), ArePolylineMidPointsNearCircle(), BOOST_TEST_CONTEXT, SHAPE_LINE_CHAIN::CPoint(), DEGREES_T, EuclideanNorm(), and SHAPE_LINE_CHAIN::PointCount().

◆ BOOST_AUTO_TEST_CASE() [2/10]

BOOST_AUTO_TEST_CASE ( BasicCPAGeom  )

Definition at line 329 of file test_shape_arc.cpp.

330{
331 for( const auto& c : arc_cases )
332 {
333 BOOST_TEST_CONTEXT( c.m_ctx_name )
334 {
335
336 const auto this_arc = SHAPE_ARC{ c.m_geom.m_center_point, c.m_geom.m_start_point,
337 EDA_ANGLE( c.m_geom.m_center_angle, DEGREES_T ),
338 c.m_width };
339
340 CheckArc( this_arc, c.m_properties );
341 }
342 }
343}
static void CheckArc(const SHAPE_ARC &aArc, const ARC_PROPERTIES &aProps, const int aSynErrIU=1)
Check an arcs geometry and other class functions.
static const std::vector< ARC_CPA_CASE > arc_cases

References arc_cases, BOOST_TEST_CONTEXT, CheckArc(), and DEGREES_T.

◆ BOOST_AUTO_TEST_CASE() [3/10]

BOOST_AUTO_TEST_CASE ( BasicSECGeom  )

Definition at line 529 of file test_shape_arc.cpp.

530{
531 for( const auto& c : arc_sec_cases )
532 {
533 BOOST_TEST_CONTEXT( c.m_ctx_name )
534 {
535 VECTOR2I start = c.m_geom.m_start;
536 VECTOR2I end = c.m_geom.m_end;
537 VECTOR2I center = c.m_geom.m_center;
538 bool cw = c.m_clockwise;
539
540 SHAPE_ARC this_arc;
541 this_arc.ConstructFromStartEndCenter( start, end, center, cw );
542
543 BOOST_CHECK_EQUAL( this_arc.GetArcMid(), c.m_expected_mid );
544 }
545 }
546}
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:114
SHAPE_ARC & ConstructFromStartEndCenter(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aClockwise=false, double aWidth=0)
Constructs this arc from the given start, end and center.
Definition: shape_arc.cpp:209
static const std::vector< ARC_SEC_CASE > arc_sec_cases

References arc_sec_cases, BOOST_TEST_CONTEXT, SHAPE_ARC::ConstructFromStartEndCenter(), and SHAPE_ARC::GetArcMid().

◆ BOOST_AUTO_TEST_CASE() [4/10]

BOOST_AUTO_TEST_CASE ( BasicTTRGeom  )

Definition at line 437 of file test_shape_arc.cpp.

438{
439 for( const auto& c : arc_ttr_cases )
440 {
441 BOOST_TEST_CONTEXT( c.m_ctx_name )
442 {
443 for( int testCase = 0; testCase < 8; ++testCase )
444 {
445 SEG seg1 = c.m_geom.m_segment_1;
446 SEG seg2 = c.m_geom.m_segment_2;
447 ARC_PROPERTIES props = c.m_properties;
448
449 if( testCase > 3 )
450 {
451 //Swap input segments.
452 seg1 = c.m_geom.m_segment_2;
453 seg2 = c.m_geom.m_segment_1;
454
455 //The result should swap start and end points and invert the angles:
456 props.m_end_point = c.m_properties.m_start_point;
457 props.m_start_point = c.m_properties.m_end_point;
458 props.m_start_angle = c.m_properties.m_end_angle;
459 props.m_end_angle = c.m_properties.m_start_angle;
460 props.m_center_angle = -c.m_properties.m_center_angle;
461 }
462
463 //Test all combinations of start and end points for the segments
464 if( ( testCase % 4 ) == 1 || ( testCase % 4 ) == 3 )
465 {
466 //Swap start and end points for seg1
467 VECTOR2I temp = seg1.A;
468 seg1.A = seg1.B;
469 seg1.B = temp;
470 }
471
472 if( ( testCase % 4 ) == 2 || ( testCase % 4 ) == 3 )
473 {
474 //Swap start and end points for seg2
475 VECTOR2I temp = seg2.A;
476 seg2.A = seg2.B;
477 seg2.B = temp;
478 }
479
480 const auto this_arc = SHAPE_ARC{ seg1, seg2,
481 c.m_geom.m_radius, c.m_width };
482
483 // Error of 4 IU permitted for the center and radius calculation
484 CheckArc( this_arc, props, SHAPE_ARC::MIN_PRECISION_IU );
485 }
486 }
487 }
488}
Definition: seg.h:42
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50
static const int MIN_PRECISION_IU
This is the minimum precision for all the points in a shape.
Definition: shape.h:129
All properties of an arc (depending on how it's constructed, some of these might be the same as the c...
VECTOR2I m_start_point
VECTOR2I m_end_point
static const std::vector< ARC_TTR_CASE > arc_ttr_cases

References SEG::A, arc_ttr_cases, SEG::B, BOOST_TEST_CONTEXT, CheckArc(), ARC_PROPERTIES::m_center_angle, ARC_PROPERTIES::m_end_angle, ARC_PROPERTIES::m_end_point, ARC_PROPERTIES::m_start_angle, ARC_PROPERTIES::m_start_point, and SHAPE::MIN_PRECISION_IU.

◆ BOOST_AUTO_TEST_CASE() [5/10]

BOOST_AUTO_TEST_CASE ( CollideArc  )

Definition at line 815 of file test_shape_arc.cpp.

816{
817 for( const auto& c : arc_arc_collide_cases )
818 {
819 BOOST_TEST_CONTEXT( c.m_ctx_name )
820 {
821 SHAPE_ARC arc1( c.m_arc1.GenerateArc() );
822 SHAPE_ARC arc2( c.m_arc2.GenerateArc() );
823
824
825 SHAPE_LINE_CHAIN arc1_slc( c.m_arc1.GenerateArc() );
826 arc1_slc.SetWidth( 0 );
827
828 SHAPE_LINE_CHAIN arc2_slc( c.m_arc2.GenerateArc() );
829 arc2_slc.SetWidth( 0 );
830
831 int actual = 0;
832 VECTOR2I location;
833
834 SHAPE* arc1_sh = &arc1;
835 SHAPE* arc2_sh = &arc2;
836 SHAPE* arc1_slc_sh = &arc1_slc;
837 SHAPE* arc2_slc_sh = &arc2_slc;
838
839 bool result_arc_to_arc = arc1_sh->Collide( arc2_sh, pcbIUScale.mmToIU( c.m_clearance ),
840 &actual, &location );
841
842 // For arc to chain collisions, we need to re-calculate the clearances because the
843 // SHAPE_LINE_CHAIN is zero width
844 int clearance = pcbIUScale.mmToIU( c.m_clearance ) + ( arc2.GetWidth() / 2 );
845
846 bool result_arc_to_chain =
847 arc1_sh->Collide( arc2_slc_sh, clearance, &actual, &location );
848
849 clearance = pcbIUScale.mmToIU( c.m_clearance ) + ( arc1.GetWidth() / 2 );
850 bool result_chain_to_arc =
851 arc1_slc_sh->Collide( arc2_sh, clearance, &actual, &location );
852
853 clearance = ( arc1.GetWidth() / 2 ) + ( arc2.GetWidth() / 2 );
854 bool result_chain_to_chain =
855 arc1_slc_sh->Collide( arc2_slc_sh, clearance, &actual, &location );
856
857 BOOST_CHECK_EQUAL( result_arc_to_arc, c.m_exp_result );
858 BOOST_CHECK_EQUAL( result_arc_to_chain, c.m_exp_result );
859 BOOST_CHECK_EQUAL( result_chain_to_arc, c.m_exp_result );
860 BOOST_CHECK_EQUAL( result_chain_to_chain, c.m_exp_result );
861 }
862 }
863}
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:109
An abstract shape on 2D plane.
Definition: shape.h:124
virtual bool Collide(const VECTOR2I &aP, int aClearance=0, int *aActual=nullptr, VECTOR2I *aLocation=nullptr) const
Check if the boundary of shape (this) lies closer to the point aP than aClearance,...
Definition: shape.h:179
constexpr int mmToIU(double mm) const
Definition: base_units.h:89
static const std::vector< ARC_ARC_COLLIDE_CASE > arc_arc_collide_cases

References arc_arc_collide_cases, BOOST_TEST_CONTEXT, SHAPE::Collide(), SHAPE_ARC::GetWidth(), EDA_IU_SCALE::mmToIU(), pcbIUScale, and SHAPE_LINE_CHAIN::SetWidth().

◆ BOOST_AUTO_TEST_CASE() [6/10]

BOOST_AUTO_TEST_CASE ( CollideArcToPolygonApproximation  )

Definition at line 891 of file test_shape_arc.cpp.

892{
893 SHAPE_ARC arc( VECTOR2I( 73843527, 74355869 ), VECTOR2I( 71713528, 72965869 ),
894 EDA_ANGLE( -76.36664803, DEGREES_T ), 1000000 );
895
896 // Create a polyset approximation from the arc - error outside (simulating the zone filler)
897 SHAPE_POLY_SET arcBuffer;
898 int clearance = ( arc.GetWidth() * 3 ) / 2;
899 int polygonApproximationError = SHAPE_ARC::DefaultAccuracyForPCB();
900
901 TransformArcToPolygon( arcBuffer, arc.GetP0(), arc.GetArcMid(), arc.GetP1(),
902 arc.GetWidth() + 2 * clearance,
903 polygonApproximationError, ERROR_OUTSIDE );
904
905 BOOST_REQUIRE_EQUAL( arcBuffer.OutlineCount(), 1 );
906 BOOST_CHECK_EQUAL( arcBuffer.HoleCount( 0 ), 0 );
907
908 // Make a reasonably large rectangular outline around the arc shape
909 BOX2I arcbbox = arc.BBox( clearance * 4 );
910
911 SHAPE_LINE_CHAIN zoneOutline( { arcbbox.GetPosition(),
912 arcbbox.GetPosition() + VECTOR2I( arcbbox.GetWidth(), 0 ),
913 arcbbox.GetEnd(),
914 arcbbox.GetEnd() - VECTOR2I( arcbbox.GetWidth(), 0 )
915 },
916 true );
917
918 // Create a synthetic "zone fill" polygon
919 SHAPE_POLY_SET zoneFill;
920 zoneFill.AddOutline( zoneOutline );
921 zoneFill.AddHole( arcBuffer.Outline( 0 ) );
922 zoneFill.CacheTriangulation( false );
923
924 int actual = 0;
925 VECTOR2I location;
926 int epsilon = polygonApproximationError / 10;
927
928 BOOST_CHECK_EQUAL( zoneFill.Collide( &arc, clearance + epsilon, &actual, &location ), true );
929
930 BOOST_CHECK_EQUAL( zoneFill.Collide( &arc, clearance - epsilon, &actual, &location ), false );
931}
const Vec & GetPosition() const
Definition: box2.h:184
coord_type GetWidth() const
Definition: box2.h:187
const Vec GetEnd() const
Definition: box2.h:185
static double DefaultAccuracyForPCB()
Definition: shape_arc.h:221
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
SHAPE_LINE_CHAIN & Outline(int aIndex)
int OutlineCount() const
Return the number of vertices in a given outline/hole.
void TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
@ ERROR_OUTSIDE
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590

References SHAPE_POLY_SET::AddOutline(), SHAPE_ARC::BBox(), SHAPE_ARC::DefaultAccuracyForPCB(), DEGREES_T, ERROR_OUTSIDE, SHAPE_ARC::GetArcMid(), BOX2< Vec >::GetEnd(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), BOX2< Vec >::GetPosition(), SHAPE_ARC::GetWidth(), BOX2< Vec >::GetWidth(), SHAPE_POLY_SET::HoleCount(), SHAPE_POLY_SET::Outline(), SHAPE_POLY_SET::OutlineCount(), and TransformArcToPolygon().

◆ BOOST_AUTO_TEST_CASE() [7/10]

BOOST_AUTO_TEST_CASE ( CollideArcToShapeLineChain  )

Definition at line 866 of file test_shape_arc.cpp.

867{
868 SHAPE_ARC arc( VECTOR2I( 206000000, 140110000 ), VECTOR2I( 201574617, 139229737 ),
869 VECTOR2I( 197822958, 136722959 ), 250000 );
870
871 SHAPE_LINE_CHAIN lc( { VECTOR2I( 159600000, 142500000 ), VECTOR2I( 159600000, 142600000 ),
872 VECTOR2I( 166400000, 135800000 ), VECTOR2I( 166400000, 111600000 ),
873 VECTOR2I( 190576804, 111600000 ), VECTOR2I( 192242284, 113265480 ),
874 VECTOR2I( 192255720, 113265480 ), VECTOR2I( 203682188, 124691948 ),
875 VECTOR2I( 203682188, 140332188 ), VECTOR2I( 206000000, 142650000 ) },
876 false );
877
878
879
880 SHAPE* arc_sh = &arc;
881 SHAPE* lc_sh = &lc;
882
883 BOOST_CHECK_EQUAL( arc_sh->Collide( &lc, 100000 ), true );
884 BOOST_CHECK_EQUAL( lc_sh->Collide( &arc, 100000 ), true );
885
886 SEG seg( VECTOR2I( 203682188, 124691948 ), VECTOR2I( 203682188, 140332188 ) );
887 BOOST_CHECK_EQUAL( arc.Collide( seg, 0 ), true );
888}

References SHAPE_ARC::Collide(), and SHAPE::Collide().

◆ BOOST_AUTO_TEST_CASE() [8/10]

BOOST_AUTO_TEST_CASE ( CollidePt  )

Definition at line 609 of file test_shape_arc.cpp.

610{
611 for( const auto& c : arc_pt_collide_cases )
612 {
613 BOOST_TEST_CONTEXT( c.m_ctx_name )
614 {
615 SHAPE_ARC arc( c.m_geom.m_center_point, c.m_geom.m_start_point,
616 EDA_ANGLE( c.m_geom.m_center_angle, DEGREES_T ) );
617
618 // Test a zero width arc (distance should equal the clearance)
619 BOOST_TEST_CONTEXT( "Test Clearance" )
620 {
621 int dist = -1;
622 BOOST_CHECK_EQUAL( arc.Collide( c.m_point, c.m_arc_clearance, &dist ),
623 c.m_exp_result );
624 BOOST_CHECK_EQUAL( dist, c.m_exp_distance );
625 }
626
627 // Test by changing the width of the arc (distance should equal zero)
628 BOOST_TEST_CONTEXT( "Test Width" )
629 {
630 int dist = -1;
631 arc.SetWidth( c.m_arc_clearance * 2 );
632 BOOST_CHECK_EQUAL( arc.Collide( c.m_point, 0, &dist ), c.m_exp_result );
633
634 if( c.m_exp_result )
635 BOOST_CHECK_EQUAL( dist, 0 );
636 else
637 BOOST_CHECK_EQUAL( dist, -1 );
638 }
639 }
640 }
641}
static const std::vector< ARC_PT_COLLIDE_CASE > arc_pt_collide_cases

References arc_pt_collide_cases, BOOST_TEST_CONTEXT, SHAPE_ARC::Collide(), DEGREES_T, and SHAPE_ARC::SetWidth().

◆ BOOST_AUTO_TEST_CASE() [9/10]

BOOST_AUTO_TEST_CASE ( CollideSeg  )

Definition at line 674 of file test_shape_arc.cpp.

675{
676 for( const auto& c : arc_seg_collide_cases )
677 {
678 BOOST_TEST_CONTEXT( c.m_ctx_name )
679 {
680 SHAPE_ARC arc( c.m_geom.m_center_point, c.m_geom.m_start_point,
681 EDA_ANGLE( c.m_geom.m_center_angle, DEGREES_T ) );
682
683 // Test a zero width arc (distance should equal the clearance)
684 BOOST_TEST_CONTEXT( "Test Clearance" )
685 {
686 int dist = -1;
687 BOOST_CHECK_EQUAL( arc.Collide( c.m_seg, c.m_arc_clearance, &dist ),
688 c.m_exp_result );
689 BOOST_CHECK_EQUAL( dist, c.m_exp_distance );
690 }
691
692 // Test by changing the width of the arc (distance should equal zero)
693 BOOST_TEST_CONTEXT( "Test Width" )
694 {
695 int dist = -1;
696 arc.SetWidth( c.m_arc_clearance * 2 );
697 BOOST_CHECK_EQUAL( arc.Collide( c.m_seg, 0, &dist ), c.m_exp_result );
698
699 if( c.m_exp_result )
700 BOOST_CHECK_EQUAL( dist, 0 );
701 else
702 BOOST_CHECK_EQUAL( dist, -1 );
703 }
704 }
705 }
706}
static const std::vector< ARC_SEG_COLLIDE_CASE > arc_seg_collide_cases

References arc_seg_collide_cases, BOOST_TEST_CONTEXT, SHAPE_ARC::Collide(), DEGREES_T, and SHAPE_ARC::SetWidth().

◆ BOOST_AUTO_TEST_CASE() [10/10]

BOOST_AUTO_TEST_CASE ( NullCtor  )

Check correct handling of filter strings (as used by WX)

Definition at line 135 of file test_shape_arc.cpp.

136{
137 auto arc = SHAPE_ARC();
138
139 BOOST_CHECK_EQUAL( arc.GetWidth(), 0 );
140
141 static ARC_PROPERTIES null_props{
142 { 0, 0 },
143 { 0, 0 },
144 { 0, 0 },
145 0,
146 0,
147 0,
148 0,
149 };
150
151 CheckArc( arc, null_props );
152}

References CheckArc().

◆ CheckArc()

static void CheckArc ( const SHAPE_ARC aArc,
const ARC_PROPERTIES aProps,
const int  aSynErrIU = 1 
)
static

Check an arcs geometry and other class functions.

Parameters
aArcArc to test
aPropsProperties to test against
aSynErrIUPermitted error for synthetic points and dimensions (currently radius and center)

Should have identical geom props

Definition at line 114 of file test_shape_arc.cpp.

115{
116 // Check the original arc
117 CheckArcGeom( aArc, aProps, aSynErrIU );
118
119 // Test the Clone function (also tests copy-ctor)
120 std::unique_ptr<SHAPE> new_shape{ aArc.Clone() };
121
122 BOOST_CHECK_EQUAL( new_shape->Type(), SH_ARC );
123
124 SHAPE_ARC* new_arc = dynamic_cast<SHAPE_ARC*>( new_shape.get() );
125
126 BOOST_REQUIRE( new_arc != nullptr );
127
129 CheckArcGeom( *new_arc, aProps, aSynErrIU );
130}
SHAPE * Clone() const override
Return a dynamically allocated copy of the shape.
Definition: shape_arc.h:82
@ SH_ARC
circular arc
Definition: shape.h:52
static void CheckArcGeom(const SHAPE_ARC &aArc, const ARC_PROPERTIES &aProps, const int aSynErrIU=1)
Check a SHAPE_ARC against a given set of geometric properties.

References CheckArcGeom(), SHAPE_ARC::Clone(), and SH_ARC.

Referenced by BOOST_AUTO_TEST_CASE().

◆ CheckArcGeom()

static void CheckArcGeom ( const SHAPE_ARC aArc,
const ARC_PROPERTIES aProps,
const int  aSynErrIU = 1 
)
static

Check a SHAPE_ARC against a given set of geometric properties.

Parameters
aArcArc to test
aPropsProperties to test against
aSynErrIUPermitted error for synthetic points and dimensions (currently radius and center)

Check the chord agrees

All arcs are solid

Collisions will be checked elsewhere.

Definition at line 59 of file test_shape_arc.cpp.

60{
61 // Angular error - note this can get quite large for very small arcs,
62 // as the integral position rounding has a relatively greater effect
63 const double angle_tol_deg = 1.0;
64
65 // Position error - rounding to nearest integer
66 const int pos_tol = 1;
67
68 BOOST_CHECK_PREDICATE( KI_TEST::IsVecWithinTol<VECTOR2I>,
69 ( aProps.m_start_point )( aProps.m_start_point )( pos_tol ) );
70
71 BOOST_CHECK_PREDICATE( KI_TEST::IsVecWithinTol<VECTOR2I>,
72 ( aArc.GetP1() )( aProps.m_end_point )( pos_tol ) );
73
74 BOOST_CHECK_PREDICATE( KI_TEST::IsVecWithinTol<VECTOR2I>,
75 ( aArc.GetCenter() )( aProps.m_center_point )( aSynErrIU ) );
76
77 BOOST_CHECK_PREDICATE( KI_TEST::IsWithinWrapped<double>,
78 ( aArc.GetCentralAngle().AsDegrees() )( aProps.m_center_angle )( 360.0 )( angle_tol_deg ) );
79
80 BOOST_CHECK_PREDICATE( KI_TEST::IsWithinWrapped<double>,
81 ( aArc.GetStartAngle().AsDegrees() )( aProps.m_start_angle )( 360.0 )( angle_tol_deg ) );
82
83 BOOST_CHECK_PREDICATE( KI_TEST::IsWithinWrapped<double>,
84 ( aArc.GetEndAngle().AsDegrees() )( aProps.m_end_angle )( 360.0 )( angle_tol_deg ) );
85
86 BOOST_CHECK_PREDICATE( KI_TEST::IsWithin<double>,
87 ( aArc.GetRadius() )( aProps.m_radius )( aSynErrIU ) );
88
90 const auto chord = aArc.GetChord();
91
92 BOOST_CHECK_PREDICATE( KI_TEST::IsVecWithinTol<VECTOR2I>,
93 ( chord.A )( aProps.m_start_point )( pos_tol ) );
94
95 BOOST_CHECK_PREDICATE( KI_TEST::IsVecWithinTol<VECTOR2I>,
96 ( chord.B )( aProps.m_end_point )( pos_tol ) );
97
99 BOOST_CHECK_EQUAL( aArc.IsSolid(), true );
100
101 BOOST_CHECK_PREDICATE( KI_TEST::IsBoxWithinTol<BOX2I>,
102 ( aArc.BBox() )( aProps.m_bbox )( pos_tol ) );
103
105}
double AsDegrees() const
Definition: eda_angle.h:149
EDA_ANGLE GetCentralAngle() const
Definition: shape_arc.cpp:448
SEG GetChord() const
Definition: shape_arc.h:187
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Definition: shape_arc.cpp:355
EDA_ANGLE GetEndAngle() const
Definition: shape_arc.cpp:426
const VECTOR2I & GetP1() const
Definition: shape_arc.h:113
double GetRadius() const
Definition: shape_arc.cpp:464
EDA_ANGLE GetStartAngle() const
Definition: shape_arc.cpp:419
VECTOR2I GetCenter() const
Definition: shape_arc.cpp:433
bool IsSolid() const override
Definition: shape_arc.h:162
VECTOR2I m_center_point

References EDA_ANGLE::AsDegrees(), SHAPE_ARC::BBox(), SHAPE_ARC::GetCenter(), SHAPE_ARC::GetCentralAngle(), SHAPE_ARC::GetChord(), SHAPE_ARC::GetEndAngle(), SHAPE_ARC::GetP1(), SHAPE_ARC::GetRadius(), SHAPE_ARC::GetStartAngle(), SHAPE_ARC::IsSolid(), ARC_PROPERTIES::m_bbox, ARC_PROPERTIES::m_center_angle, ARC_PROPERTIES::m_center_point, ARC_PROPERTIES::m_end_angle, ARC_PROPERTIES::m_end_point, ARC_PROPERTIES::m_radius, ARC_PROPERTIES::m_start_angle, and ARC_PROPERTIES::m_start_point.

Referenced by CheckArc().

Variable Documentation

◆ arc_arc_collide_cases

const std::vector<ARC_ARC_COLLIDE_CASE> arc_arc_collide_cases
static

Definition at line 741 of file test_shape_arc.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ arc_cases

const std::vector<ARC_CPA_CASE> arc_cases
static

Definition at line 184 of file test_shape_arc.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ arc_pt_collide_cases

const std::vector<ARC_PT_COLLIDE_CASE> arc_pt_collide_cases
static

Definition at line 560 of file test_shape_arc.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ arc_sec_cases

const std::vector<ARC_SEC_CASE> arc_sec_cases
static
Initial value:
= {
{ "180 deg, clockwise", { { 100, 0 }, { 0, 0 }, { 50, 0 } }, true, { 50, -50 } },
{ "180 deg, anticlockwise", { { 100, 0 }, { 0, 0 }, { 50, 0 } }, false, { 50, 50 } },
{ "180 deg flipped, clockwise", { { 0, 0 }, { 100, 0 }, { 50, 0 } }, true, { 50, 50 } },
{ "180 deg flipped, anticlockwise", { { 0, 0 }, { 100, 0 }, { 50, 0 } }, false, { 50, -50 } },
{ "90 deg, clockwise", { { -100, 0 }, { 0, 100 }, { 0, 0 } }, true, { -71, 71 } },
{ "90 deg, anticlockwise", { { -100, 0 }, { 0, 100 }, { 0, 0 } }, false, { 71, -71 } },
}

Definition at line 519 of file test_shape_arc.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ arc_seg_collide_cases

const std::vector<ARC_SEG_COLLIDE_CASE> arc_seg_collide_cases
static
Initial value:
= {
{ "0 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 100, 0 }, { 50, 0 } }, true, 0 },
{ "90 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 0, 100 }, { 0, 50 } }, true, 0 },
{ "180 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { -100, 0 }, { -50, 0 } }, true, 0 },
{ "270 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 0, -100 }, { 0, -50 } }, true, 0 },
{ "45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, 71 }, { 35, 35 } }, true, 0 },
{ "-45 deg ", { { 0, 0 }, { 100, 0 }, 270.0 }, 0, { { 71, -71 }, { 35, -35 } }, false, -1 },
{ "seg inside arc start", { { 0, 0 }, { 71, -71 }, 90.0 },
10, { { 90, 0 }, { -35, 0 } }, true, 10 },
{ "seg inside arc end", { { 0, 0 }, { 71, -71 }, 90.0 },
10, { { -35, 0 }, { 90, 0 } }, true, 10 },
{ "large diameter arc", { { 172367922, 82282076 }, { 162530000, 92120000 }, -45.0 },
433300, { { 162096732, 92331236 }, { 162096732, 78253268 } }, true, 433268 },
}

Definition at line 658 of file test_shape_arc.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ arc_ttr_cases

const std::vector<ARC_TTR_CASE> arc_ttr_cases
static

Definition at line 374 of file test_shape_arc.cpp.

Referenced by BOOST_AUTO_TEST_CASE().