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 (C) 2023 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 <eda_shape.h>
22#include <qa_utils/geometry/geometry.h> // For KI_TEST::IsVecWithinTol
23#include <geometry/shape_arc.h> // For SHAPE_ARC::DefaultAccuracyForPCB()
24
25
26BOOST_AUTO_TEST_SUITE( EdaShape )
27
29{
30public:
31 EDA_SHAPE_MOCK( SHAPE_T aShapeType ) : EDA_SHAPE( aShapeType, 0, FILL_T::NO_FILL ){};
32};
33
34
36{
37 std::string m_CaseName;
40 double m_Angle;
43};
44
45
46static const std::vector<SET_ANGLE_END_CASE> set_angle_end_cases =
47{
48 {
49 "Issue 13626: clockwise semicircle",
50 {-428880000, 117229160 },
51 {-430060565, 113472820 },
52 180.0,
53 {-431241130, 109716480 },
54 false
55 },
56 {
57 "Issue 13626: anticlockwise arc",
58 { -431241130, 109716480 },
59 { -434923630, 112954230 },
60 -138.46654568595355,
61 { -439827050, 112936200 },
62 true
63 }
64};
65
66
67BOOST_AUTO_TEST_CASE( SetAngleAndEnd )
68{
69 for( const auto& c : set_angle_end_cases )
70 {
71 BOOST_TEST_INFO_SCOPE( c.m_CaseName );
72
74 shape.SetStart( c.m_Start );
75 shape.SetCenter( c.m_Center );
76
77 shape.SetArcAngleAndEnd( EDA_ANGLE( c.m_Angle, DEGREES_T ), true );
78
79 BOOST_CHECK_EQUAL( shape.EndsSwapped(), c.m_ExpectedStartEndSwapped );
80
81 VECTOR2I newEnd = shape.EndsSwapped() ? shape.GetStart() : shape.GetEnd();
82
83 BOOST_CHECK_PREDICATE(
84 KI_TEST::IsVecWithinTol<VECTOR2I>,
85 (newEnd) ( c.m_ExpectedEndBeforeSwap ) ( SHAPE_ARC::DefaultAccuracyForPCB() ) );
86 }
87}
88
89
90BOOST_AUTO_TEST_SUITE_END()
EDA_SHAPE_MOCK(SHAPE_T aShapeType)
void SetCenter(const VECTOR2I &aCenter)
Definition: eda_shape.cpp:470
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
void SetStart(const VECTOR2I &aStart)
Definition: eda_shape.h:124
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
bool EndsSwapped() const
Have the start and end points been swapped since they were set?
Definition: eda_shape.h:195
void SetArcAngleAndEnd(const EDA_ANGLE &aAngle, bool aCheckNegativeAngle=false)
Set the end point from the angle center and start.
Definition: eda_shape.cpp:596
static double DefaultAccuracyForPCB()
Definition: shape_arc.h:221
@ DEGREES_T
Definition: eda_angle.h:31
SHAPE_T
Definition: eda_shape.h:41
FILL_T
Definition: eda_shape.h:54
std::string m_CaseName
VECTOR2I m_ExpectedEndBeforeSwap
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(SetAngleAndEnd)
static const std::vector< SET_ANGLE_END_CASE > set_angle_end_cases