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 (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 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25
26#include <geometry/eda_angle.h>
27
28
29BOOST_AUTO_TEST_SUITE( EdaAngle )
30
31
33{
34 double m_Angle;
35
36 // Expected:
42};
43
44
45static const std::vector<EDA_ANGLE_NORMALISE_CASE> normalize_cases =
46{
47 //@todo: should we unify the ranges of Normalize180, Normalize720 to be the same
48 // as Normalize90 (i.e. inclusive of both sides of the range)?
49
50 // [0,360) (-360,0] [-90,90] (-180,180] [-360,360)
51 // Original Normalized NormNeg Norm90 Norm180 Norm720
52 { 90.0, 90.0, -270.0, 90.0, 90.0, 90.0 },
53 { -90.0, 270.0, -90.0, -90.0, -90.0, -90.0 },
54 { 135.0, 135.0, -225.0, -45.0, 135.0, 135.0 },
55 { -135.0, 225.0, -135.0, 45.0, -135.0, -135.0 },
56 { 180.0, 180.0, -180.0, 0.0, 180.0, 180.0 },
57 { -180.0, 180.0, -180.0, 0.0, 180.0, -180.0 },
58 { 360.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
59 { -360.0, 0.0, 0.0, 0.0, 0.0, -360.0 },
60 { 390.0, 30.0, -330.0, 30.0, 30.0, 30.0 },
61 { -390.0, 330.0, -30.0, -30.0, -30.0, -30.0 },
62 { 720.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
63 { -720.0, 0.0, 0.0, 0.0, 0.0, -360.0 },
64};
65
66
68{
69 for( const auto& c : normalize_cases )
70 {
71 BOOST_TEST_INFO_SCOPE( "Original angle: " << c.m_Angle << " degrees" );
72
73 EDA_ANGLE normalized( c.m_Angle, DEGREES_T );
74 normalized.Normalize();
75
76 EDA_ANGLE normalizedNegative( c.m_Angle, DEGREES_T );
77 normalizedNegative.NormalizeNegative();
78
79 EDA_ANGLE normalized90( c.m_Angle, DEGREES_T );
80 normalized90.Normalize90();
81
82 EDA_ANGLE normalized180( c.m_Angle, DEGREES_T );
83 normalized180.Normalize180();
84
85 EDA_ANGLE normalized720( c.m_Angle, DEGREES_T );
86 normalized720.Normalize720();
87
88 BOOST_CHECK_EQUAL( normalized.AsDegrees(), c.m_ExpNormalized );
89 BOOST_CHECK_EQUAL( normalizedNegative.AsDegrees(), c.m_ExpNormalizedNegative );
90 BOOST_CHECK_EQUAL( normalized90.AsDegrees(), c.m_ExpNormalized90 );
91 BOOST_CHECK_EQUAL( normalized180.AsDegrees(), c.m_ExpNormalized180 );
92 BOOST_CHECK_EQUAL( normalized720.AsDegrees(), c.m_ExpNormalized720 );
93 }
94}
95
96
97BOOST_AUTO_TEST_CASE( ConstantAngles )
98{
99 BOOST_CHECK_EQUAL( ANGLE_0.AsDegrees(), 0.0 );
100 BOOST_CHECK_EQUAL( ANGLE_45.AsDegrees(), 45.0 );
101 BOOST_CHECK_EQUAL( ANGLE_90.AsDegrees(), 90.0 );
102 BOOST_CHECK_EQUAL( ANGLE_135.AsDegrees(), 135.0 );
103 BOOST_CHECK_EQUAL( ANGLE_180.AsDegrees(), 180.0 );
104 BOOST_CHECK_EQUAL( ANGLE_270.AsDegrees(), 270.0 );
105 BOOST_CHECK_EQUAL( ANGLE_360.AsDegrees(), 360.0 );
106
107 BOOST_CHECK_EQUAL( ANGLE_HORIZONTAL.AsDegrees(), 0.0 );
108 BOOST_CHECK_EQUAL( ANGLE_VERTICAL.AsDegrees(), 90.0 );
109 BOOST_CHECK_EQUAL( FULL_CIRCLE.AsDegrees(), 360.0 );
110}
111
112
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
EDA_ANGLE NormalizeNegative()
Definition: eda_angle.h:238
EDA_ANGLE Normalize90()
Definition: eda_angle.h:249
double AsDegrees() const
Definition: eda_angle.h:113
EDA_ANGLE Normalize180()
Definition: eda_angle.h:260
EDA_ANGLE Normalize720()
Definition: eda_angle.h:271
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:401
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
@ DEGREES_T
Definition: eda_angle.h:31
static constexpr EDA_ANGLE ANGLE_VERTICAL
Definition: eda_angle.h:398
static constexpr EDA_ANGLE ANGLE_HORIZONTAL
Definition: eda_angle.h:397
static constexpr EDA_ANGLE ANGLE_45
Definition: eda_angle.h:402
static constexpr EDA_ANGLE ANGLE_270
Definition: eda_angle.h:406
static constexpr EDA_ANGLE FULL_CIRCLE
Definition: eda_angle.h:399
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:407
static constexpr EDA_ANGLE ANGLE_180
Definition: eda_angle.h:405
static constexpr EDA_ANGLE ANGLE_135
Definition: eda_angle.h:404
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()