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 (C) 2021-2022 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 along
17 * with this program. If not, see <http://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 double test = m_value;
43
44 while( test < 0.0 )
45 test += 90.0;
46
47 while( test >= 90.0 )
48 test -= 90.0;
49
50 return test == 0.0;
51}
52
53
55{
56 // return true if angle is one of the two cardinal directions (90/270 degrees),
57 double test = std::abs( m_value );
58
59 while( test >= 180.0 )
60 test -= 180.0;
61
62 return test == 90.0;
63}
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
double AsDegrees() const
Definition: eda_angle.h:113
bool IsCardinal() const
Definition: eda_angle.cpp:40
EDA_ANGLE KeepUpright() const
Definition: eda_angle.cpp:23
bool IsCardinal90() const
Definition: eda_angle.cpp:54
double m_value
value in degrees
Definition: eda_angle.h:305
@ DEGREES_T
Definition: eda_angle.h:31
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:390