KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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
20#include <geometry/eda_angle.h>
21
22
24{
25 EDA_ANGLE inAngle( *this );
26 inAngle.Normalize();
27
28 double inDegrees = inAngle.AsDegrees();
29 double outDegrees;
30
31 if( inDegrees <= 45 || inDegrees >= 315 || ( inDegrees > 135 && inDegrees <= 225 ) )
32 outDegrees = 0;
33 else
34 outDegrees = 90;
35
36 return EDA_ANGLE( outDegrees, DEGREES_T );
37}
38
39
41{
42 if( !std::isfinite( m_value ) )
43 return false;
44
45 double test = foldToTwoPeriods( m_value, 90.0 );
46
47 while( test < 0.0 )
48 test += 90.0;
49
50 while( test >= 90.0 )
51 test -= 90.0;
52
53 return test == 0.0;
54}
55
56
58{
59 // return true if angle is one of the two cardinal directions (90/270 degrees),
60 if( !std::isfinite( m_value ) )
61 return false;
62
63 double test = foldToTwoPeriods( std::abs( m_value ), 180.0 );
64
65 while( test >= 180.0 )
66 test -= 180.0;
67
68 return test == 90.0;
69}
EDA_ANGLE Normalize()
Definition eda_angle.h:228
double AsDegrees() const
Definition eda_angle.h:115
bool IsCardinal() const
Definition eda_angle.cpp:40
EDA_ANGLE KeepUpright() const
Definition eda_angle.cpp:23
EDA_ANGLE(double aValue, EDA_ANGLE_T aAngleType)
Angles can be created in degrees, 1/10ths of a degree, or radians, and read as any of the angle types...
Definition eda_angle.h:45
static double foldToTwoPeriods(double aValue, double aPeriod)
Exactly remove whole periods from values beyond two periods, keeping the sign, so the normalization l...
Definition eda_angle.h:338
bool IsCardinal90() const
Definition eda_angle.cpp:57
double m_value
value in degrees
Definition eda_angle.h:350
@ DEGREES_T
Definition eda_angle.h:30
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition eda_angle.h:437