LibrePCB Developers Documentation
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 inverted () const noexcept
 Get an Angle object with inverted value. More...
 
Angleinvert () noexcept
 Invert the angle. More...
 
Angle rounded (const Angle &interval) const noexcept
 Get an Angle object rounded to a given interval. More...
 
Angleround (const Angle &interval) noexcept
 Round the angle to a given interval. 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...

Constructor & Destructor Documentation

◆ Angle() [1/3]

Angle ( )
inlinenoexcept

Default Constructor.

+ Here is the caller graph for this function:

◆ Angle() [2/3]

Angle ( const Angle angle)
inlinenoexcept

Copy Constructor.

Parameters
angleAnother Angle object

◆ Angle() [3/3]

Angle ( qint32  microdegrees)
inlineexplicitnoexcept

Constructor with an angle in microdegrees.

Parameters
microdegreesThe angle in microdegrees

◆ ~Angle()

~Angle ( )
inlinenoexcept

Destructor.

Member Function Documentation

◆ setAngleMicroDeg()

void setAngleMicroDeg ( qint32  microdegrees)
inlinenoexcept

Set the angle in microdegrees.

Parameters
microdegreesThe angle in microdegrees
+ Here is the caller graph for this function:

◆ setAngleDeg() [1/2]

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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAngleDeg() [2/2]

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:

◆ setAngleRad()

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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toMicroDeg()

qint32 toMicroDeg ( ) const
inlinenoexcept

Get the angle in microdegrees.

Returns
The angle in microdegrees
+ Here is the caller graph for this function:

◆ toDeg()

qreal toDeg ( ) const
inlinenoexcept

Get the Angle in degrees.

Returns
The Angle in degrees
+ Here is the caller graph for this function:

◆ toDegString()

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:

◆ toRad()

qreal toRad ( ) const
inlinenoexcept

Get the angle in radians.

Returns
The angle in radians
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ abs()

Angle abs ( ) const
noexcept

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

Returns
A new Angle object with absolute value
See also
librepcb::Angle::makeAbs()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ makeAbs()

Angle & makeAbs ( )
noexcept

Make the angle absolute (mMicrodegrees >= 0)

Returns
A reference to the modified object
See also
librepcb::Angle::abs()
+ Here is the caller graph for this function:

◆ inverted()

Angle inverted ( ) const
noexcept

Get an Angle object with inverted value.

Changes the sign while keeping the represented angle. For example, 270° is converted to -90° and vice versa. As a special case, an angle of 0° will be kept as-is.

Returns
A new Angle object with inverted value
See also
librepcb::Angle::invert()
+ Here is the call graph for this function:

◆ invert()

Angle & invert ( )
noexcept

Invert the angle.

Changes the sign while keeping the represented angle. For example, 270° is converted to -90° and vice versa. As a special case, an angle of 0° will be kept as-is.

Returns
A reference to the modified object
See also
librepcb::Angle::inverted()
+ Here is the caller graph for this function:

◆ rounded()

Angle rounded ( const Angle interval) const
noexcept

Get an Angle object rounded to a given interval.

Especially useful to get rid of very odd angles (like 179.999999°) when constructed from some inaccurate/calculated floating point input.

Parameters
intervalThe interval to round to (must be > 0)
Returns
A new Angle object with rounded value
See also
librepcb::Angle::round()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ round()

Angle & round ( const Angle interval)
noexcept

Round the angle to a given interval.

Especially useful to get rid of very odd angles (like 179.999999°) when constructed from some inaccurate/calculated floating point input.

Parameters
intervalThe interval to round to (must be > 0)
Returns
A reference to the modified object
See also
librepcb::Angle::rounded()
+ Here is the caller graph for this function:

◆ mappedTo0_360deg()

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
librepcb::Angle::mapTo0_360deg()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapTo0_360deg()

Angle & mapTo0_360deg ( )
noexcept

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

Returns
A reference to the modified object
See also
librepcb::Angle::mappedTo0_360deg()
+ Here is the caller graph for this function:

◆ mappedTo180deg()

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
librepcb::Angle::mapTo180deg()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapTo180deg()

Angle & mapTo180deg ( )
noexcept

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

Returns
A reference to the modified object
See also
librepcb::Angle::mappedTo180deg()
+ Here is the caller graph for this function:

◆ fromDeg() [1/2]

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:

◆ fromDeg() [2/2]

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:

◆ fromRad()

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:

◆ deg0()

static Angle deg0 ( )
inlinestaticnoexcept

0 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deg45()

static Angle deg45 ( )
inlinestaticnoexcept

45 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deg90()

static Angle deg90 ( )
inlinestaticnoexcept

90 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deg135()

static Angle deg135 ( )
inlinestaticnoexcept

135 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deg180()

static Angle deg180 ( )
inlinestaticnoexcept

180 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deg225()

static Angle deg225 ( )
inlinestaticnoexcept

225 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deg270()

static Angle deg270 ( )
inlinestaticnoexcept

270 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deg315()

static Angle deg315 ( )
inlinestaticnoexcept

315 degrees

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

Angle & operator= ( const Angle rhs)
inline

◆ operator+=()

Angle & operator+= ( const Angle rhs)
inline

◆ operator-=()

Angle & operator-= ( const Angle rhs)
inline

◆ operator+()

Angle operator+ ( const Angle rhs) const
inline
+ Here is the call graph for this function:

◆ operator-() [1/2]

Angle operator- ( ) const
inline
+ Here is the call graph for this function:

◆ operator-() [2/2]

Angle operator- ( const Angle rhs) const
inline
+ Here is the call graph for this function:

◆ operator*() [1/2]

Angle operator* ( const Angle rhs) const
inline
+ Here is the call graph for this function:

◆ operator*() [2/2]

Angle operator* ( qint32  rhs) const
inline
+ Here is the call graph for this function:

◆ operator/() [1/2]

Angle operator/ ( const Angle rhs) const
inline
+ Here is the call graph for this function:

◆ operator/() [2/2]

Angle operator/ ( qint32  rhs) const
inline
+ Here is the call graph for this function:

◆ operator%()

Angle operator% ( const Angle rhs) const
inline
+ Here is the call graph for this function:

◆ operator>() [1/2]

bool operator> ( const Angle rhs) const
inline

◆ operator>() [2/2]

bool operator> ( qint32  rhs) const
inline

◆ operator<() [1/2]

bool operator< ( const Angle rhs) const
inline

◆ operator<() [2/2]

bool operator< ( qint32  rhs) const
inline

◆ operator>=() [1/2]

bool operator>= ( const Angle rhs) const
inline

◆ operator>=() [2/2]

bool operator>= ( qint32  rhs) const
inline

◆ operator<=() [1/2]

bool operator<= ( const Angle rhs) const
inline

◆ operator<=() [2/2]

bool operator<= ( qint32  rhs) const
inline

◆ operator==() [1/2]

bool operator== ( const Angle rhs) const
inline

◆ operator==() [2/2]

bool operator== ( qint32  rhs) const
inline

◆ operator!=() [1/2]

bool operator!= ( const Angle rhs) const
inline

◆ operator!=() [2/2]

bool operator!= ( qint32  rhs) const
inline

◆ operator bool()

operator bool ( ) const
inlineexplicit

◆ degStringToMicrodeg()

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

◆ mMicrodegrees

qint32 mMicrodegrees
private

the angle in microdegrees


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