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 
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 toMm() const noexcept { return (qreal)mNanometers / 1e6; }
231 
243  QString toMmString() const noexcept;
244 
252  qreal toInch() const noexcept { return (qreal)mNanometers / sNmPerInch; }
253 
261  qreal toMil() const noexcept { return (qreal)mNanometers / sNmPerMil; }
262 
273  qreal toPx() const noexcept { return mNanometers * sPixelsPerNm; }
274 
275  // General Methods
276 
284  Length abs() const noexcept;
285 
293  Length& makeAbs() noexcept;
294 
305  Length mappedToGrid(const Length& gridInterval) const noexcept;
306 
317  Length& mapToGrid(const Length& gridInterval) noexcept;
318 
331  Length scaled(qreal factor) const noexcept;
332 
345  Length& scale(qreal factor) noexcept;
346 
347  // Static Functions
348 
367  static Length fromMm(qreal millimeters,
368  const Length& gridInterval = Length(0));
369 
395  static Length fromMm(const QString& millimeters,
396  const Length& gridInterval = Length(0));
397 
416  static Length fromInch(qreal inches, const Length& gridInterval = Length(0));
417 
436  static Length fromMil(qreal mils, const Length& gridInterval = Length(0));
437 
459  static Length fromPx(qreal pixels, const Length& gridInterval = Length(0));
460 
461  // Operators
462  Length& operator=(const Length& rhs) {
463  mNanometers = rhs.mNanometers;
464  return *this;
465  }
466  Length& operator+=(const Length& rhs) {
467  mNanometers += rhs.mNanometers;
468  return *this;
469  }
470  Length& operator-=(const Length& rhs) {
471  mNanometers -= rhs.mNanometers;
472  return *this;
473  }
474  Length& operator*=(const Length& rhs) {
475  mNanometers *= rhs.mNanometers;
476  return *this;
477  }
479  mNanometers *= rhs;
480  return *this;
481  }
482  Length& operator/=(const Length& rhs) {
483  mNanometers /= rhs.mNanometers;
484  return *this;
485  }
487  mNanometers /= rhs;
488  return *this;
489  }
490  Length operator+(const Length& rhs) const {
491  return Length(mNanometers + rhs.mNanometers);
492  }
493  Length operator-() const { return Length(-mNanometers); }
494  Length operator-(const Length& rhs) const {
495  return Length(mNanometers - rhs.mNanometers);
496  }
497  Length operator*(const Length& rhs) const {
498  return Length(mNanometers * rhs.mNanometers);
499  }
500  Length operator*(LengthBase_t rhs) const { return Length(mNanometers * rhs); }
501  Length operator/(const Length& rhs) const {
502  return Length(mNanometers / rhs.mNanometers);
503  }
504  Length operator/(LengthBase_t rhs) const { return Length(mNanometers / rhs); }
505  Length operator%(const Length& rhs) const {
506  return Length(mNanometers % rhs.mNanometers);
507  }
508  constexpr bool operator>(const Length& rhs) const {
509  return mNanometers > rhs.mNanometers;
510  }
511  constexpr bool operator>(LengthBase_t rhs) const { return mNanometers > rhs; }
512  constexpr bool operator<(const Length& rhs) const {
513  return mNanometers < rhs.mNanometers;
514  }
515  constexpr bool operator<(LengthBase_t rhs) const { return mNanometers < rhs; }
516  constexpr bool operator>=(const Length& rhs) const {
517  return mNanometers >= rhs.mNanometers;
518  }
519  constexpr bool operator>=(LengthBase_t rhs) const {
520  return mNanometers >= rhs;
521  }
522  constexpr bool operator<=(const Length& rhs) const {
523  return mNanometers <= rhs.mNanometers;
524  }
525  constexpr bool operator<=(LengthBase_t rhs) const {
526  return mNanometers <= rhs;
527  }
528  constexpr bool operator==(const Length& rhs) const {
529  return mNanometers == rhs.mNanometers;
530  }
531  constexpr bool operator==(LengthBase_t rhs) const {
532  return mNanometers == rhs;
533  }
534  constexpr bool operator!=(const Length& rhs) const {
535  return mNanometers != rhs.mNanometers;
536  }
537  constexpr bool operator!=(LengthBase_t rhs) const {
538  return mNanometers != rhs;
539  }
540 
541 private:
542  // Private Functions
543 
557  void setLengthFromFloat(qreal nanometers);
558 
559  // Private Static Functions
560 
572  static LengthBase_t mapNmToGrid(LengthBase_t nanometers,
573  const Length& gridInterval) noexcept;
574 
587  static LengthBase_t mmStringToNm(const QString& millimeters);
588 
589  // Private Member Variables
591 
592  // Static Length Converting Constants
593  static constexpr LengthBase_t sNmPerInch = 25400000;
594  static constexpr LengthBase_t sNmPerMil = 25400;
595  static constexpr LengthBase_t sPixelsPerInch =
596  72;
597  static constexpr qreal sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch;
598  static constexpr qreal sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch;
599 };
600 
601 /*******************************************************************************
602  * Non-Member Functions
603  ******************************************************************************/
604 
605 template <>
607  return SExpression::createToken(obj.toMmString());
608 }
609 
610 template <>
612  bool throwIfEmpty) {
613  QString str = sexpr.getStringOrToken(throwIfEmpty);
614  return Length::fromMm(str);
615 }
616 
617 inline QDataStream& operator<<(QDataStream& stream, const Length& length) {
618  stream << length.toMm();
619  return stream;
620 }
621 
622 inline QDebug operator<<(QDebug stream, const Length& length) {
623  stream << QString("Length(%1mm)").arg(length.toMm());
624  return stream;
625 }
626 
627 inline uint qHash(const Length& key, uint seed = 0) noexcept {
628  return ::qHash(key.toNm(), seed);
629 }
630 
631 /*******************************************************************************
632  * Class UnsignedLength
633  ******************************************************************************/
634 
636  template <typename Value, typename Predicate>
637  static constexpr auto verify(Value&& val, const Predicate& p) ->
638  typename std::decay<Value>::type {
639  return p(val) ? std::forward<Value>(val)
640  : (throw RuntimeError(__FILE__, __LINE__,
641  Length::tr("Value must be >= 0!")),
642  std::forward<Value>(val));
643  }
644 };
645 
647  constexpr bool operator()(const Length& l) const noexcept { return l >= 0; }
648 };
649 
657 using UnsignedLength =
658  type_safe::constrained_type<Length, UnsignedLengthConstraint,
660 
662  const UnsignedLength& rhs) noexcept {
663  return UnsignedLength(*lhs +
664  *rhs); // will not throw as long as there's no overflow
665 }
666 
668  const UnsignedLength& rhs) noexcept {
669  lhs = lhs + rhs; // will not throw as long as there's no overflow
670  return lhs;
671 }
672 
673 inline Length operator*(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
674  return (*lhs) * rhs;
675 }
676 inline Length operator/(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
677  return (*lhs) / rhs;
678 }
679 inline Length operator+(const Length& lhs, const UnsignedLength& rhs) noexcept {
680  return lhs + *rhs;
681 }
682 inline Length operator+(const UnsignedLength& lhs, const Length& rhs) noexcept {
683  return *lhs + rhs;
684 }
685 inline Length operator-(const Length& lhs, const UnsignedLength& rhs) noexcept {
686  return lhs - *rhs;
687 }
688 inline Length operator-(const UnsignedLength& lhs, const Length& rhs) noexcept {
689  return *lhs - rhs;
690 }
691 inline Length operator-(const UnsignedLength& lhs) noexcept {
692  return -(*lhs);
693 }
694 inline bool operator>(const UnsignedLength& lhs, const Length& rhs) noexcept {
695  return (*lhs) > rhs;
696 }
697 inline bool operator>(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
698  return (*lhs) > rhs;
699 }
700 inline bool operator>=(const UnsignedLength& lhs, const Length& rhs) noexcept {
701  return (*lhs) >= rhs;
702 }
703 inline bool operator>=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
704  return (*lhs) >= rhs;
705 }
706 inline bool operator<(const UnsignedLength& lhs, const Length& rhs) noexcept {
707  return (*lhs) <= rhs;
708 }
709 inline bool operator<(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
710  return (*lhs) <= rhs;
711 }
712 inline bool operator==(const UnsignedLength& lhs, const Length& rhs) noexcept {
713  return (*lhs) == rhs;
714 }
715 inline bool operator==(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
716  return (*lhs) == rhs;
717 }
718 inline bool operator!=(const UnsignedLength& lhs, const Length& rhs) noexcept {
719  return (*lhs) != rhs;
720 }
721 inline bool operator!=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
722  return (*lhs) != rhs;
723 }
724 
725 template <>
727  return SExpression::createToken(obj->toMmString());
728 }
729 
730 template <>
732  bool throwIfEmpty) {
733  QString str = sexpr.getStringOrToken(throwIfEmpty);
734  return UnsignedLength(Length::fromMm(str));
735 }
736 
737 inline QDataStream& operator<<(QDataStream& stream,
738  const UnsignedLength& length) {
739  stream << length->toMm();
740  return stream;
741 }
742 
743 inline QDebug operator<<(QDebug stream, const UnsignedLength& length) {
744  stream << QString("UnsignedLength(%1mm)").arg(length->toMm());
745  return stream;
746 }
747 
748 inline uint qHash(const UnsignedLength& key, uint seed = 0) noexcept {
749  return ::qHash(key->toNm(), seed);
750 }
751 
752 /*******************************************************************************
753  * Class PositiveLength
754  ******************************************************************************/
755 
757  template <typename Value, typename Predicate>
758  static constexpr auto verify(Value&& val, const Predicate& p) ->
759  typename std::decay<Value>::type {
760  return p(val) ? std::forward<Value>(val)
761  : (throw RuntimeError(__FILE__, __LINE__,
762  Length::tr("Value must be > 0!")),
763  std::forward<Value>(val));
764  }
765 };
766 
768  constexpr bool operator()(const Length& l) const noexcept { return l > 0; }
769 };
770 
778 using PositiveLength =
779  type_safe::constrained_type<Length, PositiveLengthConstraint,
781 
783  return UnsignedLength(*l);
784 }
785 
787  const PositiveLength& rhs) noexcept {
788  return PositiveLength(*lhs +
789  *rhs); // will not throw as long as there's no overflow
790 }
791 
793  const UnsignedLength& rhs) noexcept {
794  return PositiveLength(*lhs +
795  *rhs); // will not throw as long as there's no overflow
796 }
797 
799  const PositiveLength& rhs) noexcept {
800  return PositiveLength(*lhs +
801  *rhs); // will not throw as long as there's no overflow
802 }
803 
805  const PositiveLength& rhs) noexcept {
806  lhs = lhs + rhs; // will not throw as long as there's no overflow
807  return lhs;
808 }
809 
811  const UnsignedLength& rhs) noexcept {
812  lhs = lhs + rhs; // will not throw as long as there's no overflow
813  return lhs;
814 }
815 
817  const PositiveLength& rhs) noexcept {
818  lhs = positiveToUnsigned(
819  lhs + rhs); // will not throw as long as there's no overflow
820  return lhs;
821 }
822 
823 inline Length operator*(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
824  return (*lhs) * rhs;
825 }
826 inline Length operator/(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
827  return (*lhs) / rhs;
828 }
829 inline Length operator+(const Length& lhs, const PositiveLength& rhs) noexcept {
830  return lhs + *rhs;
831 }
832 inline Length operator+(const PositiveLength& lhs, const Length& rhs) noexcept {
833  return *lhs + rhs;
834 }
835 inline Length operator-(const Length& lhs, const PositiveLength& rhs) noexcept {
836  return lhs - *rhs;
837 }
838 inline Length operator-(const PositiveLength& lhs, const Length& rhs) noexcept {
839  return *lhs - rhs;
840 }
841 inline Length operator-(const UnsignedLength& lhs,
842  const PositiveLength& rhs) noexcept {
843  return *lhs - *rhs;
844 }
845 inline Length operator-(const PositiveLength& lhs,
846  const UnsignedLength& rhs) noexcept {
847  return *lhs - *rhs;
848 }
849 inline Length operator-(const PositiveLength& lhs) noexcept {
850  return -(*lhs);
851 }
852 inline bool operator>(const UnsignedLength& lhs,
853  const PositiveLength& rhs) noexcept {
854  return (*lhs) > (*rhs);
855 }
856 inline bool operator>(const PositiveLength& lhs,
857  const UnsignedLength& rhs) noexcept {
858  return (*lhs) > (*rhs);
859 }
860 inline bool operator>(const PositiveLength& lhs, const Length& rhs) noexcept {
861  return (*lhs) > rhs;
862 }
863 inline bool operator>(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
864  return (*lhs) > rhs;
865 }
866 inline bool operator>=(const UnsignedLength& lhs,
867  const PositiveLength& rhs) noexcept {
868  return (*lhs) >= (*rhs);
869 }
870 inline bool operator>=(const PositiveLength& lhs,
871  const UnsignedLength& rhs) noexcept {
872  return (*lhs) >= (*rhs);
873 }
874 inline bool operator>=(const PositiveLength& lhs, const Length& rhs) noexcept {
875  return (*lhs) >= rhs;
876 }
877 inline bool operator>=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
878  return (*lhs) >= rhs;
879 }
880 inline bool operator<(const UnsignedLength& lhs,
881  const PositiveLength& rhs) noexcept {
882  return (*lhs) < (*rhs);
883 }
884 inline bool operator<(const PositiveLength& lhs,
885  const UnsignedLength& rhs) noexcept {
886  return (*lhs) < (*rhs);
887 }
888 inline bool operator<(const PositiveLength& lhs, const Length& rhs) noexcept {
889  return (*lhs) <= rhs;
890 }
891 inline bool operator<(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
892  return (*lhs) <= rhs;
893 }
894 inline bool operator==(const UnsignedLength& lhs,
895  const PositiveLength& rhs) noexcept {
896  return (*lhs) == (*rhs);
897 }
898 inline bool operator==(const PositiveLength& lhs,
899  const UnsignedLength& rhs) noexcept {
900  return (*lhs) == (*rhs);
901 }
902 inline bool operator==(const PositiveLength& lhs, const Length& rhs) noexcept {
903  return (*lhs) == rhs;
904 }
905 inline bool operator==(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
906  return (*lhs) == rhs;
907 }
908 inline bool operator!=(const UnsignedLength& lhs,
909  const PositiveLength& rhs) noexcept {
910  return (*lhs) != (*rhs);
911 }
912 inline bool operator!=(const PositiveLength& lhs,
913  const UnsignedLength& rhs) noexcept {
914  return (*lhs) != (*rhs);
915 }
916 inline bool operator!=(const PositiveLength& lhs, const Length& rhs) noexcept {
917  return (*lhs) != rhs;
918 }
919 inline bool operator!=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
920  return (*lhs) != rhs;
921 }
922 
923 template <>
925  return SExpression::createToken(obj->toMmString());
926 }
927 
928 template <>
930  bool throwIfEmpty) {
931  QString str = sexpr.getStringOrToken(throwIfEmpty);
932  return PositiveLength(Length::fromMm(str));
933 }
934 
935 inline QDataStream& operator<<(QDataStream& stream,
936  const PositiveLength& length) {
937  stream << length->toMm();
938  return stream;
939 }
940 
941 inline QDebug operator<<(QDebug stream, const PositiveLength& length) {
942  stream << QString("PositiveLength(%1mm)").arg(length->toMm());
943  return stream;
944 }
945 
946 inline uint qHash(const PositiveLength& key, uint seed = 0) noexcept {
947  return ::qHash(key->toNm(), seed);
948 }
949 
950 /*******************************************************************************
951  * End of File
952  ******************************************************************************/
953 
954 } // namespace librepcb
955 
956 #endif // LIBREPCB_LENGTH_H
qreal toPx() const noexcept
Get the length in pixels (for QGraphics* objects)
Definition: length.h:273
Definition: length.h:646
Length operator*(const UnsignedLength &lhs, LengthBase_t rhs) noexcept
Definition: length.h:673
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:109
Length & operator+=(const Length &rhs)
Definition: length.h:466
constexpr bool operator!=(LengthBase_t rhs) const
Definition: length.h:537
constexpr bool operator!=(const Length &rhs) const
Definition: length.h:534
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: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:598
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:946
bool operator>=(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:700
QString toNmString() const noexcept
Get the length in nanometers as a QString.
Definition: length.h:221
Length operator%(const Length &rhs) const
Definition: length.h:505
void setLengthNm(LengthBase_t nanometers) noexcept
Set the length in nanometers.
Definition: length.h:123
static constexpr qreal sNmPerPixel
Definition: length.h:597
bool operator>(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:694
Length operator-(const Length &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:685
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:647
qreal toMm() const noexcept
Get the length in millimeters.
Definition: length.h:230
LengthBase_t toNm() const noexcept
Get the length in nanometers.
Definition: length.h:213
UnsignedLength & operator+=(UnsignedLength &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:667
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
SExpression serializeToSExpression(const HAlign &obj)
Definition: alignment.h:76
~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:525
constexpr bool operator<(LengthBase_t rhs) const
Definition: length.h:515
constexpr bool operator==(LengthBase_t rhs) const
Definition: length.h:531
Length operator-(const Length &rhs) const
Definition: length.h:494
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:90
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:280
Definition: length.h:767
constexpr bool operator==(const Length &rhs) const
Definition: length.h:528
Length & operator*=(const Length &rhs)
Definition: length.h:474
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:637
Length & operator/=(LengthBase_t rhs)
Definition: length.h:486
Length & operator-=(const Length &rhs)
Definition: length.h:470
UnsignedLength operator+(const UnsignedLength &lhs, const UnsignedLength &rhs) noexcept
Definition: length.h:661
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:497
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:516
qreal toMil() const noexcept
Get the length in mils (1/1000 inches)
Definition: length.h:261
void setLengthPx(qreal pixels)
Set the length in pixels (from QGraphics* objects)
Definition: length.h:204
constexpr bool operator>=(LengthBase_t rhs) const
Definition: length.h:519
static constexpr LengthBase_t sNmPerMil
1 inch = 25.4mm
Definition: length.h:594
Length operator*(LengthBase_t rhs) const
Definition: length.h:500
constexpr bool operator>(const Length &rhs) const
Definition: length.h:508
Definition: length.h:635
Length & operator*=(LengthBase_t rhs)
Definition: length.h:478
bool operator<(const UnsignedLength &lhs, const Length &rhs) noexcept
Definition: length.h:706
The RuntimeError class.
Definition: exceptions.h:219
Length operator/(LengthBase_t rhs) const
Definition: length.h:504
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:768
LengthBase_t mNanometers
the length in nanometers
Definition: length.h:590
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:493
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:512
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:758
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:50
constexpr bool operator<=(const Length &rhs) const
Definition: length.h:522
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:482
Length operator/(const UnsignedLength &lhs, LengthBase_t rhs) noexcept
Definition: length.h:676
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:780
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
static constexpr LengthBase_t sNmPerInch
1 inch = 25.4mm
Definition: length.h:593
Length operator/(const Length &rhs) const
Definition: length.h:501
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:782
Length operator+(const Length &rhs) const
Definition: length.h:490
qreal toInch() const noexcept
Get the length in inches.
Definition: length.h:252
void setLengthMm(qreal millimeters)
Set the length in millimeters.
Definition: length.h:140
static constexpr LengthBase_t sPixelsPerInch
72 dpi for the QGraphics* objects
Definition: length.h:595
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:511
The SExpression class.
Definition: sexpression.h:57
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:119
constexpr Length() noexcept
Default Constructor.
Definition: length.h:93
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:659
Definition: length.h:756
constexpr Length(LengthBase_t nanometers) noexcept
Constructor with length in nanometers.
Definition: length.h:108