LibrePCB Developers Documentation
length.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_LENGTH_H
21#define LIBREPCB_CORE_LENGTH_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../exceptions.h"
27#include "../qtcompat.h"
28
29#include <type_safe/constrained_type.hpp>
30
31#include <QtCore>
32
33/*******************************************************************************
34 * Namespace / Forward Declarations
35 ******************************************************************************/
36namespace librepcb {
37
38/*******************************************************************************
39 * Typedefs
40 ******************************************************************************/
41
59#ifdef USE_32BIT_LENGTH_UNITS
60typedef qint32 LengthBase_t;
61#else
62typedef qint64 LengthBase_t;
63#endif
64
65/*******************************************************************************
66 * Class Length
67 ******************************************************************************/
68
83class Length {
84 Q_DECLARE_TR_FUNCTIONS(Length)
85
86public:
87 // Constructors / Destructor
88
94 constexpr Length() noexcept : Length(0) {}
95
101 constexpr Length(const Length& length) noexcept
102 : mNanometers(length.mNanometers) {}
103
109 constexpr Length(LengthBase_t nanometers) noexcept
110 : mNanometers(nanometers) {}
111
115 ~Length() = default;
116
117 // Setters
118
124 void setLengthNm(LengthBase_t nanometers) noexcept {
125 mNanometers = nanometers;
126 }
127
141 void setLengthMm(qreal millimeters) { setLengthFromFloat(millimeters * 1e6); }
142
156 void setLengthMm(const QString& millimeters) {
157 mNanometers = mmStringToNm(millimeters);
158 }
159
173 void setLengthInch(qreal inches) { setLengthFromFloat(inches * sNmPerInch); }
174
188 void setLengthMil(qreal mils) { setLengthFromFloat(mils * sNmPerMil); }
189
205 void setLengthPx(qreal pixels) { setLengthFromFloat(pixels * sNmPerPixel); }
206
207 // Conversions
208
214 LengthBase_t toNm() const noexcept { return mNanometers; }
215
222 QString toNmString() const noexcept { return QString::number(toNm()); }
223
231 qreal toMicrometers() const noexcept { return (qreal)mNanometers / 1e3; }
232
240 qreal toMm() const noexcept { return (qreal)mNanometers / 1e6; }
241
253 QString toMmString() const noexcept;
254
262 qreal toInch() const noexcept { return (qreal)mNanometers / sNmPerInch; }
263
271 qreal toMil() const noexcept { return (qreal)mNanometers / sNmPerMil; }
272
283 qreal toPx() const noexcept { return mNanometers * sPixelsPerNm; }
284
285 // General Methods
286
294 Length abs() const noexcept;
295
303 Length& makeAbs() noexcept;
304
315 Length mappedToGrid(const Length& gridInterval) const noexcept;
316
327 Length& mapToGrid(const Length& gridInterval) noexcept;
328
341 Length scaled(qreal factor) const noexcept;
342
355 Length& scale(qreal factor) noexcept;
356
357 // Static Functions
358
367 static bool isValidMm(qreal millimeters) noexcept {
368 return checkRange(millimeters * 1e6);
369 }
370
389 static Length fromMm(qreal millimeters,
390 const Length& gridInterval = Length(0));
391
417 static Length fromMm(const QString& millimeters,
418 const Length& gridInterval = Length(0));
419
438 static Length fromInch(qreal inches, const Length& gridInterval = Length(0));
439
458 static Length fromMil(qreal mils, const Length& gridInterval = Length(0));
459
481 static Length fromPx(qreal pixels, const Length& gridInterval = Length(0));
482
488 static Length min() noexcept;
489
495 static Length max() noexcept;
496
497 // Operators
498 Length& operator=(const Length& rhs) {
499 mNanometers = rhs.mNanometers;
500 return *this;
501 }
502 Length& operator+=(const Length& rhs) {
504 return *this;
505 }
506 Length& operator-=(const Length& rhs) {
508 return *this;
509 }
510 Length& operator*=(const Length& rhs) {
512 return *this;
513 }
515 mNanometers *= rhs;
516 return *this;
517 }
518 Length& operator/=(const Length& rhs) {
520 return *this;
521 }
523 mNanometers /= rhs;
524 return *this;
525 }
526 Length operator+(const Length& rhs) const {
527 return Length(mNanometers + rhs.mNanometers);
528 }
529 Length operator-() const { return Length(-mNanometers); }
530 Length operator-(const Length& rhs) const {
531 return Length(mNanometers - rhs.mNanometers);
532 }
533 Length operator*(const Length& rhs) const {
534 return Length(mNanometers * rhs.mNanometers);
535 }
536 Length operator*(LengthBase_t rhs) const { return Length(mNanometers * rhs); }
537 Length operator/(const Length& rhs) const {
538 return Length(mNanometers / rhs.mNanometers);
539 }
540 Length operator/(LengthBase_t rhs) const { return Length(mNanometers / rhs); }
541 Length operator%(const Length& rhs) const {
542 return Length(mNanometers % rhs.mNanometers);
543 }
544 constexpr bool operator>(const Length& rhs) const {
545 return mNanometers > rhs.mNanometers;
546 }
547 constexpr bool operator>(LengthBase_t rhs) const { return mNanometers > rhs; }
548 constexpr bool operator<(const Length& rhs) const {
549 return mNanometers < rhs.mNanometers;
550 }
551 constexpr bool operator<(LengthBase_t rhs) const { return mNanometers < rhs; }
552 constexpr bool operator>=(const Length& rhs) const {
553 return mNanometers >= rhs.mNanometers;
554 }
555 constexpr bool operator>=(LengthBase_t rhs) const {
556 return mNanometers >= rhs;
557 }
558 constexpr bool operator<=(const Length& rhs) const {
559 return mNanometers <= rhs.mNanometers;
560 }
561 constexpr bool operator<=(LengthBase_t rhs) const {
562 return mNanometers <= rhs;
563 }
564 constexpr bool operator==(const Length& rhs) const {
565 return mNanometers == rhs.mNanometers;
566 }
567 constexpr bool operator==(LengthBase_t rhs) const {
568 return mNanometers == rhs;
569 }
570 constexpr bool operator!=(const Length& rhs) const {
571 return mNanometers != rhs.mNanometers;
572 }
573 constexpr bool operator!=(LengthBase_t rhs) const {
574 return mNanometers != rhs;
575 }
576
577private:
578 // Private Functions
579
593 void setLengthFromFloat(qreal nanometers);
594
595 // Private Static Functions
596
607 static bool checkRange(qreal nanometers, bool doThrow = false);
608
620 static LengthBase_t mapNmToGrid(LengthBase_t nanometers,
621 const Length& gridInterval) noexcept;
622
635 static LengthBase_t mmStringToNm(const QString& millimeters);
636
637 // Private Member Variables
639
640 // Static Length Converting Constants
641 static constexpr LengthBase_t sNmPerInch = 25400000;
642 static constexpr LengthBase_t sNmPerMil = 25400;
643 static constexpr LengthBase_t sPixelsPerInch =
644 72;
645 static constexpr qreal sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch;
646 static constexpr qreal sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch;
647};
648
649/*******************************************************************************
650 * Non-Member Functions
651 ******************************************************************************/
652
653inline QDataStream& operator<<(QDataStream& stream, const Length& length) {
654 stream << length.toMm();
655 return stream;
656}
657
658inline QDebug operator<<(QDebug stream, const Length& length) {
659 stream << QString("Length(%1mm)").arg(length.toMm());
660 return stream;
661}
662
663inline QtCompat::Hash qHash(const Length& key,
664 QtCompat::Hash seed = 0) noexcept {
665 return ::qHash(key.toNm(), seed);
666}
667
668/*******************************************************************************
669 * Class UnsignedLength
670 ******************************************************************************/
671
673 template <typename Value, typename Predicate>
674 static constexpr auto verify(Value&& val, const Predicate& p) ->
675 typename std::decay<Value>::type {
676 return p(val) ? std::forward<Value>(val)
677 : (throw RuntimeError(__FILE__, __LINE__,
678 Length::tr("Value must be >= 0!")),
679 std::forward<Value>(val));
680 }
681};
682
684 constexpr bool operator()(const Length& l) const noexcept { return l >= 0; }
685};
686
695 type_safe::constrained_type<Length, UnsignedLengthConstraint,
697
699 const UnsignedLength& rhs) noexcept {
700 return UnsignedLength(*lhs +
701 *rhs); // will not throw as long as there's no overflow
702}
703
705 const UnsignedLength& rhs) noexcept {
706 lhs = lhs + rhs; // will not throw as long as there's no overflow
707 return lhs;
708}
709
710inline Length operator*(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
711 return (*lhs) * rhs;
712}
713inline Length operator/(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
714 return (*lhs) / rhs;
715}
716inline Length operator+(const Length& lhs, const UnsignedLength& rhs) noexcept {
717 return lhs + *rhs;
718}
719inline Length operator+(const UnsignedLength& lhs, const Length& rhs) noexcept {
720 return *lhs + rhs;
721}
722inline Length operator-(const Length& lhs, const UnsignedLength& rhs) noexcept {
723 return lhs - *rhs;
724}
725inline Length operator-(const UnsignedLength& lhs, const Length& rhs) noexcept {
726 return *lhs - rhs;
727}
728inline Length operator-(const UnsignedLength& lhs) noexcept {
729 return -(*lhs);
730}
731inline bool operator>(const UnsignedLength& lhs, const Length& rhs) noexcept {
732 return (*lhs) > rhs;
733}
734inline bool operator>(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
735 return (*lhs) > rhs;
736}
737inline bool operator>=(const UnsignedLength& lhs, const Length& rhs) noexcept {
738 return (*lhs) >= rhs;
739}
740inline bool operator>=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
741 return (*lhs) >= rhs;
742}
743inline bool operator<(const UnsignedLength& lhs, const Length& rhs) noexcept {
744 return (*lhs) < rhs;
745}
746inline bool operator<(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
747 return (*lhs) < rhs;
748}
749inline bool operator<=(const UnsignedLength& lhs, const Length& rhs) noexcept {
750 return (*lhs) <= rhs;
751}
752inline bool operator<=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
753 return (*lhs) <= rhs;
754}
755inline bool operator==(const UnsignedLength& lhs, const Length& rhs) noexcept {
756 return (*lhs) == rhs;
757}
758inline bool operator==(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
759 return (*lhs) == rhs;
760}
761inline bool operator!=(const UnsignedLength& lhs, const Length& rhs) noexcept {
762 return (*lhs) != rhs;
763}
764inline bool operator!=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
765 return (*lhs) != rhs;
766}
767
768inline QDataStream& operator<<(QDataStream& stream,
769 const UnsignedLength& length) {
770 stream << length->toMm();
771 return stream;
772}
773
774inline QDebug operator<<(QDebug stream, const UnsignedLength& length) {
775 stream << QString("UnsignedLength(%1mm)").arg(length->toMm());
776 return stream;
777}
778
780 QtCompat::Hash seed = 0) noexcept {
781 return ::qHash(key->toNm(), seed);
782}
783
784/*******************************************************************************
785 * Class PositiveLength
786 ******************************************************************************/
787
789 template <typename Value, typename Predicate>
790 static constexpr auto verify(Value&& val, const Predicate& p) ->
791 typename std::decay<Value>::type {
792 return p(val) ? std::forward<Value>(val)
793 : (throw RuntimeError(__FILE__, __LINE__,
794 Length::tr("Value must be > 0!")),
795 std::forward<Value>(val));
796 }
797};
798
800 constexpr bool operator()(const Length& l) const noexcept { return l > 0; }
801};
802
811 type_safe::constrained_type<Length, PositiveLengthConstraint,
813
815 return UnsignedLength(*l);
816}
817
819 const PositiveLength& rhs) noexcept {
820 return PositiveLength(*lhs +
821 *rhs); // will not throw as long as there's no overflow
822}
823
825 const UnsignedLength& rhs) noexcept {
826 return PositiveLength(*lhs +
827 *rhs); // will not throw as long as there's no overflow
828}
829
831 const PositiveLength& rhs) noexcept {
832 return PositiveLength(*lhs +
833 *rhs); // will not throw as long as there's no overflow
834}
835
837 const PositiveLength& rhs) noexcept {
838 lhs = lhs + rhs; // will not throw as long as there's no overflow
839 return lhs;
840}
841
843 const UnsignedLength& rhs) noexcept {
844 lhs = lhs + rhs; // will not throw as long as there's no overflow
845 return lhs;
846}
847
849 const PositiveLength& rhs) noexcept {
850 lhs = positiveToUnsigned(
851 lhs + rhs); // will not throw as long as there's no overflow
852 return lhs;
853}
854
855inline Length operator*(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
856 return (*lhs) * rhs;
857}
858inline Length operator/(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
859 return (*lhs) / rhs;
860}
861inline Length operator+(const Length& lhs, const PositiveLength& rhs) noexcept {
862 return lhs + *rhs;
863}
864inline Length operator+(const PositiveLength& lhs, const Length& rhs) noexcept {
865 return *lhs + rhs;
866}
867inline Length operator-(const Length& lhs, const PositiveLength& rhs) noexcept {
868 return lhs - *rhs;
869}
870inline Length operator-(const PositiveLength& lhs, const Length& rhs) noexcept {
871 return *lhs - rhs;
872}
874 const PositiveLength& rhs) noexcept {
875 return *lhs - *rhs;
876}
878 const UnsignedLength& rhs) noexcept {
879 return *lhs - *rhs;
880}
881inline Length operator-(const PositiveLength& lhs) noexcept {
882 return -(*lhs);
883}
884inline bool operator>(const UnsignedLength& lhs,
885 const PositiveLength& rhs) noexcept {
886 return (*lhs) > (*rhs);
887}
888inline bool operator>(const PositiveLength& lhs,
889 const UnsignedLength& rhs) noexcept {
890 return (*lhs) > (*rhs);
891}
892inline bool operator>(const PositiveLength& lhs, const Length& rhs) noexcept {
893 return (*lhs) > rhs;
894}
895inline bool operator>(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
896 return (*lhs) > rhs;
897}
898inline bool operator>=(const UnsignedLength& lhs,
899 const PositiveLength& rhs) noexcept {
900 return (*lhs) >= (*rhs);
901}
902inline bool operator>=(const PositiveLength& lhs,
903 const UnsignedLength& rhs) noexcept {
904 return (*lhs) >= (*rhs);
905}
906inline bool operator>=(const PositiveLength& lhs, const Length& rhs) noexcept {
907 return (*lhs) >= rhs;
908}
909inline bool operator>=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
910 return (*lhs) >= rhs;
911}
912inline bool operator<(const UnsignedLength& lhs,
913 const PositiveLength& rhs) noexcept {
914 return (*lhs) < (*rhs);
915}
916inline bool operator<(const PositiveLength& lhs,
917 const UnsignedLength& rhs) noexcept {
918 return (*lhs) < (*rhs);
919}
920inline bool operator<(const PositiveLength& lhs, const Length& rhs) noexcept {
921 return (*lhs) < rhs;
922}
923inline bool operator<(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
924 return (*lhs) < rhs;
925}
926inline bool operator<=(const UnsignedLength& lhs,
927 const PositiveLength& rhs) noexcept {
928 return (*lhs) <= (*rhs);
929}
930inline bool operator<=(const PositiveLength& lhs,
931 const UnsignedLength& rhs) noexcept {
932 return (*lhs) <= (*rhs);
933}
934inline bool operator<=(const PositiveLength& lhs, const Length& rhs) noexcept {
935 return (*lhs) <= rhs;
936}
937inline bool operator<=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
938 return (*lhs) <= rhs;
939}
940inline bool operator==(const UnsignedLength& lhs,
941 const PositiveLength& rhs) noexcept {
942 return (*lhs) == (*rhs);
943}
944inline bool operator==(const PositiveLength& lhs,
945 const UnsignedLength& rhs) noexcept {
946 return (*lhs) == (*rhs);
947}
948inline bool operator==(const PositiveLength& lhs, const Length& rhs) noexcept {
949 return (*lhs) == rhs;
950}
951inline bool operator==(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
952 return (*lhs) == rhs;
953}
954inline bool operator!=(const UnsignedLength& lhs,
955 const PositiveLength& rhs) noexcept {
956 return (*lhs) != (*rhs);
957}
958inline bool operator!=(const PositiveLength& lhs,
959 const UnsignedLength& rhs) noexcept {
960 return (*lhs) != (*rhs);
961}
962inline bool operator!=(const PositiveLength& lhs, const Length& rhs) noexcept {
963 return (*lhs) != rhs;
964}
965inline bool operator!=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
966 return (*lhs) != rhs;
967}
968
969inline QDataStream& operator<<(QDataStream& stream,
970 const PositiveLength& length) {
971 stream << length->toMm();
972 return stream;
973}
974
975inline QDebug operator<<(QDebug stream, const PositiveLength& length) {
976 stream << QString("PositiveLength(%1mm)").arg(length->toMm());
977 return stream;
978}
979
981 QtCompat::Hash seed = 0) noexcept {
982 return ::qHash(key->toNm(), seed);
983}
984
985/*******************************************************************************
986 * Class Point3D
987 ******************************************************************************/
988
989using Point3D = std::tuple<Length, Length, Length>;
990
991QDebug operator<<(QDebug stream, const Point3D& obj);
992
993/*******************************************************************************
994 * End of File
995 ******************************************************************************/
996
997} // namespace librepcb
998
999Q_DECLARE_METATYPE(librepcb::Length)
1000
1001#endif
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
constexpr bool operator!=(const Length &rhs) const
Definition: length.h:570
void setLengthMil(qreal mils)
Set the length in mils (1/1000 inch)
Definition: length.h:188
Length & operator/=(const Length &rhs)
Definition: length.h:518
Length & mapToGrid(const Length &gridInterval) noexcept
Map this Length object to a specific grid interval.
Definition: length.cpp:75
Length & makeAbs() noexcept
Make the length absolute (mNanometers >= 0)
Definition: length.cpp:61
void setLengthMm(const QString &millimeters)
Set the length in millimeters, represented in a QString.
Definition: length.h:156
Length & operator*=(LengthBase_t rhs)
Definition: length.h:514
constexpr bool operator==(LengthBase_t rhs) const
Definition: length.h:567
Length & operator-=(const Length &rhs)
Definition: length.h:506
Length operator-() const
Definition: length.h:529
static constexpr LengthBase_t sNmPerMil
1 inch = 25.4mm
Definition: length.h:642
Length operator/(const Length &rhs) const
Definition: length.h:537
constexpr bool operator!=(LengthBase_t rhs) const
Definition: length.h:573
constexpr bool operator<=(const Length &rhs) const
Definition: length.h:558
Length abs() const noexcept
Get a Length object with absolute value (mNanometers >= 0)
Definition: length.cpp:55
constexpr bool operator<(LengthBase_t rhs) const
Definition: length.h:551
Length mappedToGrid(const Length &gridInterval) const noexcept
Get a Length object which is mapped to a specific grid interval.
Definition: length.cpp:70
constexpr bool operator==(const Length &rhs) const
Definition: length.h:564
static LengthBase_t mmStringToNm(const QString &millimeters)
Convert a length from a QString (in millimeters) to an integer (in nanometers)
Definition: length.cpp:200
constexpr bool operator>=(const Length &rhs) const
Definition: length.h:552
void setLengthPx(qreal pixels)
Set the length in pixels (from QGraphics* objects)
Definition: length.h:205
QString toMmString() const noexcept
Get the length in millimeters as a QString.
Definition: length.cpp:47
Length & operator+=(const Length &rhs)
Definition: length.h:502
Length operator*(LengthBase_t rhs) const
Definition: length.h:536
qreal toMm() const noexcept
Get the length in millimeters.
Definition: length.h:240
static constexpr LengthBase_t sNmPerInch
1 inch = 25.4mm
Definition: length.h:641
constexpr Length() noexcept
Default Constructor.
Definition: length.h:94
qreal toInch() const noexcept
Get the length in inches.
Definition: length.h:262
Length & scale(qreal factor) noexcept
Scale this Length object with a specific factor.
Definition: length.cpp:85
void setLengthFromFloat(qreal nanometers)
Set the length from a floating point number in nanometers.
Definition: length.cpp:136
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.
Definition: length.cpp:94
constexpr bool operator>=(LengthBase_t rhs) const
Definition: length.h:555
Length & operator/=(LengthBase_t rhs)
Definition: length.h:522
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.
Definition: length.cpp:106
Length & operator*=(const Length &rhs)
Definition: length.h:510
qreal toMicrometers() const noexcept
Get the length in micrometers.
Definition: length.h:231
Length operator/(LengthBase_t rhs) const
Definition: length.h:540
static bool isValidMm(qreal millimeters) noexcept
Check if a float value in millimeters is in the allowed range.
Definition: length.h:367
void setLengthNm(LengthBase_t nanometers) noexcept
Set the length in nanometers.
Definition: length.h:124
static LengthBase_t mapNmToGrid(LengthBase_t nanometers, const Length &gridInterval) noexcept
Map a length in nanometers to a grid interval in nanometers.
Definition: length.cpp:160
static constexpr LengthBase_t sPixelsPerInch
72 dpi for the QGraphics* objects
Definition: length.h:643
Length operator-(const Length &rhs) const
Definition: length.h:530
constexpr bool operator>(const Length &rhs) const
Definition: length.h:544
static Length min() noexcept
Get the smallest possible length value.
Definition: length.cpp:124
static bool checkRange(qreal nanometers, bool doThrow=false)
Check if a float value in nanometers is in the allowed range.
Definition: length.cpp:147
void setLengthInch(qreal inches)
Set the length in inches.
Definition: length.h:173
Length operator*(const Length &rhs) const
Definition: length.h:533
constexpr bool operator<(const Length &rhs) const
Definition: length.h:548
constexpr bool operator>(LengthBase_t rhs) const
Definition: length.h:547
qreal toPx() const noexcept
Get the length in pixels (for QGraphics* objects)
Definition: length.h:283
LengthBase_t mNanometers
the length in nanometers
Definition: length.h:638
QString toNmString() const noexcept
Get the length in nanometers as a QString.
Definition: length.h:222
static constexpr qreal sNmPerPixel
Definition: length.h:645
constexpr Length(LengthBase_t nanometers) noexcept
Constructor with length in nanometers.
Definition: length.h:109
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.
Definition: length.cpp:112
void setLengthMm(qreal millimeters)
Set the length in millimeters.
Definition: length.h:141
Length scaled(qreal factor) const noexcept
Get a Length object which is scaled with a specific factor.
Definition: length.cpp:80
constexpr Length(const Length &length) noexcept
Copy Constructor.
Definition: length.h:101
qreal toMil() const noexcept
Get the length in mils (1/1000 inches)
Definition: length.h:271
LengthBase_t toNm() const noexcept
Get the length in nanometers.
Definition: length.h:214
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.
Definition: length.cpp:118
~Length()=default
Destructor.
static Length max() noexcept
Get the highest possible length value.
Definition: length.cpp:128
static constexpr qreal sPixelsPerNm
Definition: length.h:646
Length operator%(const Length &rhs) const
Definition: length.h:541
Length operator+(const Length &rhs) const
Definition: length.h:526
constexpr bool operator<=(LengthBase_t rhs) const
Definition: length.h:561
uint Hash
Return type of Qt's qHash() function.
Definition: qtcompat.h:58
The RuntimeError class.
Definition: exceptions.h:218
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:86
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
bool operator>=(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:737
std::tuple< Length, Length, Length > Point3D
Definition: length.h:989
qint64 LengthBase_t
This type is the ONLY base type to store all lengths (always in nanometers)!
Definition: length.h:62
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:92
static bool operator<(const BoardGerberExport::LayerPair &lhs, const BoardGerberExport::LayerPair &rhs) noexcept
Definition: boardgerberexport.cpp:62
Length operator-(const Length &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:722
Length operator*(const UnsignedLength &lhs, LengthBase_t rhs) noexcept
Definition: length.h:710
UnsignedLength positiveToUnsigned(const PositiveLength &l) noexcept
Definition: length.h:814
UnsignedLength operator+(const UnsignedLength &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:698
Length operator/(const UnsignedLength &lhs, LengthBase_t rhs) noexcept
Definition: length.h:713
UnsignedLength & operator+=(UnsignedLength &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:704
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:109
bool operator<=(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:749
QtCompat::Hash qHash(const PositiveLength &key, QtCompat::Hash seed=0) noexcept
Definition: length.h:980
bool operator>(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:731
Definition: length.h:799
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:800
Definition: length.h:788
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:790
Definition: length.h:683
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:684
Definition: length.h:672
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:674