LibrePCB Developers Documentation
|
The Angle class is used to represent an angle (for example 12.75 degrees) More...
#include <angle.h>
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 °rees) |
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... | |
Angle & | makeAbs () noexcept |
Make the angle absolute (mMicrodegrees >= 0) More... | |
Angle | inverted () const noexcept |
Get an Angle object with inverted value. More... | |
Angle & | invert () noexcept |
Invert the angle. More... | |
Angle | rounded (const Angle &interval) const noexcept |
Get an Angle object rounded to a given interval. More... | |
Angle & | round (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... | |
Angle & | mapTo0_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... | |
Angle & | mapTo180deg () noexcept |
Map this Angle object to [-180..+180[ degrees. More... | |
Angle & | operator= (const Angle &rhs) |
Angle & | operator+= (const Angle &rhs) |
Angle & | operator-= (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 °rees) |
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 °rees) |
Convert an angle from a QString (in degrees) to an integer (in microdegrees) More... | |
Private Attributes | |
qint32 | mMicrodegrees |
the angle in microdegrees More... | |
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:
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...
|
inlinenoexcept |
Default Constructor.
|
inlineexplicitnoexcept |
Constructor with an angle in microdegrees.
microdegrees | The angle in microdegrees |
|
inlinenoexcept |
Destructor.
|
inlinenoexcept |
Set the angle in microdegrees.
microdegrees | The angle in microdegrees |
|
inlinenoexcept |
Set the angle in degrees.
degrees | The angle in degrees |
|
inline |
Set the angle in degrees, represented in a QString.
This method is useful to read angles from files.
degrees | See fromDeg(const QString&) |
|
inlinenoexcept |
Set the angle in radians.
radians | The angle in radians |
|
inlinenoexcept |
Get the angle in microdegrees.
|
inlinenoexcept |
|
noexcept |
Get the angle in degrees as a QString.
|
inlinenoexcept |
Get the angle in radians.
|
noexcept |
Get an Angle object with absolute value (mMicrodegrees >= 0)
|
noexcept |
Make the angle absolute (mMicrodegrees >= 0)
|
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.
|
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.
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.
interval | The interval to round to (must be > 0) |
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.
interval | The interval to round to (must be > 0) |
|
noexcept |
Get an Angle object which is mapped to [0..360[ degrees.
|
noexcept |
Map this Angle object to [0..360[ degrees.
|
noexcept |
Get an Angle object which is mapped to [-180..+180[ degrees.
|
noexcept |
Map this Angle object to [-180..+180[ degrees.
|
staticnoexcept |
Get an Angle object with a specific angle.
degrees | See setAngleDeg(qreal) |
|
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.
degrees | See setAngleDeg(const QString&) |
|
staticnoexcept |
Get an Angle object with a specific angle.
radians | See setAngleRad() |
|
inlinestaticnoexcept |
0 degrees
|
inlinestaticnoexcept |
45 degrees
|
inlinestaticnoexcept |
90 degrees
|
inlinestaticnoexcept |
135 degrees
|
inlinestaticnoexcept |
180 degrees
|
inlinestaticnoexcept |
225 degrees
|
inlinestaticnoexcept |
270 degrees
|
inlinestaticnoexcept |
315 degrees
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
|
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().
degrees | A 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 |
|
private |
the angle in microdegrees