KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_eda_angle.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 2
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 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <geometry/eda_angle.h>
23
24
25BOOST_AUTO_TEST_SUITE( EdaAngle )
26
27
39
40
41static const std::vector<EDA_ANGLE_NORMALISE_CASE> normalize_cases =
42{
43 //@todo: should we unify the ranges of Normalize180, Normalize720 to be the same
44 // as Normalize90 (i.e. inclusive of both sides of the range)?
45
46 // [0,360) (-360,0] [-90,90] (-180,180] [-360,360)
47 // Original Normalized NormNeg Norm90 Norm180 Norm720
48 { 90.0, 90.0, -270.0, 90.0, 90.0, 90.0 },
49 { -90.0, 270.0, -90.0, -90.0, -90.0, -90.0 },
50 { 135.0, 135.0, -225.0, -45.0, 135.0, 135.0 },
51 { -135.0, 225.0, -135.0, 45.0, -135.0, -135.0 },
52 { 180.0, 180.0, -180.0, 0.0, 180.0, 180.0 },
53 { -180.0, 180.0, -180.0, 0.0, 180.0, -180.0 },
54 { 360.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
55 { -360.0, 0.0, 0.0, 0.0, 0.0, -360.0 },
56 { 390.0, 30.0, -330.0, 30.0, 30.0, 30.0 },
57 { -390.0, 330.0, -30.0, -30.0, -30.0, -30.0 },
58 { 720.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
59 { -720.0, 0.0, 0.0, 0.0, 0.0, -360.0 },
60};
61
62
64{
65 for( const auto& c : normalize_cases )
66 {
67 BOOST_TEST_INFO_SCOPE( "Original angle: " << c.m_Angle << " degrees" );
68
69 EDA_ANGLE normalized( c.m_Angle, DEGREES_T );
70 normalized.Normalize();
71
72 EDA_ANGLE normalizedNegative( c.m_Angle, DEGREES_T );
73 normalizedNegative.NormalizeNegative();
74
75 EDA_ANGLE normalized90( c.m_Angle, DEGREES_T );
76 normalized90.Normalize90();
77
78 EDA_ANGLE normalized180( c.m_Angle, DEGREES_T );
79 normalized180.Normalize180();
80
81 EDA_ANGLE normalized720( c.m_Angle, DEGREES_T );
82 normalized720.Normalize720();
83
84 BOOST_CHECK_EQUAL( normalized.AsDegrees(), c.m_ExpNormalized );
85 BOOST_CHECK_EQUAL( normalizedNegative.AsDegrees(), c.m_ExpNormalizedNegative );
86 BOOST_CHECK_EQUAL( normalized90.AsDegrees(), c.m_ExpNormalized90 );
87 BOOST_CHECK_EQUAL( normalized180.AsDegrees(), c.m_ExpNormalized180 );
88 BOOST_CHECK_EQUAL( normalized720.AsDegrees(), c.m_ExpNormalized720 );
89 }
90}
91
92
93BOOST_AUTO_TEST_CASE( ConstantAngles )
94{
95 BOOST_CHECK_EQUAL( ANGLE_0.AsDegrees(), 0.0 );
96 BOOST_CHECK_EQUAL( ANGLE_45.AsDegrees(), 45.0 );
97 BOOST_CHECK_EQUAL( ANGLE_90.AsDegrees(), 90.0 );
98 BOOST_CHECK_EQUAL( ANGLE_135.AsDegrees(), 135.0 );
99 BOOST_CHECK_EQUAL( ANGLE_180.AsDegrees(), 180.0 );
100 BOOST_CHECK_EQUAL( ANGLE_270.AsDegrees(), 270.0 );
101 BOOST_CHECK_EQUAL( ANGLE_360.AsDegrees(), 360.0 );
102
103 BOOST_CHECK_EQUAL( ANGLE_HORIZONTAL.AsDegrees(), 0.0 );
104 BOOST_CHECK_EQUAL( ANGLE_VERTICAL.AsDegrees(), 90.0 );
105 BOOST_CHECK_EQUAL( FULL_CIRCLE.AsDegrees(), 360.0 );
106}
107
108
EDA_ANGLE Normalize()
Definition eda_angle.h:229
EDA_ANGLE NormalizeNegative()
Definition eda_angle.h:246
EDA_ANGLE Normalize90()
Definition eda_angle.h:257
double AsDegrees() const
Definition eda_angle.h:116
EDA_ANGLE Normalize180()
Definition eda_angle.h:268
EDA_ANGLE Normalize720()
Definition eda_angle.h:279
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
@ DEGREES_T
Definition eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition eda_angle.h:408
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition eda_angle.h:407
static constexpr EDA_ANGLE ANGLE_45
Definition eda_angle.h:412
static constexpr EDA_ANGLE ANGLE_270
Definition eda_angle.h:416
static constexpr EDA_ANGLE FULL_CIRCLE
Definition eda_angle.h:409
static constexpr EDA_ANGLE ANGLE_360
Definition eda_angle.h:417
static constexpr EDA_ANGLE ANGLE_180
Definition eda_angle.h:415
static constexpr EDA_ANGLE ANGLE_135
Definition eda_angle.h:414
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(Normalize)
static const std::vector< EDA_ANGLE_NORMALISE_CASE > normalize_cases
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")