LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Angle Class Reference

The Angle class is used to represent an angle (for example 12.75 degrees) More...

#include <angle.h>

+ Collaboration diagram for Angle:

Public Member Functions

 Angle () noexcept
 Default Constructor. More...
 
 Angle (const Angle &angle) noexcept
 Copy Constructor. More...
 
 Angle (qint32 microdegrees) noexcept
 Constructor with an angle in microdegrees. More...
 
 ~Angle () noexcept
 Destructor. More...
 
void setAngleMicroDeg (qint32 microdegrees) noexcept
 Set the angle in microdegrees. More...
 
void setAngleDeg (qreal degrees) noexcept
 Set the angle in degrees. More...
 
void setAngleDeg (const QString &degrees)
 Set the angle in degrees, represented in a QString. More...
 
void setAngleRad (qreal radians) noexcept
 Set the angle in radians. More...
 
qint32 toMicroDeg () const noexcept
 Get the angle in microdegrees. More...
 
qreal toDeg () const noexcept
 Get the Angle in degrees. More...
 
QString toDegString () const noexcept
 Get the angle in degrees as a QString. More...
 
qreal toRad () const noexcept
 Get the angle in radians. More...
 
Angle abs () const noexcept
 Get an Angle object with absolute value (mMicrodegrees >= 0) More...
 
AnglemakeAbs () noexcept
 Make the angle absolute (mMicrodegrees >= 0) More...
 
