KiCad PCB EDA Suite
EDA_ANGLE Class Reference

#include <eda_angle.h>

Public Member Functions

 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. More...
 
 EDA_ANGLE (const VECTOR2D &aVector)
 
 EDA_ANGLE (const VECTOR2I &aVector)
 
 EDA_ANGLE ()
 
double AsDegrees () const
 
int AsTenthsOfADegree () const
 
double AsRadians () const
 
bool IsCardinal () const
 
bool IsCardinal90 () const
 
bool IsZero () const
 
bool IsHorizontal () const
 
bool IsVertical () const
 
bool IsParallelTo (EDA_ANGLE aAngle) const
 
EDA_ANGLE Invert () const
 
double Sin () const
 
double Cos () const
 
double Tan () const
 
EDA_ANGLE Normalize ()
 
EDA_ANGLE Normalize90 ()
 
EDA_ANGLE Normalize180 ()
 
EDA_ANGLE Normalize720 ()
 
EDA_ANGLE KeepUpright () const
 
EDA_ANGLEoperator+= (const EDA_ANGLE &aAngle)
 
EDA_ANGLEoperator-= (const EDA_ANGLE &aAngle)
 

Static Public Member Functions

static EDA_ANGLE Arccos (double x)
 
static EDA_ANGLE Arcsin (double x)
 
static EDA_ANGLE Arctan (double x)
 
static EDA_ANGLE Arctan2 (double y, double x)
 

Static Public Attributes

static constexpr double DEGREES_TO_RADIANS = M_PI / 180.0
 
static EDA_ANGLE m_Angle0 = EDA_ANGLE( 0, DEGREES_T )
 
static EDA_ANGLE m_Angle45 = EDA_ANGLE( 45, DEGREES_T )
 
static EDA_ANGLE m_Angle90 = EDA_ANGLE( 90, DEGREES_T )
 
static EDA_ANGLE m_Angle135 = EDA_ANGLE( 135, DEGREES_T )
 
static EDA_ANGLE m_Angle180 = EDA_ANGLE( 180, DEGREES_T )
 
static EDA_ANGLE m_Angle270 = EDA_ANGLE( 270, DEGREES_T )
 
static EDA_ANGLE m_Angle360 = EDA_ANGLE( 360, DEGREES_T )
 

Private Attributes

double m_value
 value in degrees More...
 

Detailed Description

Definition at line 36 of file eda_angle.h.

Constructor & Destructor Documentation

◆ EDA_ANGLE() [1/4]

EDA_ANGLE::EDA_ANGLE ( double  aValue,
EDA_ANGLE_T  aAngleType 
)
inline

Angles can be created in degrees, 1/10ths of a degree, or radians, and read as any of the angle types.

Angle type must be explicitly specified at creation, because there is no other way of knowing what an int or a double represents.

Definition at line 46 of file eda_angle.h.

47 {
48 switch( aAngleType )
49 {
50 case RADIANS_T:
51 m_value = aValue / DEGREES_TO_RADIANS;
52 break;
53
55 m_value = aValue / 10.0;
56 break;
57
58 default:
59 m_value = aValue;
60 }
61 }
static constexpr double DEGREES_TO_RADIANS
Definition: eda_angle.h:155
double m_value
value in degrees
Definition: eda_angle.h:308
@ TENTHS_OF_A_DEGREE_T
Definition: eda_angle.h:30
@ RADIANS_T
Definition: eda_angle.h:32

References DEGREES_TO_RADIANS, m_value, RADIANS_T, and TENTHS_OF_A_DEGREE_T.

◆ EDA_ANGLE() [2/4]

EDA_ANGLE::EDA_ANGLE ( const VECTOR2D aVector)
inlineexplicit

Definition at line 63 of file eda_angle.h.

64 {
65 if( aVector.x == 0.0 && aVector.y == 0.0 )
66 {
67 m_value = 0.0;
68 }
69 else if( aVector.y == 0.0 )
70 {
71 if( aVector.x >= 0 )
72 m_value = 0.0;
73 else
74 m_value = -180.0;
75 }
76 else if( aVector.x == 0.0 )
77 {
78 if( aVector.y >= 0.0 )
79 m_value = 90.0;
80 else
81 m_value = -90.0;
82 }
83 else if( aVector.x == aVector.y )
84 {
85 if( aVector.x >= 0.0 )
86 m_value = 45.0;
87 else
88 m_value = -180.0 + 45.0;
89 }
90 else if( aVector.x == -aVector.y )
91 {
92 if( aVector.x >= 0.0 )
93 m_value = -45.0;
94 else
95 m_value = 180.0 - 45.0;
96 }
97 else
98 {
99 *this = EDA_ANGLE( atan2( aVector.y, aVector.x ), RADIANS_T );
100 }
101 }

