LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_LENGTH_H
21 #define LIBREPCB_LENGTH_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../fileio/sexpression.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 
85 class Length {
86  Q_DECLARE_TR_FUNCTIONS(Length)
87 
88 public:
89  // Constructors / Destructor
90 
96  constexpr Length() noexcept : Length(0) {}
97 
103  constexpr Length(const Length& length) noexcept
104  : mNanometers(length.mNanometers) {}
105 
111  constexpr Length(LengthBase_t nanometers) noexcept
112  : mNanometers(nanometers) {}
113 
117  ~Length() = default;
118 
119  // Setters
120 
126  void setLengthNm(LengthBase_t nanometers) noexcept {
127  mNanometers = nanometers;
128  }
129 
143  void setLengthMm(qreal millimeters) { setLengthFromFloat(millimeters * 1e6); }
144 
158  void setLengthMm(const QString& millimeters) {
159  mNanometers = mmStringToNm(millimeters);
160  }
161 
175  void setLengthInch(qreal inches) { setLengthFromFloat(inches * sNmPerInch); }
176 
190  void setLengthMil(qreal mils) { setLengthFromFloat(mils * sNmPerMil); }
191 
207  void setLengthPx(qreal pixels) { setLengthFromFloat(pixels * sNmPerPixel); }
208 
209  // Conversions
210 
216  LengthBase_t toNm() const noexcept { return mNanometers; }
217 
224  QString toNmString() const noexcept { return QString::number(toNm()); }
225 
233  qreal toMm() const noexcept { return (qreal)mNanometers / 1e6; }
234 
246  QString toMmString() const noexcept;
247 
255  qreal toInch() const noexcept { return (qreal)mNanometers / sNmPerInch; }
256 
264  qreal toMil() const noexcept { return (qreal)mNanometers / sNmPerMil; }
265 
276  qreal toPx() const noexcept { return mNanometers * sPixelsPerNm; }
277 
278  // General Methods
279 
287  Length abs() const noexcept;
288 
296  Length& makeAbs() noexcept;
297 
308  Length mappedToGrid(const Length& gridInterval) const noexcept;
309 
320  Length& mapToGrid(const Length& gridInterval) noexcept;
321 
334  Length scaled(qreal factor) const noexcept;
335 
348  Length& scale(qreal factor) noexcept;
349 
350  // Static Functions
351 
370  static Length fromMm(qreal millimeters,
371  const Length& gridInterval = Length(0));
372 
398  static Length fromMm(const QString& millimeters,
399  const Length& gridInterval = Length(0));
400 
419  static Length fromInch(qreal inches, const Length& gridInterval = Length(0));
420 
439  static Length fromMil(qreal mils, const Length& gridInterval = Length(0));
440 
462  static Length fromPx(qreal pixels, const Length& gridInterval = Length(0));
463 
464  // Operators
465  Length& operator=(const Length& rhs) {
466  mNanometers = rhs.mNanometers;
467  return *this;
468  }
469  Length& operator+=(const Length& rhs) {
470  mNanometers += rhs.mNanometers;
471  return *this;
472  }
473  Length& operator-=(const Length& rhs) {
474  mNanometers -= rhs.mNanometers;
475  return *this;
476  }
477  Length& operator*=(const Length& rhs) {
478  mNanometers *= rhs.mNanometers;
479  return *this;
480  }
482  mNanometers *= rhs;
483  return *this;
484  }
485  Length& operator/=(const Length& rhs) {
486  mNanometers /= rhs.mNanometers;
487  return *this;
488  }
490  mNanometers /= rhs;
491  return *this;
492  }
493  Length operator+(const Length& rhs) const {
494  return Length(mNanometers + rhs.mNanometers);
495  }
496  Length operator-() const { return Length(-mNanometers); }
497  Length operator-(const Length& rhs) const {
498  return Length(mNanometers - rhs.mNanometers);
499  }
500  Length operator*(const Length& rhs) const {
501  return Length(mNanometers * rhs.mNanometers);
502  }
503  Length operator*(LengthBase_t rhs) const { return Length(mNanometers * rhs); }
504  Length operator/(const Length& rhs) const {
505  return Length(mNanometers / rhs.mNanometers);
506  }
507  Length operator/(LengthBase_t rhs) const { return Length(mNanometers / rhs); }
508  Length operator%(const Length& rhs) const {
509  return Length(mNanometers % rhs.mNanometers);
510  }
511  constexpr bool operator>(const Length& rhs) const {
512  return mNanometers > rhs.mNanometers;
513  }
514  constexpr bool operator>(LengthBase_t rhs) const { return mNanometers > rhs; }
515  constexpr bool operator<(const Length& rhs) const {
516  return mNanometers < rhs.mNanometers;
517  }
518  constexpr bool operator<(LengthBase_t rhs) const { return mNanometers < rhs; }
519  constexpr bool operator>=(const Length& rhs) const {
520  return mNanometers >= rhs.mNanometers;
521  }
522  constexpr bool operator>=(LengthBase_t rhs) const {
523  return mNanometers >= rhs;
524  }
525  constexpr bool operator<=(const Length& rhs) const {
526  return mNanometers <= rhs.mNanometers;
527  }
528  constexpr bool operator<=(LengthBase_t rhs) const {
529  return mNanometers <= rhs;
530  }
531  constexpr bool operator==(const Length& rhs) const {
532  return mNanometers == rhs.mNanometers;
533  }
534  constexpr bool operator==(LengthBase_t rhs) const {
535  return mNanometers == rhs;
536  }
537  constexpr bool operator!=(const Length& rhs) const {
538  return mNanometers != rhs.mNanometers;
539  }
540  constexpr bool operator!=(LengthBase_t rhs) const {
541  return mNanometers != rhs;
542  }
543 
544 private:
545  // Private Functions
546 
560  void setLengthFromFloat(qreal nanometers);
561 
562  // Private Static Functions
563 
575  static LengthBase_t mapNmToGrid(LengthBase_t nanometers,
576  const Length& gridInterval) noexcept;
577 
590  static LengthBase_t mmStringToNm(const QString& millimeters);
591 
592  // Private Member Variables
594 
595  // Static Length Converting Constants
596  static constexpr LengthBase_t sNmPerInch = 25400000;
597  static constexpr LengthBase_t sNmPerMil = 25400;
598  static constexpr LengthBase_t sPixelsPerInch =
599  72;
600  static constexpr qreal sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch;
601  static constexpr qreal sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch;
602 };
603 
604 /*******************************************************************************
605  * Non-Member Functions
606  ******************************************************************************/
607 
608 template <>
610  return SExpression::createToken(obj.toMmString());
611 }
612 
613 template <>
615  bool throwIfEmpty) {
616  QString str = sexpr.getStringOrToken(throwIfEmpty);
617  return Length::fromMm(str);
618 }
619 
620 inline QDataStream& operator<<(QDataStream& stream, const Length& length) {
621  stream << length.toMm();
622  return stream;
623 }
624 
625 inline QDebug operator<<(QDebug stream, const Length& length) {
626  stream << QString("Length(%1mm)").arg(length.toMm());
627  return stream;
628 }
629 
630 inline uint qHash(const Length& key, uint seed = 0) noexcept {
631  return ::qHash(key.toNm(), seed);
632 }
633 
634 /*******************************************************************************
635  * Class UnsignedLength
636  ******************************************************************************/
637 
639  template <typename Value, typename Predicate>
640  static constexpr auto verify(Value&& val, const Predicate& p) ->
641  typename std::decay<Value>::type {
642  return p(val) ? std::forward<Value>(val)
643  : (throw RuntimeError(__FILE__, __LINE__,
644  Length::tr("Value must be >= 0!")),
645  std::forward<Value>(val));
646  }
647 };
648 
650  constexpr bool operator()(const Length& l) const noexcept { return l >= 0; }
651 };
652 
660 using UnsignedLength =
661  type_safe::constrained_type<Length, UnsignedLengthConstraint,
663 
665  const UnsignedLength& rhs) noexcept {
666  return UnsignedLength(*lhs +
667  *rhs); // will not throw as long as there's no overflow
668 }
669 
671  const UnsignedLength& rhs) noexcept {
672  lhs = lhs + rhs; // will not throw as long as there's no overflow
673  return lhs;
674 }
675 
676 inline Length operator*(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
677  return (*lhs) * rhs;
678 }
679 inline Length operator/(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
680  return (*lhs) / rhs;
681 }
682 inline Length operator+(const Length& lhs, const UnsignedLength& rhs) noexcept {
683  return lhs + *rhs;
684 }
685 inline Length operator+(const UnsignedLength& lhs, const Length& rhs) noexcept {
686  return *lhs + rhs;
687 }
688 inline Length operator-(const Length& lhs, const UnsignedLength& rhs) noexcept {
689  return lhs - *rhs;
690 }
691 inline Length operator-(const UnsignedLength& lhs, const Length& rhs) noexcept {
692  return *lhs - rhs;
693 }
694 inline Length operator-(const UnsignedLength& lhs) noexcept {
695  return -(*lhs);
696 }
697 inline bool operator>(const UnsignedLength& lhs, const Length& rhs) noexcept {
698  return (*lhs) > rhs;
699 }
700 inline bool operator>(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
701  return (*lhs) > rhs;
702 }
703 inline bool operator>=(const UnsignedLength& lhs, const Length& rhs) noexcept {
704  return (*lhs) >= rhs;
705 }
706 inline bool operator>=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
707  return (*lhs) >= rhs;
708 }
709 inline bool operator<(const UnsignedLength& lhs, const Length& rhs) noexcept {
710  return (*lhs) <= rhs;
711 }
712 inline bool operator<(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
713  return (*lhs) <= rhs;
714 }
715 inline bool operator==(const UnsignedLength& lhs, const Length& rhs) noexcept {
716  return (*lhs) == rhs;
717 }
718 inline bool operator==(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
719  return (*lhs) == rhs;
720 }
721 inline bool operator!=(const UnsignedLength& lhs, const Length& rhs) noexcept {
722  return (*lhs) != rhs;
723 }
724 inline bool operator!=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
725  return (*lhs) != rhs;
726 }
727 
728 template <>
730  return SExpression::createToken(obj->toMmString());
731 }
732 
733 template <>
735  bool throwIfEmpty) {
736  QString str = sexpr.getStringOrToken(throwIfEmpty);
737  return UnsignedLength(Length::fromMm(str));
738 }
739 
740 inline QDataStream& operator<<(QDataStream& stream,
741  const UnsignedLength& length) {
742  stream << length->toMm();
743  return stream;
744 }
745 
746 inline QDebug operator<<(QDebug stream, const UnsignedLength& length) {
747  stream << QString("UnsignedLength(%1mm)").arg(length->toMm());
748  return stream;
749 }
750 
751 inline uint qHash(const UnsignedLength& key, uint seed = 0) noexcept {
752  return ::qHash(key->toNm(), seed);
753 }
754 
755 /*******************************************************************************
756  * Class PositiveLength
757  ******************************************************************************/
758 
760  template <typename Value, typename Predicate>
761  static constexpr auto verify(Value&& val, const Predicate& p) ->
762  typename std::decay<Value>::type {
763  return p(val) ? std::forward<Value>(val)
764  : (throw RuntimeError(__FILE__, __LINE__,
765  Length::tr("Value must be > 0!")),
766  std::forward<Value>(val));
767  }
768 };
769 
771  constexpr bool operator()(const Length& l) const noexcept { return l > 0; }
772 };
773 
781 using PositiveLength =
782  type_safe::constrained_type<Length, PositiveLengthConstraint,
784 
786  return UnsignedLength(*l);
787 }
788 
790  const PositiveLength& rhs) noexcept {
791  return PositiveLength(*lhs +
792  *rhs); // will not throw as long as there's no overflow
793 }
794 
796  const UnsignedLength& rhs) noexcept {
797  return PositiveLength(*lhs +
798  *rhs); // will not throw as long as there's no overflow
799 }
800 
802  const PositiveLength& rhs) noexcept {
803  return PositiveLength(*lhs +
804  *rhs); // will not throw as long as there's no overflow
805 }
806 
808  const PositiveLength& rhs) noexcept {
809  lhs = lhs + rhs; // will not throw as long as there's no overflow
810  return lhs;
811 }
812 
814  const UnsignedLength& rhs) noexcept {
815  lhs = lhs + rhs; // will not throw as long as there's no overflow
816  return lhs;
817 }
818 
820  const PositiveLength& rhs) noexcept {
821  lhs = positiveToUnsigned(
822  lhs + rhs); // will not throw as long as there's no overflow
823  return lhs;
824 }
825 
826 inline Length operator*(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
827  return (*lhs) * rhs;
828 }
829 inline Length operator/(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
830  return (*lhs) / rhs;
831 }
832 inline Length operator+(const Length& lhs, const PositiveLength& rhs) noexcept {
833  return lhs + *rhs;
834 }
835 inline Length operator+(const PositiveLength& lhs, const Length& rhs) noexcept {
836  return *lhs + rhs;
837 }
838 inline Length operator-(const Length& lhs, const PositiveLength& rhs) noexcept {
839  return lhs - *rhs;
840 }
841 inline Length operator-(const PositiveLength& lhs, const Length& rhs) noexcept {
842  return *lhs - rhs;
843 }
844 inline Length operator-(const UnsignedLength& lhs,
845  const PositiveLength& rhs) noexcept {
846  return *lhs - *rhs;
847 }
848 inline Length operator-(const PositiveLength& lhs,
849  const UnsignedLength& rhs) noexcept {
850  return *lhs - *rhs;
851 }
852 inline Length operator-(const PositiveLength& lhs) noexcept {
853  return -(*lhs);
854 }
855 inline bool operator>(const UnsignedLength& lhs,
856  const PositiveLength& rhs) noexcept {
857  return (*lhs) > (*rhs);
858 }
859 inline bool operator>(const PositiveLength& lhs,
860  const UnsignedLength& rhs) noexcept {
861  return (*lhs) > (*rhs);
862 }
863 inline bool operator>(const PositiveLength& lhs, const Length& rhs) noexcept {
864  return (*lhs) > rhs;
865 }
866 inline bool operator>(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
867  return (*lhs) > rhs;
868 }
869 inline bool operator>=(const UnsignedLength& lhs,
870  const PositiveLength& rhs) noexcept {
871  return (*lhs) >= (*rhs);
872 }
873 inline bool operator>=(const PositiveLength& lhs,
874  const UnsignedLength& rhs) noexcept {
875  return (*lhs) >= (*rhs);
876 }
877 inline bool operator>=(const PositiveLength& lhs, const Length& rhs) noexcept {
878  return (*lhs) >= rhs;
879 }
880 inline bool operator>=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
881  return (*lhs) >= rhs;
882 }
883 inline bool operator<(const UnsignedLength& lhs,
884  const PositiveLength& rhs) noexcept {
885  return (*lhs) < (*rhs);
886 }
887 inline bool operator<(const PositiveLength& lhs,
888  const UnsignedLength& rhs) noexcept {
889  return (*lhs) < (*rhs);
890 }
891 inline bool operator<(const PositiveLength& lhs, const Length& rhs) noexcept {
892  return (*lhs) <= rhs;
893 }
894 inline bool operator<(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
895  return (*lhs) <= rhs;
896 }
897 inline bool operator==(const UnsignedLength& lhs,
898  const PositiveLength& rhs) noexcept {
899  return (*lhs) == (*rhs);
900 }
901 inline bool operator==(const PositiveLength& lhs,
902  const UnsignedLength& rhs) noexcept {
903  return (*lhs) == (*rhs);
904 }
905 inline bool operator==(const PositiveLength& lhs, const Length& rhs) noexcept {
906  return (*lhs) == rhs;
907 }
908 inline bool operator==(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
909  return (*lhs) == rhs;
910 }
911 inline bool operator!=(const UnsignedLength& lhs,
912  const PositiveLength& rhs) noexcept {
913  return (*lhs) != (*rhs);
914 }
915 inline bool operator!=(const PositiveLength& lhs,
916  const UnsignedLength& rhs) noexcept {
917  return (*lhs) != (*rhs);
918 }
919 inline bool operator!=(const PositiveLength& lhs, const Length& rhs) noexcept {
920  return (*lhs) != rhs;
921 }
922 inline bool operator!=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
923  return (*lhs) != rhs;
924 }
925 
926 template <>
928  return SExpression::createToken(obj->toMmString());
929 }
930 
931 template <>
933  bool throwIfEmpty) {
934  QString str = sexpr.getStringOrToken(throwIfEmpty);
935  return PositiveLength(Length::fromMm(str));
936 }
937 
938 inline QDataStream& operator<<(QDataStream& stream,
939  const PositiveLength& length) {
940  stream << length->toMm();
941  return stream;
942 }
943 
944 inline QDebug operator<<(QDebug stream, const PositiveLength& length) {
945  stream << QString("PositiveLength(%1mm)").arg(length->toMm());
946  return stream;
947 }
948 
949 inline uint qHash(const PositiveLength& key, uint seed = 0) noexcept {
950  return ::qHash(key->toNm(), seed);
951 }
952 
953 /*******************************************************************************
954  * End of File
955  ******************************************************************************/
956 
957 } // namespace librepcb
958 
959 #endif // LIBREPCB_LENGTH_H
qreal toPx() const noexcept
Get the length in pixels (for QGraphics* objects)
Definition: length.h:276
Definition: length.h:649
Length operator*(const UnsignedLength &lhs, LengthBase_t rhs) noexcept
Definition: length.h:676
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:109
Length & operator+=(const Length &rhs)
Definition: length.h:469
constexpr bool operator!=(LengthBase_t rhs) const
Definition: length.h:540
constexpr bool operator!=(const Length &rhs) const
Definition: length.h:537
constexpr Length(const Length &length) noexcept
Copy Constructor.
Definition: length.h:103
Length mappedToGrid(const Length &gridInterval) const noexcept
Get a Length object which is mapped to a specific grid interval.
Definition: length.cpp:65
Length & mapToGrid(const Length &gridInterval) noexcept
Map this Length object to a specific grid interval.
Definition: length.cpp:70
Length scaled(qreal factor) const noexcept
Get a Length object which is scaled with a specific factor.
Definition: length.cpp:75
static constexpr qreal sPixelsPerNm
Definition: length.h:601
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:101
uint qHash(const PositiveLength &key, uint seed=0) noexcept
Definition: length.h:949
bool operator>=(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:703
QString toNmString() const noexcept
Get the length in nanometers as a QString.
Definition: length.h:224
Length operator%(const Length &rhs) const
Definition: length.h:508
void setLengthNm(LengthBase_t nanometers) noexcept
Set the length in nanometers.
Definition: length.h:126
static constexpr qreal sNmPerPixel
Definition: length.h:600
bool operator>(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:697
Length operator-(const Length &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:688
qint64 LengthBase_t
This type is the ONLY base type to store all lengths (always in nanometers)!
Definition: length.h:61
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:650
qreal toMm() const noexcept
Get the length in millimeters.
Definition: length.h:233
LengthBase_t toNm() const noexcept
Get the length in nanometers.
Definition: length.h:216
UnsignedLength & operator+=(UnsignedLength &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:670
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:79
~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:89
constexpr bool operator<=(LengthBase_t rhs) const
Definition: length.h:528
constexpr bool operator<(LengthBase_t rhs) const
Definition: length.h:518
constexpr bool operator==(LengthBase_t rhs) const
Definition: length.h:534
Length operator-(const Length &rhs) const
Definition: length.h:497
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:93
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:280
Definition: length.h:770
constexpr bool operator==(const Length &rhs) const
Definition: length.h:531
Length & operator*=(const Length &rhs)
Definition: length.h:477
Length & makeAbs() noexcept
Make the length absolute (mNanometers >= 0)
Definition: length.cpp:56
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:640
Length & operator/=(LengthBase_t rhs)
Definition: length.h:489
Length & operator-=(const Length &rhs)
Definition: length.h:473
UnsignedLength operator+(const UnsignedLength &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:664
void setLengthFromFloat(qreal nanometers)
Set the length from a floating point number in nanometers.
Definition: length.cpp:123
Length operator*(const Length &rhs) const
Definition: length.h:500
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:107
constexpr bool operator>=(const Length &rhs) const
Definition: length.h:519
qreal toMil() const noexcept
Get the length in mils (1/1000 inches)
Definition: length.h:264
void setLengthPx(qreal pixels)
Set the length in pixels (from QGraphics* objects)
Definition: length.h:207
constexpr bool operator>=(LengthBase_t rhs) const
Definition: length.h:522
static constexpr LengthBase_t sNmPerMil
1 inch = 25.4mm
Definition: length.h:597
Length operator*(LengthBase_t rhs) const
Definition: length.h:503
constexpr bool operator>(const Length &rhs) const
Definition: length.h:511
Definition: length.h:638
Length & operator*=(LengthBase_t rhs)
Definition: length.h:481
bool operator<(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:709
The RuntimeError class.
Definition: exceptions.h:219
Length operator/(LengthBase_t rhs) const
Definition: length.h:507
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:771
LengthBase_t mNanometers
the length in nanometers
Definition: length.h:593
bool operator==(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:85
bool operator!=(const AttributeKey &lhs, const QString &rhs) noexcept
Definition: attributekey.h:91
Length operator-() const
Definition: length.h:496
static LengthBase_t mmStringToNm(const QString &millimeters)
Convert a length from a QString (in millimeters) to an integer (in nanometers)
Definition: length.cpp:178
constexpr bool operator<(const Length &rhs) const
Definition: length.h:515
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:138
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:761
void setLengthInch(qreal inches)
Set the length in inches.
Definition: length.h:175
Length abs() const noexcept
Get a Length object with absolute value (mNanometers >= 0)
Definition: length.cpp:50
constexpr bool operator<=(const Length &rhs) const
Definition: length.h:525
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:113
Length & operator/=(const Length &rhs)
Definition: length.h:485
Length operator/(const UnsignedLength &lhs, LengthBase_t rhs) noexcept
Definition: length.h:679
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
void setLengthMil(qreal mils)
Set the length in mils (1/1000 inch)
Definition: length.h:190
void setLengthMm(const QString &millimeters)
Set the length in millimeters, represented in a QString.
Definition: length.h:158
static constexpr LengthBase_t sNmPerInch
1 inch = 25.4mm
Definition: length.h:596
Length operator/(const Length &rhs) const
Definition: length.h:504
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:85
UnsignedLength positiveToUnsigned(const PositiveLength &l) noexcept
Definition: length.h:785
Length operator+(const Length &rhs) const
Definition: length.h:493
qreal toInch() const noexcept
Get the length in inches.
Definition: length.h:255
void setLengthMm(qreal millimeters)
Set the length in millimeters.
Definition: length.h:143
static constexpr LengthBase_t sPixelsPerInch
72 dpi for the QGraphics* objects
Definition: length.h:598
Length & scale(qreal factor) noexcept
Scale this Length object with a specific factor.
Definition: length.cpp:80
QString toMmString() const noexcept
Get the length in millimeters as a QString.
Definition: length.cpp:42
constexpr bool operator>(LengthBase_t rhs) const
Definition: length.h:514
The SExpression class.
Definition: sexpression.h:60
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:119
constexpr Length() noexcept
Default Constructor.
Definition: length.h:96
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:662
Definition: length.h:759
constexpr Length(LengthBase_t nanometers) noexcept
Constructor with length in nanometers.
Definition: length.h:111