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 
28 #include <type_safe/constrained_type.hpp>
29 
30 #include <QtCore>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 /*******************************************************************************
38  * Typedefs
39  ******************************************************************************/
40 
58 #ifdef USE_32BIT_LENGTH_UNITS
59 typedef qint32 LengthBase_t;
60 #else
61 typedef qint64 LengthBase_t;
62 #endif
63 
64 /*******************************************************************************
65  * Class Length
66  ******************************************************************************/
67 
82 class Length {
83  Q_DECLARE_TR_FUNCTIONS(Length)
84 
85 public:
86  // Constructors / Destructor
87 
93  constexpr Length() noexcept : Length(0) {}
94 
100  constexpr Length(const Length& length) noexcept
101  : mNanometers(length.mNanometers) {}
102 
108  constexpr Length(LengthBase_t nanometers) noexcept
109  : mNanometers(nanometers) {}
110 
114  ~Length() = default;
115 
116  // Setters
117 
123  void setLengthNm(LengthBase_t nanometers) noexcept {
124  mNanometers = nanometers;
125  }
126 
140  void setLengthMm(qreal millimeters) { setLengthFromFloat(millimeters * 1e6); }
141 
155  void setLengthMm(const QString& millimeters) {
156  mNanometers = mmStringToNm(millimeters);
157  }
158 
172  void setLengthInch(qreal inches) { setLengthFromFloat(inches * sNmPerInch); }
173 
187  void setLengthMil(qreal mils) { setLengthFromFloat(mils * sNmPerMil); }
188 
204  void setLengthPx(qreal pixels) { setLengthFromFloat(pixels * sNmPerPixel); }
205 
206  // Conversions
207 
213  LengthBase_t toNm() const noexcept { return mNanometers; }
214 
221  QString toNmString() const noexcept { return QString::number(toNm()); }
222 
230  qreal toMicrometers() const noexcept { return (qreal)mNanometers / 1e3; }
231 
239  qreal toMm() const noexcept { return (qreal)mNanometers / 1e6; }
240 
252  QString toMmString() const noexcept;
253 
261  qreal toInch() const noexcept { return (qreal)mNanometers / sNmPerInch; }
262 
270  qreal toMil() const noexcept { return (qreal)mNanometers / sNmPerMil; }
271 
282  qreal toPx() const noexcept { return mNanometers * sPixelsPerNm; }
283 
284  // General Methods
285 
293  Length abs() const noexcept;
294 
302  Length& makeAbs() noexcept;
303 
314  Length mappedToGrid(const Length& gridInterval) const noexcept;
315 
326  Length& mapToGrid(const Length& gridInterval) noexcept;
327 
340  Length scaled(qreal factor) const noexcept;
341 
354  Length& scale(qreal factor) noexcept;
355 
356  // Static Functions
357 
376  static Length fromMm(qreal millimeters,
377  const Length& gridInterval = Length(0));
378 
404  static Length fromMm(const QString& millimeters,
405  const Length& gridInterval = Length(0));
406 
425  static Length fromInch(qreal inches, const Length& gridInterval = Length(0));
426 
445  static Length fromMil(qreal mils, const Length& gridInterval = Length(0));
446 
468  static Length fromPx(qreal pixels, const Length& gridInterval = Length(0));
469 
475  static Length min() noexcept;
476 
482  static Length max() noexcept;
483 
484  // Operators
485  Length& operator=(const Length& rhs) {
486  mNanometers = rhs.mNanometers;
487  return *this;
488  }
489  Length& operator+=(const Length& rhs) {
490  mNanometers += rhs.mNanometers;
491  return *this;
492  }
493  Length& operator-=(const Length& rhs) {
494  mNanometers -= rhs.mNanometers;
495  return *this;
496  }
497  Length& operator*=(const Length& rhs) {
498  mNanometers *= rhs.mNanometers;
499  return *this;
500  }
501  Length& operator*=(LengthBase_t rhs) {
502  mNanometers *= rhs;
503  return *this;
504  }
505  Length& operator/=(const Length& rhs) {
506  mNanometers /= rhs.mNanometers;
507  return *this;
508  }
509  Length& operator/=(LengthBase_t rhs) {
510  mNanometers /= rhs;
511  return *this;
512  }
513  Length operator+(const Length& rhs) const {
514  return Length(mNanometers + rhs.mNanometers);
515  }
516  Length operator-() const { return Length(-mNanometers); }
517  Length operator-(const Length& rhs) const {
518  return Length(mNanometers - rhs.mNanometers);
519  }
520  Length operator*(const Length& rhs) const {
521  return Length(mNanometers * rhs.mNanometers);
522  }
523  Length operator*(LengthBase_t rhs) const { return Length(mNanometers * rhs); }
524  Length operator/(const Length& rhs) const {
525  return Length(mNanometers / rhs.mNanometers);
526  }
527  Length operator/(LengthBase_t rhs) const { return Length(mNanometers / rhs); }
528  Length operator%(const Length& rhs) const {
529  return Length(mNanometers % rhs.mNanometers);
530  }
531  constexpr bool operator>(const Length& rhs) const {
532  return mNanometers > rhs.mNanometers;
533  }
534  constexpr bool operator>(LengthBase_t rhs) const { return mNanometers > rhs; }
535  constexpr bool operator<(const Length& rhs) const {
536  return mNanometers < rhs.mNanometers;
537  }
538  constexpr bool operator<(LengthBase_t rhs) const { return mNanometers < rhs; }
539  constexpr bool operator>=(const Length& rhs) const {
540  return mNanometers >= rhs.mNanometers;
541  }
542  constexpr bool operator>=(LengthBase_t rhs) const {
543  return mNanometers >= rhs;
544  }
545  constexpr bool operator<=(const Length& rhs) const {
546  return mNanometers <= rhs.mNanometers;
547  }
548  constexpr bool operator<=(LengthBase_t rhs) const {
549  return mNanometers <= rhs;
550  }
551  constexpr bool operator==(const Length& rhs) const {
552  return mNanometers == rhs.mNanometers;
553  }
554  constexpr bool operator==(LengthBase_t rhs) const {
555  return mNanometers == rhs;
556  }
557  constexpr bool operator!=(const Length& rhs) const {
558  return mNanometers != rhs.mNanometers;
559  }
560  constexpr bool operator!=(LengthBase_t rhs) const {
561  return mNanometers != rhs;
562  }
563 
564 private:
565  // Private Functions
566 
580  void setLengthFromFloat(qreal nanometers);
581 
582  // Private Static Functions
583 
595  static LengthBase_t mapNmToGrid(LengthBase_t nanometers,
596  const Length& gridInterval) noexcept;
597 
610  static LengthBase_t mmStringToNm(const QString& millimeters);
611 
612  // Private Member Variables
613  LengthBase_t mNanometers;
614 
615  // Static Length Converting Constants
616  static constexpr LengthBase_t sNmPerInch = 25400000;
617  static constexpr LengthBase_t sNmPerMil = 25400;
618  static constexpr LengthBase_t sPixelsPerInch =
619  72;
620  static constexpr qreal sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch;
621  static constexpr qreal sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch;
622 };
623 
624 /*******************************************************************************
625  * Non-Member Functions
626  ******************************************************************************/
627 
628 inline QDataStream& operator<<(QDataStream& stream, const Length& length) {
629  stream << length.toMm();
630  return stream;
631 }
632 
633 inline QDebug operator<<(QDebug stream, const Length& length) {
634  stream << QString("Length(%1mm)").arg(length.toMm());
635  return stream;
636 }
637 
638 inline uint qHash(const Length& key, uint seed = 0) noexcept {
639  return ::qHash(key.toNm(), seed);
640 }
641 
642 /*******************************************************************************
643  * Class UnsignedLength
644  ******************************************************************************/
645 
647  template <typename Value, typename Predicate>
648  static constexpr auto verify(Value&& val, const Predicate& p) ->
649  typename std::decay<Value>::type {
650  return p(val) ? std::forward<Value>(val)
651  : (throw RuntimeError(__FILE__, __LINE__,
652  Length::tr("Value must be >= 0!")),
653  std::forward<Value>(val));
654  }
655 };
656 
658  constexpr bool operator()(const Length& l) const noexcept { return l >= 0; }
659 };
660 
668 using UnsignedLength =
669  type_safe::constrained_type<Length, UnsignedLengthConstraint,
671 
673  const UnsignedLength& rhs) noexcept {
674  return UnsignedLength(*lhs +
675  *rhs); // will not throw as long as there's no overflow
676 }
677 
679  const UnsignedLength& rhs) noexcept {
680  lhs = lhs + rhs; // will not throw as long as there's no overflow
681  return lhs;
682 }
683 
684 inline Length operator*(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
685  return (*lhs) * rhs;
686 }
687 inline Length operator/(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
688  return (*lhs) / rhs;
689 }
690 inline Length operator+(const Length& lhs, const UnsignedLength& rhs) noexcept {
691  return lhs + *rhs;
692 }
693 inline Length operator+(const UnsignedLength& lhs, const Length& rhs) noexcept {
694  return *lhs + rhs;
695 }
696 inline Length operator-(const Length& lhs, const UnsignedLength& rhs) noexcept {
697  return lhs - *rhs;
698 }
699 inline Length operator-(const UnsignedLength& lhs, const Length& rhs) noexcept {
700  return *lhs - rhs;
701 }
702 inline Length operator-(const UnsignedLength& lhs) noexcept {
703  return -(*lhs);
704 }
705 inline bool operator>(const UnsignedLength& lhs, const Length& rhs) noexcept {
706  return (*lhs) > rhs;
707 }
708 inline bool operator>(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
709  return (*lhs) > rhs;
710 }
711 inline bool operator>=(const UnsignedLength& lhs, const Length& rhs) noexcept {
712  return (*lhs) >= rhs;
713 }
714 inline bool operator>=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
715  return (*lhs) >= rhs;
716 }
717 inline bool operator<(const UnsignedLength& lhs, const Length& rhs) noexcept {
718  return (*lhs) < rhs;
719 }
720 inline bool operator<(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
721  return (*lhs) < rhs;
722 }
723 inline bool operator<=(const UnsignedLength& lhs, const Length& rhs) noexcept {
724  return (*lhs) <= rhs;
725 }
726 inline bool operator<=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
727  return (*lhs) <= rhs;
728 }
729 inline bool operator==(const UnsignedLength& lhs, const Length& rhs) noexcept {
730  return (*lhs) == rhs;
731 }
732 inline bool operator==(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
733  return (*lhs) == rhs;
734 }
735 inline bool operator!=(const UnsignedLength& lhs, const Length& rhs) noexcept {
736  return (*lhs) != rhs;
737 }
738 inline bool operator!=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
739  return (*lhs) != rhs;
740 }
741 
742 inline QDataStream& operator<<(QDataStream& stream,
743  const UnsignedLength& length) {
744  stream << length->toMm();
745  return stream;
746 }
747 
748 inline QDebug operator<<(QDebug stream, const UnsignedLength& length) {
749  stream << QString("UnsignedLength(%1mm)").arg(length->toMm());
750  return stream;
751 }
752 
753 inline uint qHash(const UnsignedLength& key, uint seed = 0) noexcept {
754  return ::qHash(key->toNm(), seed);
755 }
756 
757 /*******************************************************************************
758  * Class PositiveLength
759  ******************************************************************************/
760 
762  template <typename Value, typename Predicate>
763  static constexpr auto verify(Value&& val, const Predicate& p) ->
764  typename std::decay<Value>::type {
765  return p(val) ? std::forward<Value>(val)
766  : (throw RuntimeError(__FILE__, __LINE__,
767  Length::tr("Value must be > 0!")),
768  std::forward<Value>(val));
769  }
770 };
771 
773  constexpr bool operator()(const Length& l) const noexcept { return l > 0; }
774 };
775 
783 using PositiveLength =
784  type_safe::constrained_type<Length, PositiveLengthConstraint,
786 
788  return UnsignedLength(*l);
789 }
790 
792  const PositiveLength& rhs) noexcept {
793  return PositiveLength(*lhs +
794  *rhs); // will not throw as long as there's no overflow
795 }
796 
798  const UnsignedLength& rhs) noexcept {
799  return PositiveLength(*lhs +
800  *rhs); // will not throw as long as there's no overflow
801 }
802 
804  const PositiveLength& rhs) noexcept {
805  return PositiveLength(*lhs +
806  *rhs); // will not throw as long as there's no overflow
807 }
808 
810  const PositiveLength& rhs) noexcept {
811  lhs = lhs + rhs; // will not throw as long as there's no overflow
812  return lhs;
813 }
814 
816  const UnsignedLength& rhs) noexcept {
817  lhs = lhs + rhs; // will not throw as long as there's no overflow
818  return lhs;
819 }
820 
822  const PositiveLength& rhs) noexcept {
823  lhs = positiveToUnsigned(
824  lhs + rhs); // will not throw as long as there's no overflow
825  return lhs;
826 }
827 
828 inline Length operator*(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
829  return (*lhs) * rhs;
830 }
831 inline Length operator/(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
832  return (*lhs) / rhs;
833 }
834 inline Length operator+(const Length& lhs, const PositiveLength& rhs) noexcept {
835  return lhs + *rhs;
836 }
837 inline Length operator+(const PositiveLength& lhs, const Length& rhs) noexcept {
838  return *lhs + rhs;
839 }
840 inline Length operator-(const Length& lhs, const PositiveLength& rhs) noexcept {
841  return lhs - *rhs;
842 }
843 inline Length operator-(const PositiveLength& lhs, const Length& rhs) noexcept {
844  return *lhs - rhs;
845 }
846 inline Length operator-(const UnsignedLength& lhs,
847  const PositiveLength& rhs) noexcept {
848  return *lhs - *rhs;
849 }
850 inline Length operator-(const PositiveLength& lhs,
851  const UnsignedLength& rhs) noexcept {
852  return *lhs - *rhs;
853 }
854 inline Length operator-(const PositiveLength& lhs) noexcept {
855  return -(*lhs);
856 }
857 inline bool operator>(const UnsignedLength& lhs,
858  const PositiveLength& rhs) noexcept {
859  return (*lhs) > (*rhs);
860 }
861 inline bool operator>(const PositiveLength& lhs,
862  const UnsignedLength& rhs) noexcept {
863  return (*lhs) > (*rhs);
864 }
865 inline bool operator>(const PositiveLength& lhs, const Length& rhs) noexcept {
866  return (*lhs) > rhs;
867 }
868 inline bool operator>(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
869  return (*lhs) > rhs;
870 }
871 inline bool operator>=(const UnsignedLength& lhs,
872  const PositiveLength& rhs) noexcept {
873  return (*lhs) >= (*rhs);
874 }
875 inline bool operator>=(const PositiveLength& lhs,
876  const UnsignedLength& rhs) noexcept {
877  return (*lhs) >= (*rhs);
878 }
879 inline bool operator>=(const PositiveLength& lhs, const Length& rhs) noexcept {
880  return (*lhs) >= rhs;
881 }
882 inline bool operator>=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
883  return (*lhs) >= rhs;
884 }
885 inline bool operator<(const UnsignedLength& lhs,
886  const PositiveLength& rhs) noexcept {
887  return (*lhs) < (*rhs);
888 }
889 inline bool operator<(const PositiveLength& lhs,
890  const UnsignedLength& rhs) noexcept {
891  return (*lhs) < (*rhs);
892 }
893 inline bool operator<(const PositiveLength& lhs, const Length& rhs) noexcept {
894  return (*lhs) < rhs;
895 }
896 inline bool operator<(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
897  return (*lhs) < rhs;
898 }
899 inline bool operator<=(const UnsignedLength& lhs,
900  const PositiveLength& rhs) noexcept {
901  return (*lhs) <= (*rhs);
902 }
903 inline bool operator<=(const PositiveLength& lhs,
904  const UnsignedLength& rhs) noexcept {
905  return (*lhs) <= (*rhs);
906 }
907 inline bool operator<=(const PositiveLength& lhs, const Length& rhs) noexcept {
908  return (*lhs) <= rhs;
909 }
910 inline bool operator<=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
911  return (*lhs) <= rhs;
912 }
913 inline bool operator==(const UnsignedLength& lhs,
914  const PositiveLength& rhs) noexcept {
915  return (*lhs) == (*rhs);
916 }
917 inline bool operator==(const PositiveLength& lhs,
918  const UnsignedLength& rhs) noexcept {
919  return (*lhs) == (*rhs);
920 }
921 inline bool operator==(const PositiveLength& lhs, const Length& rhs) noexcept {
922  return (*lhs) == rhs;
923 }
924 inline bool operator==(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
925  return (*lhs) == rhs;
926 }
927 inline bool operator!=(const UnsignedLength& lhs,
928  const PositiveLength& rhs) noexcept {
929  return (*lhs) != (*rhs);
930 }
931 inline bool operator!=(const PositiveLength& lhs,
932  const UnsignedLength& rhs) noexcept {
933  return (*lhs) != (*rhs);
934 }
935 inline bool operator!=(const PositiveLength& lhs, const Length& rhs) noexcept {
936  return (*lhs) != rhs;
937 }
938 inline bool operator!=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
939  return (*lhs) != rhs;
940 }
941 
942 inline QDataStream& operator<<(QDataStream& stream,
943  const PositiveLength& length) {
944  stream << length->toMm();
945  return stream;
946 }
947 
948 inline QDebug operator<<(QDebug stream, const PositiveLength& length) {
949  stream << QString("PositiveLength(%1mm)").arg(length->toMm());
950  return stream;
951 }
952 
953 inline uint qHash(const PositiveLength& key, uint seed = 0) noexcept {
954  return ::qHash(key->toNm(), seed);
955 }
956 
957 /*******************************************************************************
958  * Class Point3D
959  ******************************************************************************/
960 
961 using Point3D = std::tuple<Length, Length, Length>;
962 
963 QDebug operator<<(QDebug stream, const Point3D& obj);
964 
965 /*******************************************************************************
966  * End of File
967  ******************************************************************************/
968 
969 } // namespace librepcb
970 
971 Q_DECLARE_METATYPE(librepcb::Length)
972 
973 #endif
qreal toPx() const noexcept
Get the length in pixels (for QGraphics* objects)
Definition: length.h:282
Definition: length.h:657
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:108
Length operator-() const
Definition: length.h:516
Length & operator+=(const Length &rhs)
Definition: length.h:489
Length operator%(const Length &rhs) const
Definition: length.h:528
constexpr bool operator>=(LengthBase_t rhs) const
Definition: length.h:542
constexpr Length(const Length &length) noexcept
Copy Constructor.
Definition: length.h:100
Length mappedToGrid(const Length &gridInterval) const noexcept
Get a Length object which is mapped to a specific grid interval.
Definition: length.cpp:70
Length operator+(const Length &rhs) const
Definition: length.h:513
Length & mapToGrid(const Length &gridInterval) noexcept
Map this Length object to a specific grid interval.
Definition: length.cpp:75
Length scaled(qreal factor) const noexcept
Get a Length object which is scaled with a specific factor.
Definition: length.cpp:80
static constexpr qreal sPixelsPerNm
Definition: length.h:621
Definition: occmodel.cpp:76
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
uint qHash(const PositiveLength &key, uint seed=0) noexcept
Definition: length.h:953
QString toNmString() const noexcept
Get the length in nanometers as a QString.
Definition: length.h:221
void setLengthNm(LengthBase_t nanometers) noexcept
Set the length in nanometers.
Definition: length.h:123
static constexpr qreal sNmPerPixel
Definition: length.h:620
qint64 LengthBase_t
This type is the ONLY base type to store all lengths (always in nanometers)!
Definition: length.h:61
constexpr bool operator==(LengthBase_t rhs) const
Definition: length.h:554
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:658
qreal toMm() const noexcept
Get the length in millimeters.
Definition: length.h:239
LengthBase_t toNm() const noexcept
Get the length in nanometers.
Definition: length.h:213
constexpr bool operator<=(LengthBase_t rhs) const
Definition: length.h:548
constexpr bool operator!=(const Length &rhs) const
Definition: length.h:557
~Length()=default
Destructor.
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>(const Length &rhs) const
Definition: length.h:531
static Length min() noexcept
Get the smallest possible length value.
Definition: length.cpp:124
constexpr bool operator==(const Length &rhs) const
Definition: length.h:551
Length operator-(const Length &rhs) const
Definition: length.h:517
Definition: length.h:772
Length & operator*=(const Length &rhs)
Definition: length.h:497
Length & makeAbs() noexcept
Make the length absolute (mNanometers >= 0)
Definition: length.cpp:61
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:648
Length & operator/=(LengthBase_t rhs)
Definition: length.h:509
constexpr bool operator>(LengthBase_t rhs) const
Definition: length.h:534
Length & operator-=(const Length &rhs)
Definition: length.h:493
void setLengthFromFloat(qreal nanometers)
Set the length from a floating point number in nanometers.
Definition: length.cpp:136
Length operator/(const Length &rhs) const
Definition: length.h:524
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
static Length max() noexcept
Get the highest possible length value.
Definition: length.cpp:128
constexpr bool operator>=(const Length &rhs) const
Definition: length.h:539
qreal toMil() const noexcept
Get the length in mils (1/1000 inches)
Definition: length.h:270
void setLengthPx(qreal pixels)
Set the length in pixels (from QGraphics* objects)
Definition: length.h:204
Length operator*(const Length &rhs) const
Definition: length.h:520
static constexpr LengthBase_t sNmPerMil
1 inch = 25.4mm
Definition: length.h:617
constexpr bool operator!=(LengthBase_t rhs) const
Definition: length.h:560
Definition: length.h:646
Length & operator*=(LengthBase_t rhs)
Definition: length.h:501
The RuntimeError class.
Definition: exceptions.h:216
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:773
Length & operator=(const Length &rhs)
Definition: length.h:485
LengthBase_t mNanometers
the length in nanometers
Definition: length.h:613
constexpr bool operator<(LengthBase_t rhs) const
Definition: length.h:538
constexpr bool operator<(const Length &rhs) const
Definition: length.h:535
static LengthBase_t mmStringToNm(const QString &millimeters)
Convert a length from a QString (in millimeters) to an integer (in nanometers)
Definition: length.cpp:191
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:151
Length operator/(LengthBase_t rhs) const
Definition: length.h:527
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:763
void setLengthInch(qreal inches)
Set the length in inches.
Definition: length.h:172
Length abs() const noexcept
Get a Length object with absolute value (mNanometers >= 0)
Definition: length.cpp:55
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 & operator/=(const Length &rhs)
Definition: length.h:505
qreal toMicrometers() const noexcept
Get the length in micrometers.
Definition: length.h:230
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:785
void setLengthMil(qreal mils)
Set the length in mils (1/1000 inch)
Definition: length.h:187
void setLengthMm(const QString &millimeters)
Set the length in millimeters, represented in a QString.
Definition: length.h:155
constexpr bool operator<=(const Length &rhs) const
Definition: length.h:545
std::tuple< Length, Length, Length > Point3D
Definition: length.h:961
static constexpr LengthBase_t sNmPerInch
1 inch = 25.4mm
Definition: length.h:616
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:82
UnsignedLength positiveToUnsigned(const PositiveLength &l) noexcept
Definition: length.h:787
qreal toInch() const noexcept
Get the length in inches.
Definition: length.h:261
void setLengthMm(qreal millimeters)
Set the length in millimeters.
Definition: length.h:140
Length operator*(LengthBase_t rhs) const
Definition: length.h:523
static constexpr LengthBase_t sPixelsPerInch
72 dpi for the QGraphics* objects
Definition: length.h:618
Length & scale(qreal factor) noexcept
Scale this Length object with a specific factor.
Definition: length.cpp:85
QString toMmString() const noexcept
Get the length in millimeters as a QString.
Definition: length.cpp:47
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:118
constexpr Length() noexcept
Default Constructor.
Definition: length.h:93
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:670
Definition: length.h:761
constexpr Length(LengthBase_t nanometers) noexcept
Constructor with length in nanometers.
Definition: length.h:108