References EDA_ANGLE(), m_value, RADIANS_T, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ EDA_ANGLE() [3/4]

EDA_ANGLE::EDA_ANGLE ( const VECTOR2I aVector)
inlineexplicit

Definition at line 103 of file eda_angle.h.

104 {
105 /* gcc is surprisingly smart in optimizing these conditions in a tree! */
106
107 if( aVector.x == 0 && aVector.y == 0 )
108 {
109 m_value = 0;
110 }
111 else if( aVector.y == 0 )
112 {
113 if( aVector.x >= 0 )
114 m_value = 0.0;
115 else
116 m_value = -180.0;
117 }
118 else if( aVector.x == 0 )
119 {
120 if( aVector.y >= 0 )
121 m_value = 90.0;
122 else
123 m_value = -90.0;
124 }
125 else if( aVector.x == aVector.y )
126 {
127 if( aVector.x >= 0 )
128 m_value = 45.0;
129 else
130 m_value = -180.0 + 45.0;
131 }
132 else if( aVector.x == -aVector.y )
133 {
134 if( aVector.x >= 0 )
135 m_value = -45.0;
136 else
137 m_value = 180.0 - 45.0;
138 }
139 else
140 {
141 *this = EDA_ANGLE( atan2( (double) aVector.y, (double) aVector.x ), RADIANS_T );
142 }
143 }

References EDA_ANGLE(), m_value, RADIANS_T, VECTOR2< T >::x, and VECTOR2< T >::y.

◆ EDA_ANGLE() [4/4]

EDA_ANGLE::EDA_ANGLE ( )
inline

Definition at line 145 of file eda_angle.h.

145 :
146 m_value( 0.0 )
147 {}

Referenced by Arccos(), Arcsin(), Arctan(), Arctan2(), EDA_ANGLE(), Invert(), IsParallelTo(), KeepUpright(), operator+=(), and operator-=().

Member Function Documentation

◆ Arccos()

static EDA_ANGLE EDA_ANGLE::Arccos ( double  x)
inlinestatic

Definition at line 238 of file eda_angle.h.

238{ return EDA_ANGLE( acos( x ), RADIANS_T ); }

References EDA_ANGLE(), and RADIANS_T.

◆ Arcsin()

static EDA_ANGLE EDA_ANGLE::Arcsin ( double  x)
inlinestatic

Definition at line 240 of file eda_angle.h.

240{ return EDA_ANGLE( asin( x ), RADIANS_T ); }

References EDA_ANGLE(), and RADIANS_T.

◆ Arctan()

static EDA_ANGLE EDA_ANGLE::Arctan ( double  x)
inlinestatic

Definition at line 242 of file eda_angle.h.

242{ return EDA_ANGLE( atan( x ), RADIANS_T ); }

References EDA_ANGLE(), and RADIANS_T.

◆ Arctan2()

static EDA_ANGLE EDA_ANGLE::Arctan2 ( double  y,
double  x 
)
inlinestatic

Definition at line 244 of file eda_angle.h.

245 {
246 return EDA_ANGLE( atan2( y, x ), RADIANS_T );
247 }

References EDA_ANGLE(), and RADIANS_T.

◆ AsDegrees()

double EDA_ANGLE::AsDegrees ( ) const
inline

Definition at line 149 of file eda_angle.h.

149{ return m_value; }

References m_value.

