LibrePCB Developers Documentation
|
The Length class is used to represent a length (for example 12.75 millimeters) More...
#include <length.h>
Public Member Functions | |
constexpr | Length () noexcept |
Default Constructor. | |
constexpr | Length (const Length &length) noexcept |
Copy Constructor. | |
constexpr | Length (LengthBase_t nanometers) noexcept |
Constructor with length in nanometers. | |
~Length ()=default | |
Destructor. | |
void | setLengthNm (LengthBase_t nanometers) noexcept |
Set the length in nanometers. | |
void | setLengthMm (qreal millimeters) |
Set the length in millimeters. | |
void | setLengthMm (const QString &millimeters) |
Set the length in millimeters, represented in a QString. | |
void | setLengthInch (qreal inches) |
Set the length in inches. | |
void | setLengthMil (qreal mils) |
Set the length in mils (1/1000 inch) | |
void | setLengthPx (qreal pixels) |
Set the length in pixels (from QGraphics* objects) | |
LengthBase_t | toNm () const noexcept |
Get the length in nanometers. | |
QString | toNmString () const noexcept |
Get the length in nanometers as a QString. | |
qreal | toMicrometers () const noexcept |
Get the length in micrometers. | |
qreal | toMm () const noexcept |
Get the length in millimeters. | |
QString | toMmString () const noexcept |
Get the length in millimeters as a QString. | |
qreal | toInch () const noexcept |
Get the length in inches. | |
qreal | toMil () const noexcept |
Get the length in mils (1/1000 inches) | |
qreal | toPx () const noexcept |
Get the length in pixels (for QGraphics* objects) | |
Length | abs () const noexcept |
Get a Length object with absolute value (mNanometers >= 0) | |
Length & | makeAbs () noexcept |
Make the length absolute (mNanometers >= 0) | |
Length | mappedToGrid (const Length &gridInterval) const noexcept |
Get a Length object which is mapped to a specific grid interval. | |
Length & | mapToGrid (const Length &gridInterval) noexcept |
Map this Length object to a specific grid interval. | |
Length | scaled (qreal factor) const noexcept |
Get a Length object which is scaled with a specific factor. | |
Length & | scale (qreal factor) noexcept |
Scale this Length object with a specific factor. | |
Length & | operator= (const Length &rhs) |
Length & | operator+= (const Length &rhs) |
Length & | operator-= (const Length &rhs) |
Length & | operator*= (const Length &rhs) |
Length & | operator*= (LengthBase_t rhs) |
Length & | operator/= (const Length &rhs) |
Length & | operator/= (LengthBase_t rhs) |
Length | operator+ (const Length &rhs) const |
Length | operator- () const |
Length | operator- (const Length &rhs) const |
Length | operator* (const Length &rhs) const |
Length | operator* (LengthBase_t rhs) const |
Length | operator/ (const Length &rhs) const |
Length | operator/ (LengthBase_t rhs) const |
Length | operator% (const Length &rhs) const |
constexpr bool | operator> (const Length &rhs) const |
constexpr bool | operator> (LengthBase_t rhs) const |
constexpr bool | operator< (const Length &rhs) const |
constexpr bool | operator< (LengthBase_t rhs) const |
constexpr bool | operator>= (const Length &rhs) const |
constexpr bool | operator>= (LengthBase_t rhs) const |
constexpr bool | operator<= (const Length &rhs) const |
constexpr bool | operator<= (LengthBase_t rhs) const |
constexpr bool | operator== (const Length &rhs) const |
constexpr bool | operator== (LengthBase_t rhs) const |
constexpr bool | operator!= (const Length &rhs) const |
constexpr bool | operator!= (LengthBase_t rhs) const |
Static Public Member Functions | |
static bool | isValidMm (qreal millimeters) noexcept |
Check if a float value in millimeters is in the allowed range. | |
static Length | fromMm (qreal millimeters, const Length &gridInterval=Length(0)) |
Get a Length object with a specific length and map it to a specific grid. | |
static Length | fromMm (const QString &millimeters, const Length &gridInterval=Length(0)) |
Get a Length object with a specific length and map it to a specific grid. | |
static Length | fromInch (qreal inches, const Length &gridInterval=Length(0)) |
Get a Length object with a specific length and map it to a specific grid. | |
static Length | fromMil (qreal mils, const Length &gridInterval=Length(0)) |
Get a Length object with a specific length and map it to a specific grid. | |
static Length | fromPx (qreal pixels, const Length &gridInterval=Length(0)) |
Get a Length object with a specific length and map it to a specific grid. | |
static Length | min () noexcept |
Get the smallest possible length value. | |
static Length | max () noexcept |
Get the highest possible length value. | |
Private Member Functions | |
void | setLengthFromFloat (qreal nanometers) |
Set the length from a floating point number in nanometers. | |
Static Private Member Functions | |
static bool | checkRange (qreal nanometers, bool doThrow=false) |
Check if a float value in nanometers is in the allowed range. | |
static LengthBase_t | mapNmToGrid (LengthBase_t nanometers, const Length &gridInterval) noexcept |
Map a length in nanometers to a grid interval in nanometers. | |
static LengthBase_t | mmStringToNm (const QString &millimeters) |
Convert a length from a QString (in millimeters) to an integer (in nanometers) | |
Private Attributes | |
LengthBase_t | mNanometers |
the length in nanometers | |
Static Private Attributes | |
static constexpr LengthBase_t | sNmPerInch = 25400000 |
1 inch = 25.4mm | |
static constexpr LengthBase_t | sNmPerMil = 25400 |
1 inch = 25.4mm | |
static constexpr LengthBase_t | sPixelsPerInch |
72 dpi for the QGraphics* objects | |
static constexpr qreal | sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch |
static constexpr qreal | sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch |
The Length class is used to represent a length (for example 12.75 millimeters)
This class is used to represent ALL length values in Symbols, Schematics, Footprints, Layouts and so on. You should never use another length type, like integer or float! It's very important to have a consistent length type over the whole project.
All lengths are stored in the integer base type librepcb::LengthBase_t. The internal unit is always nanometers, but this class provides also some converting methods to other units. Read the documentation of librepcb::LengthBase_t for more details.
|
inlineconstexprnoexcept |
Default Constructor.
The length will be initialized with zero nanometers.
Copy Constructor.
length | Another Length object |
|
inlineconstexprnoexcept |
Constructor with length in nanometers.
nanometers | The length in nanometers |
|
default |
Destructor.
|
inlinenoexcept |
Set the length in nanometers.
nanometers | The length in nanometers |
|
inline |
Set the length in millimeters.
millimeters | The length in millimeters |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
|
inline |
Set the length in millimeters, represented in a QString.
millimeters | The length in millimeters in a QString with locale "C" |
Exception | If the string is not valid or the number is out of range, an Exception will be thrown |
|
inline |
Set the length in inches.
inches | The length in inches |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
|
inline |
Set the length in mils (1/1000 inch)
mils | The length in mils |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
|
inline |
Set the length in pixels (from QGraphics* objects)
pixels | The length in pixels, from a QGraphics* object |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
|
inlinenoexcept |
Get the length in nanometers.
|
inlinenoexcept |
Get the length in nanometers as a QString.
|
inlinenoexcept |
Get the length in micrometers.
|
inlinenoexcept |
Get the length in millimeters.
|
noexcept |
Get the length in millimeters as a QString.
|
inlinenoexcept |
Get the length in inches.
|
inlinenoexcept |
Get the length in mils (1/1000 inches)
|
inlinenoexcept |
Get the length in pixels (for QGraphics* objects)
|
noexcept |
Get a Length object with absolute value (mNanometers >= 0)
|
noexcept |
Make the length absolute (mNanometers >= 0)
Get a Length object which is mapped to a specific grid interval.
gridInterval | The grid interval in nanometers (e.g. 2540000 for 2.54mm). If this parameter is zero, this method will do nothing. |
Map this Length object to a specific grid interval.
gridInterval | The grid interval in nanometers (e.g. 2540000 for 2.54mm). If this parameter is zero, this method will do nothing. |
|
noexcept |
Get a Length object which is scaled with a specific factor.
factor | The scale factor (1.0 does nothing) |
|
noexcept |
Scale this Length object with a specific factor.
factor | The scale factor (1.0 does nothing) |
|
inlinestaticnoexcept |
Check if a float value in millimeters is in the allowed range.
millimeters | The value to check |
true | Value is valid, can construct a Length from it. |
false | Value is invalid, constructing a Length would throw. |
Get a Length object with a specific length and map it to a specific grid.
millimeters | See setLengthMm(qreal) |
gridInterval | See mapToGrid() |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
Get a Length object with a specific length and map it to a specific grid.
This method can be used to create a Length object from a QString which contains a floating point number in millimeters, like QString("123.456") for 123.456 millimeters. 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 nanometer.
millimeters | See setLengthMm(const QString&) |
gridInterval | See mapToGrid() |
Get a Length object with a specific length and map it to a specific grid.
inches | See setLengthInch() |
gridInterval | See mapToGrid() |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
Get a Length object with a specific length and map it to a specific grid.
mils | See setLengthMil() |
gridInterval | See mapToGrid() |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
Get a Length object with a specific length and map it to a specific grid.
pixels | See setLengthPx() |
gridInterval | See mapToGrid() |
RangeError | If the argument is out of range, a RangeError exception will be thrown |
|
staticnoexcept |
Get the smallest possible length value.
|
staticnoexcept |
Get the highest possible length value.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
private |
Set the length from a floating point number in nanometers.
This is a helper method for the setLength*() methods.
nanometers | A floating point number in nanometers. |
|
staticprivate |
Check if a float value in nanometers is in the allowed range.
nanometers | The value to check |
doThrow | If true, throw a librepcb::RangeError if out of range instead of returning the result |
true | Value is valid, can construct a Length from it. |
false | Value is invalid, constructing a Length would throw. |
|
staticprivatenoexcept |
Map a length in nanometers to a grid interval in nanometers.
This is a helper function for mapToGrid().
nanometers | The length we want to map to the grid |
gridInterval | The grid interval |
|
staticprivate |
Convert a length from a QString (in millimeters) to an integer (in nanometers)
This is a helper function for Length(const QString&) and setLengthMm().
millimeters | 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("-1234.56") for -1234.56mm |
|
private |
the length in nanometers
|
staticconstexprprivate |
1 inch = 25.4mm
|
staticconstexprprivate |
1 inch = 25.4mm
|
staticconstexprprivate |
72 dpi for the QGraphics* objects
|
staticconstexprprivate |
|
staticconstexprprivate |