Angle mappedTo0_360deg () const noexcept
 Get an Angle object which is mapped to [0..360[ degrees. More...
 
AnglemapTo0_360deg () noexcept
 Map this Angle object to [0..360[ degrees. More...
 
Angle mappedTo180deg () const noexcept
 Get an Angle object which is mapped to [-180..+180[ degrees. More...
 
AnglemapTo180deg () noexcept
 Map this Angle object to [-180..+180[ degrees. More...
 
Angleoperator= (const Angle &rhs)
 
Angleoperator+= (const Angle &rhs)
 
Angleoperator-= (const Angle &rhs)
 
Angle operator+ (const Angle &rhs) const
 
Angle operator- () const
 
Angle operator- (const Angle &rhs) const
 
Angle operator* (const Angle &rhs) const
 
Angle operator* (qint32 rhs) const
 
Angle operator/ (const Angle &rhs) const
 
Angle operator/ (qint32 rhs) const
 
Angle operator% (const Angle &rhs) const
 
bool operator> (const Angle &rhs) const
 
bool operator> (qint32 rhs) const
 
bool operator< (const Angle &rhs) const
 
bool operator< (qint32 rhs) const
 
bool operator>= (const Angle &rhs) const
 
bool operator>= (qint32 rhs) const
 
bool operator<= (const Angle &rhs) const
 
bool operator<= (qint32 rhs) const
 
bool operator== (const Angle &rhs) const
 
bool operator== (qint32 rhs) const
 
bool operator!= (const Angle &rhs) const
 
bool operator!= (qint32 rhs) const
 
 operator bool () const
 

Static Public Member Functions

static Angle fromDeg (qreal degrees) noexcept
 Get an Angle object with a specific angle. More...
 
static Angle fromDeg (const QString &degrees)
 Get an Angle object with a specific angle. More...
 
static Angle fromRad (qreal radians) noexcept
 Get an Angle object with a specific angle. More...
 
static Angle deg0 () noexcept
 0 degrees More...
 
static Angle deg45 () noexcept
 45 degrees More...
 
static Angle deg90 () noexcept
 90 degrees More...
 
static Angle deg135 () noexcept
 135 degrees More...
 
static Angle deg180 () noexcept
 180 degrees More...
 
static Angle deg225 () noexcept
 225 degrees More...
 
static Angle deg270 () noexcept
 270 degrees More...
 
static Angle deg315 () noexcept
 315 degrees More...
 

Static Private Member Functions

static qint32 degStringToMicrodeg (const QString &degrees)
 Convert an angle from a QString (in degrees) to an integer (in microdegrees) More...
 

Private Attributes

qint32 mMicrodegrees
 the angle in microdegrees More...
 

Detailed Description

The Angle class is used to represent an angle (for example 12.75 degrees)

This class is used to represent ALL angle values in Symbols, Schematics, Footprints, Layouts and so on. You should never use another angle type, like integer or float! It's very important to have a consistent angle type over the whole project.

An angle is normally interpreted as a CCW rotation from the horizontal line:

Y
^ /
| /
| / +60°
|/
+--------> X
Warning
Please note that the Qt Graphics Framework (QGraphicsView/QGraphicsScene) may interpret an angle as a CW rotation! So you may need to negate the angle first when used for a rotation in the graphics framework.

All angles are stored in the integer base type int32_t. The internal unit is always microdegrees, but this class provides also some converting methods to other units. The range of the angle is ]-360°...+360°[. So each angle (except 0 degrees) can be represented in two different ways (for example +270° is equal to -90°). Angles outside this range are mapped to this range (modulo), the sign will be the same as before.

If you don't want an (ambiguous) angle in the range ]-360..+360[ degrees but [0..360[ or [-180..+180[ degrees, there are converter methods available: mappedTo0_360deg(), mapTo0_360deg(), mappedTo180deg(), mapTo180deg().

There are also some static method available to build some often used angles: deg0(), deg45(), deg90() and so on...

Author
ubruhin
Date
2014-06-21

Constructor & Destructor Documentation

Angle ( )
inlinenoexcept

Default Constructor.

+ Here is the caller graph for this function:

Angle ( const Angle angle)
inlinenoexcept

Copy Constructor.

Parameters
angleAnother Angle object
Angle ( qint32  microdegrees)
inlineexplicitnoexcept

Constructor with an angle in microdegrees.

Parameters
microdegreesThe angle in microdegrees
~Angle ( )
inlinenoexcept

Destructor.

Member Function Documentation

void setAngleMicroDeg ( qint32  microdegrees)
inlinenoexcept

Set the angle in microdegrees.

Parameters
microdegreesThe angle in microdegrees
void setAngleDeg ( qreal  degrees)
inlinenoexcept

Set the angle in degrees.

Parameters
degreesThe angle in degrees
Warning
If you want to set the angle exactly to common values like 0/45/90/... degrees, you should not use this method. Please use setAngleMicroDeg() instead, because it is more accurate (no use of floating point numbers). Or you can also use the static methods deg0(), deg45() and so on.
Todo:
fmod is only for double, so not good for processors with single precision FPU...

+ Here is the caller graph for this function:

void setAngleDeg ( const QString &  degrees)
inline

Set the angle in degrees, represented in a QString.

This method is useful to read angles from files.

Parameters
degreesSee fromDeg(const QString&)
Exceptions
ExceptionIf the argument is invalid, an Exception will be thrown

+ Here is the call graph for this function:

void setAngleRad ( qreal  radians)
inlinenoexcept

Set the angle in radians.

Parameters
radiansThe angle in radians
Warning
If you want to set the angle exactly to common values like 0/45/90/... degrees, you should not use this method. Please use setAngleMicroDeg() instead, because it is more accurate (no use of floating point numbers). Or you can also use the static methods deg0(), deg45() and so on.
Todo:
fmod is only for double, so not good for processors with single precision FPU...

+ Here is the caller graph for this function:

qint32 toMicroDeg ( ) const
inlinenoexcept

Get the angle in microdegrees.

Returns
The angle in microdegrees

+ Here is the caller graph for this function:

qreal toDeg ( ) const
inlinenoexcept

Get the Angle in degrees.

Returns
The Angle in degrees

+ Here is the caller graph for this function:

QString toDegString ( ) const
noexcept

Get the angle in degrees as a QString.

Returns
The angle in degrees as a QString
Note
This method is useful to store lengths in files.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

qreal toRad ( ) const
inlinenoexcept

Get the angle in radians.

Returns
The angle in radians
Angle abs ( ) const
noexcept

Get an Angle object with absolute value (mMicrodegrees >= 0)

Returns
A new Angle object with absolute value
See Also
Angle::makeAbs()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Angle & makeAbs ( )
noexcept

Make the angle absolute (mMicrodegrees >= 0)

Returns
A reference to the modified object
See Also
Angle::abs()

+ Here is the caller graph for this function:

Angle mappedTo0_360deg ( ) const
noexcept

Get an Angle object which is mapped to [0..360[ degrees.

Returns
A new Angle object which is mapped to [0..360[ degrees
See Also
Angle::mapTo0_360deg()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Angle & mapTo0_360deg ( )
noexcept

Map this Angle object to [0..360[ degrees.

Returns
A reference to the modified object
See Also
Angle::mappedTo0_360deg()

+ Here is the caller graph for this function:

Angle mappedTo180deg ( ) const
noexcept

Get an Angle object which is mapped to [-180..+180[ degrees.

Returns
A new Angle object which is mapped to [-180..+180[ degrees
See Also
Angle::mapTo180deg()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Angle & mapTo180deg ( )
noexcept

Map this Angle object to [-180..+180[ degrees.

Returns
A reference to the modified object
See Also
Angle::mappedTo180deg()

+ Here is the caller graph for this function:

Angle fromDeg ( qreal  degrees)
staticnoexcept

Get an Angle object with a specific angle.

Parameters
degreesSee setAngleDeg(qreal)
Returns
A new Angle object with the specified angle

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Angle fromDeg ( const QString &  degrees)
static

Get an Angle object with a specific angle.

This method can be used to create an Angle object from a QString which contains a floating point number in degrees, like QString("123.456") for 123.456 degrees. The string must not depend on the locale settings (see QLocale), it have always to represent a number in the "C" locale. The maximum count of decimals after the decimal point is 6, because the 6th decimal represents one microdegree.

Parameters
degreesSee setAngleDeg(const QString&)
Returns
A new Angle object with the specified angle
Exceptions
ExceptionIf the argument is invalid, an Exception will be thrown

+ Here is the call graph for this function:

Angle fromRad ( qreal  radians)
staticnoexcept

Get an Angle object with a specific angle.

Parameters
radiansSee setAngleRad()
Returns
A new Angle object with the specified angle

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Angle deg0 ( )
inlinestaticnoexcept

0 degrees

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Angle deg45 ( )
inlinestaticnoexcept

45 degrees

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Angle deg90 ( )
inlinestaticnoexcept

90 degrees

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Angle deg135 ( )
inlinestaticnoexcept

135 degrees

+ Here is the call graph for this function:

static Angle deg180 ( )
inlinestaticnoexcept

180 degrees

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Angle deg225 ( )
inlinestaticnoexcept

225 degrees

+ Here is the call graph for this function:

static Angle deg270 ( )
inlinestaticnoexcept

270 degrees

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static Angle deg315 ( )
inlinestaticnoexcept

315 degrees

+ Here is the call graph for this function:

Angle& operator= ( const Angle rhs)
inline
Angle& operator+= ( const Angle rhs)
inline
Angle& operator-= ( const Angle rhs)
inline
Angle operator+ ( const Angle rhs) const
inline

+ Here is the call graph for this function:

Angle operator- ( ) const
inline

+ Here is the call graph for this function:

Angle operator- ( const Angle rhs) const
inline

+ Here is the call graph for this function:

Angle operator* ( const Angle rhs) const
inline

+ Here is the call graph for this function:

Angle operator* ( qint32  rhs) const
inline

+ Here is the call graph for this function:

Angle operator/ ( const Angle rhs) const
inline

+ Here is the call graph for this function:

Angle operator/ ( qint32  rhs) const
inline

+ Here is the call graph for this function:

Angle operator% ( const Angle rhs) const
inline

+ Here is the call graph for this function:

bool operator> ( const Angle rhs) const
inline
bool operator> ( qint32  rhs) const
inline
bool operator< ( const Angle rhs) const
inline
bool operator< ( qint32  rhs) const
inline
bool operator>= ( const Angle rhs) const
inline
bool operator>= ( qint32  rhs) const
inline
bool operator<= ( const Angle rhs) const
inline
bool operator<= ( qint32  rhs) const
inline
bool operator== ( const Angle rhs) const
inline
bool operator== ( qint32  rhs) const
inline
bool operator!= ( const Angle rhs) const
inline
bool operator!= ( qint32  rhs) const
inline
operator bool ( ) const
inlineexplicit
qint32 degStringToMicrodeg ( const QString &  degrees)
staticprivate

Convert an angle from a QString (in degrees) to an integer (in microdegrees)

This is a helper function for Angle(const QString&) and setAngleDeg().

Parameters
degreesA QString which contains a floating point number with maximum six decimals after the decimal point. The locale of the string have to be "C"! Example: QString("-123.456") for -123.456 degrees
Returns
The angle in microdegrees

+ Here is the caller graph for this function:

Member Data Documentation

qint32 mMicrodegrees
private

the angle in microdegrees


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