Referenced by std::abs(), DXF_PLOTTER::Arc(), HPGL_PLOTTER::Arc(), PS_PLOTTER::Arc(), UNIT_BINDER::ChangeAngleValue(), CADSTAR_PCB_ARCHIVE_LOADER::checkAndLogHatchCode(), CheckArcGeom(), HPGL_PLOTTER::Circle(), EDA_TEXT::Compare(), ConvertArcToPolyline(), ALTIUM_PCB::ConvertPads6ToFootprintItemOnCopper(), SHAPE_ARC::ConvertToPolyline(), PROPERTIES_FRAME::CopyPrmsFromItemToPanel(), CreateComponentsSection(), CreateShapesSection(), BOARD_ADAPTER::createTrack(), EXPORTER_PCB_VRML::ExportVrmlPadHole(), fillArcPOLY(), PCB_PLUGIN::format(), DS_DATA_MODEL_IO::format(), EDA_UNIT_UTILS::FormatAngle(), GetArcToSegmentCount(), CADSTAR_SCH_ARCHIVE_LOADER::getCadstarAngle(), PAD::GetMsgPanelInfo(), FOOTPRINT::GetOrientationDegrees(), PAD::GetOrientationDegrees(), PAD::GetThermalSpokeAngleDegrees(), ARRAY_CIRCULAR_OPTIONS::GetTransform(), hash_fp_item(), HYPERLYNX_PAD_STACK::HYPERLYNX_PAD_STACK(), idf_export_footprint(), idf_export_outline(), DIALOG_PAD_PROPERTIES::initValues(), Invert(), IsParallelTo(), KeepUpright(), CADSTAR_SCH_ARCHIVE_LOADER::loadSchematicSymbol(), CADSTAR_SCH_ARCHIVE_LOADER::loadSymbolFieldAttribute(), UNITS_PROVIDER::MessageTextFromValue(), EDA_UNIT_UTILS::UI::MessageTextFromValue(), DIALOG_MOVE_EXACT::OnPolarChanged(), DIALOG_POSITION_RELATIVE::OnPolarChanged(), operator!=(), operator*(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator<(), operator<<(), operator<=(), operator==(), operator>(), operator>=(), EAGLE_PLUGIN::orientFPText(), padsNeedUpdate(), ALTIUM_PCB::ParseComponentsBodies6Data(), BRDITEMS_PLOTTER::PlotFootprintShape(), BRDITEMS_PLOTTER::PlotPcbShape(), RENDER_3D_OPENGL::renderFootprint(), SCH_SEXPR_PLUGIN_CACHE::saveField(), GERBER_PLOTTER::selectAperture(), UNIT_BINDER::SetAngleValue(), SHAPE_ARC::sliceContainsPoint(), UNITS_PROVIDER::StringFromValue(), DXF_PLOTTER::Text(), SVG_PLOTTER::Text(), AR_MATRIX::traceArc(), TransformIsClose(), SHAPE_ARC::update_bbox(), PCB_DIM_RADIAL::updateText(), KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw(), KIGFX::PREVIEW::TWO_POINT_ASSISTANT::ViewDraw(), and zonesNeedUpdate().

◆ AsRadians()

◆ AsTenthsOfADegree()

int EDA_ANGLE::AsTenthsOfADegree ( ) const
inline

Definition at line 151 of file eda_angle.h.

151{ return KiROUND( m_value * 10.0 ); }
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:80

References KiROUND(), and m_value.

Referenced by LIB_TEXTBOX::compare(), FOOTPRINT_EDITOR_SETTINGS::FOOTPRINT_EDITOR_SETTINGS(), CADSTAR_SCH_ARCHIVE_LOADER::getCadstarAngle(), PCBNEW_SETTINGS::PCBNEW_SETTINGS(), AR_MATRIX::PlacePad(), SCH_LEGACY_PLUGIN_CACHE::saveArc(), SCH_LEGACY_PLUGIN_CACHE::saveText(), and SCH_SEXPR_PLUGIN_CACHE::saveText().

◆ Cos()

◆ Invert()

EDA_ANGLE EDA_ANGLE::Invert ( ) const
inline

Definition at line 201 of file eda_angle.h.

202 {
203 return EDA_ANGLE( -AsDegrees(), DEGREES_T );
204 }
double AsDegrees() const
Definition: eda_angle.h:149
@ DEGREES_T
Definition: eda_angle.h:31

References AsDegrees(), DEGREES_T, and EDA_ANGLE().

Referenced by PSLIKE_PLOTTER::computeTextParameters(), CreateComponentsSection(), TRANSFORM::MapAngles(), and operator-().

◆ IsCardinal()

bool EDA_ANGLE::IsCardinal ( ) const
Returns
true if angle is one of the four cardinal directions (0/90/180/270 degrees), otherwise false

Definition at line 49 of file eda_angle.cpp.

50{
51 double test = m_value;
52
53 while( test < 0.0 )
54 test += 90.0;
55
56 while( test >= 90.0 )
57 test -= 90.0;
58
59 return test == 0.0;
60}

References m_value.

Referenced by GERBER_PLOTTER::FlashPadOval(), GERBER_PLOTTER::FlashPadRect(), SCH_LINE::IsOrthogonal(), AR_MATRIX::PlacePad(), and EDA_SHAPE::rotate().

◆ IsCardinal90()

bool EDA_ANGLE::IsCardinal90 ( ) const
Returns
true if angle is one of the two cardinal directions (90/270 degrees), otherwise false

Definition at line 63 of file eda_angle.cpp.

64{
65 // return true if angle is one of the two cardinal directions (90/270 degrees),
66 double test = std::abs( m_value );
67
68 while( test >= 180.0 )
69 test -= 180.0;
70
71 return test == 90.0;
72}
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401

References std::abs(), and m_value.

Referenced by GERBER_PLOTTER::FlashPadOval(), and GERBER_PLOTTER::FlashPadRect().

◆ IsHorizontal()

◆ IsParallelTo()

bool EDA_ANGLE::IsParallelTo ( EDA_ANGLE  aAngle) const
inline

Definition at line 184 of file eda_angle.h.

185 {
186 EDA_ANGLE thisNormalized = *this;
187
188 // Normalize90 is inclusive on both ends [-90, +90]
189 // but we need it to be (-90, +90] for this test to work
190 thisNormalized.Normalize90();
191 if( thisNormalized.AsDegrees() == -90.0 )
192 thisNormalized = EDA_ANGLE( 90.0, DEGREES_T );
193
194 aAngle.Normalize90();
195 if( aAngle.AsDegrees() == -90.0 )
196 aAngle = EDA_ANGLE( 90.0, DEGREES_T );
197
198 return ( thisNormalized.AsDegrees() == aAngle.AsDegrees() );
199 }
EDA_ANGLE Normalize90()
Definition: eda_angle.h:260

References AsDegrees(), DEGREES_T, EDA_ANGLE(), and Normalize90().

Referenced by SCH_MOVE_TOOL::orthoLineDrag().

◆ IsVertical()

bool EDA_ANGLE::IsVertical ( ) const
inline

◆ IsZero()

◆ KeepUpright()

EDA_ANGLE EDA_ANGLE::KeepUpright ( ) const

Definition at line 32 of file eda_angle.cpp.

33{
34 EDA_ANGLE inAngle( *this );
35 inAngle.Normalize();
36
37 int inDegrees = inAngle.AsDegrees();
38 int outDegrees;
39
40 if( inDegrees <= 45 || inDegrees >= 315 || ( inDegrees > 135 && inDegrees <= 225 ) )
41 outDegrees = 0;
42 else
43 outDegrees = 90;
44
45 return EDA_ANGLE( outDegrees, DEGREES_T );
46}

References AsDegrees(), DEGREES_T, EDA_ANGLE(), and Normalize().

◆ Normalize()

EDA_ANGLE EDA_ANGLE::Normalize ( )
inline

Definition at line 249 of file eda_angle.h.

250 {
251 while( m_value < -0.0 )
252 m_value += 360.0;
253
254 while( m_value >= 360.0 )
255 m_value -= 360.0;
256
257 return *this;
258 }

References m_value.

Referenced by PLOTTER::Arc(), PDF_PLOTTER::Arc(), EDA_SHAPE::CalcArcAngles(), EDA_SHAPE::calcEdit(), SHAPE_ARC::Collide(), EDA_SHAPE::computeArcBBox(), SHAPE_ARC::ConstructFromStartEndCenter(), ALTIUM_PCB::ConvertArcs6ToBoardItemOnLayer(), ALTIUM_PCB::ConvertArcs6ToPcbShape(), ALTIUM_PCB::ConvertPads6ToFootprintItemOnCopper(), CreateComponentsSection(), CreateShapesSection(), GERBER_PLOTTER::FlashPadOval(), FP_TEXTBOX::GetAnchorAndOppositeCorner(), PCB_TEXTBOX::GetAnchorAndOppositeCorner(), PCB_ARC::GetArcAngleEnd(), PCB_ARC::GetArcAngleStart(), FP_TEXT::GetDrawRotation(), FP_TEXTBOX::GetDrawRotation(), CADSTAR_PCB_ARCHIVE_LOADER::getShapeFromVertex(), EDA_SHAPE::hitTest(), PCB_ARC::HitTest(), GERBER_DRAW_ITEM::HitTest(), BOX2< Vec >::Intersects(), KeepUpright(), FP_TEXT::KeepUpright(), CADSTAR_SCH_ARCHIVE_LOADER::loadShapeVertices(), DSN::SPECCTRA_DB::makeIMAGE(), TRANSFORM::MapAngles(), PCAD2KICAD::PCB_ARC::Parse(), SCH_SEXPR_PARSER::parseArc(), SCH_ALTIUM_PLUGIN::ParseArc(), FABMASTER::processArc(), PAD::Rotate(), PCB_DIMENSION_BASE::Rotate(), PAD::SetOrientation(), STROKE_PARAMS::Stroke(), GERBER_PLOTTER::ThickArc(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow(), DIALOG_TEXTBOX_PROPERTIES::TransferDataFromWindow(), DIALOG_DIMENSION_PROPERTIES::updateDimensionFromDialog(), PCB_DIM_ALIGNED::updateText(), and PCB_DIM_RADIAL::updateText().

◆ Normalize180()

◆ Normalize720()

EDA_ANGLE EDA_ANGLE::Normalize720 ( )
inline

Definition at line 282 of file eda_angle.h.

283 {
284 while( m_value < -360.0 )
285 m_value += 360.0;
286
287 while( m_value >= 360.0 )
288 m_value -= 360.0;
289
290 return *this;
291 }

References m_value.

Referenced by KIGFX::PREVIEW::ARC_ASSISTANT::ViewDraw().

◆ Normalize90()

EDA_ANGLE EDA_ANGLE::Normalize90 ( )
inline

Definition at line 260 of file eda_angle.h.

261 {
262 while( m_value < -90.0 )
263 m_value += 180.0;
264
265 while( m_value > 90.0 )
266 m_value -= 180.0;
267
268 return *this;
269 }

References m_value.

Referenced by KIGFX::PCB_PAINTER::draw(), and IsParallelTo().

◆ operator+=()

EDA_ANGLE & EDA_ANGLE::operator+= ( const EDA_ANGLE aAngle)
inline

Definition at line 295 of file eda_angle.h.

296 {
297 *this = EDA_ANGLE( AsDegrees() + aAngle.AsDegrees(), DEGREES_T );
298 return *this;
299 }

References AsDegrees(), DEGREES_T, and EDA_ANGLE().

◆ operator-=()

EDA_ANGLE & EDA_ANGLE::operator-= ( const EDA_ANGLE aAngle)
inline

Definition at line 301 of file eda_angle.h.

302 {
303 *this = EDA_ANGLE( AsDegrees() - aAngle.AsDegrees(), DEGREES_T );
304 return *this;
305 }

References AsDegrees(), DEGREES_T, and EDA_ANGLE().

◆ Sin()

◆ Tan()

double EDA_ANGLE::Tan ( ) const
inline

Definition at line 236 of file eda_angle.h.

236{ return tan( AsRadians() ); }

References AsRadians().

Member Data Documentation

◆ DEGREES_TO_RADIANS

constexpr double EDA_ANGLE::DEGREES_TO_RADIANS = M_PI / 180.0
staticconstexpr

Definition at line 155 of file eda_angle.h.

Referenced by AsRadians(), and EDA_ANGLE().

◆ m_Angle0

EDA_ANGLE EDA_ANGLE::m_Angle0 = EDA_ANGLE( 0, DEGREES_T )
static

Definition at line 311 of file eda_angle.h.

◆ m_Angle135

EDA_ANGLE EDA_ANGLE::m_Angle135 = EDA_ANGLE( 135, DEGREES_T )
static

Definition at line 314 of file eda_angle.h.

◆ m_Angle180

EDA_ANGLE EDA_ANGLE::m_Angle180 = EDA_ANGLE( 180, DEGREES_T )
static

Definition at line 315 of file eda_angle.h.

◆ m_Angle270

EDA_ANGLE EDA_ANGLE::m_Angle270 = EDA_ANGLE( 270, DEGREES_T )
static

Definition at line 316 of file eda_angle.h.

◆ m_Angle360

EDA_ANGLE EDA_ANGLE::m_Angle360 = EDA_ANGLE( 360, DEGREES_T )
static

Definition at line 317 of file eda_angle.h.

◆ m_Angle45

EDA_ANGLE EDA_ANGLE::m_Angle45 = EDA_ANGLE( 45, DEGREES_T )
static

Definition at line 312 of file eda_angle.h.

◆ m_Angle90

EDA_ANGLE EDA_ANGLE::m_Angle90 = EDA_ANGLE( 90, DEGREES_T )
static

Definition at line 313 of file eda_angle.h.

◆ m_value

double EDA_ANGLE::m_value
private

The documentation for this class was generated from the following files: