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 "../serialization/sexpression.h"
28 
29 #include <type_safe/constrained_type.hpp>
30 
31 #include <QtCore>
32 
33 /*******************************************************************************
34  * Namespace / Forward Declarations
35  ******************************************************************************/
36 namespace librepcb {
37 
38 /*******************************************************************************
39  * Typedefs
40  ******************************************************************************/
41 
59 #ifdef USE_32BIT_LENGTH_UNITS
60 typedef qint32 LengthBase_t;
61 #else
62 typedef qint64 LengthBase_t;
63 #endif
64 
65 /*******************************************************************************
66  * Class Length
67  ******************************************************************************/
68 
83 class Length {
84  Q_DECLARE_TR_FUNCTIONS(Length)
85 
86 public:
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 toMm() const noexcept { return (qreal)mNanometers / 1e6; }
232 
244  QString toMmString() const noexcept;
245 
253  qreal toInch() const noexcept { return (qreal)mNanometers / sNmPerInch; }
254 
262  qreal toMil() const noexcept { return (qreal)mNanometers / sNmPerMil; }
263 
274  qreal toPx() const noexcept { return mNanometers * sPixelsPerNm; }
275 
276  // General Methods
277 
285  Length abs() const noexcept;
286 
294  Length& makeAbs() noexcept;
295 
306  Length mappedToGrid(const Length& gridInterval) const noexcept;
307 
318  Length& mapToGrid(const Length& gridInterval) noexcept;
319 
332  Length scaled(qreal factor) const noexcept;
333 
346  Length& scale(qreal factor) noexcept;
347 
348  // Static Functions
349 
368  static Length fromMm(qreal millimeters,
369  const Length& gridInterval = Length(0));
370 
396  static Length fromMm(const QString& millimeters,
397  const Length& gridInterval = Length(0));
398 
417  static Length fromInch(qreal inches, const Length& gridInterval = Length(0));
418 
437  static Length fromMil(qreal mils, const Length& gridInterval = Length(0));
438 
460  static Length fromPx(qreal pixels, const Length& gridInterval = Length(0));
461 
467  static Length min() noexcept;
468 
474  static Length max() noexcept;
475 
476  // Operators
477  Length& operator=(const Length& rhs) {
478  mNanometers = rhs.mNanometers;
479  return *this;
480  }
481  Length& operator+=(const Length& rhs) {
482  mNanometers += rhs.mNanometers;
483  return *this;
484  }
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*=(LengthBase_t rhs) {
494  mNanometers *= rhs;
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) const {
506  return Length(mNanometers + rhs.mNanometers);
507  }
508  Length operator-() const { return Length(-mNanometers); }
509  Length operator-(const Length& rhs) const {
510  return Length(mNanometers - rhs.mNanometers);
511  }
512  Length operator*(const Length& rhs) const {
513  return Length(mNanometers * rhs.mNanometers);
514  }
515  Length operator*(LengthBase_t rhs) const { return Length(mNanometers * rhs); }
516  Length operator/(const Length& rhs) const {
517  return Length(mNanometers / rhs.mNanometers);
518  }
519  Length operator/(LengthBase_t rhs) const { return Length(mNanometers / rhs); }
520  Length operator%(const Length& rhs) const {
521  return Length(mNanometers % rhs.mNanometers);
522  }
523  constexpr bool operator>(const Length& rhs) const {
524  return mNanometers > rhs.mNanometers;
525  }
526  constexpr bool operator>(LengthBase_t rhs) const { return mNanometers > rhs; }
527  constexpr bool operator<(const Length& rhs) const {
528  return mNanometers < rhs.mNanometers;
529  }
530  constexpr bool operator<(LengthBase_t rhs) const { return mNanometers < rhs; }
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  constexpr bool operator==(const Length& rhs) const {
544  return mNanometers == rhs.mNanometers;
545  }
546  constexpr bool operator==(LengthBase_t rhs) const {
547  return mNanometers == rhs;
548  }
549  constexpr bool operator!=(const Length& rhs) const {
550  return mNanometers != rhs.mNanometers;
551  }
552  constexpr bool operator!=(LengthBase_t rhs) const {
553  return mNanometers != rhs;
554  }
555 
556 private:
557  // Private Functions
558 
572  void setLengthFromFloat(qreal nanometers);
573 
574  // Private Static Functions
575 
587  static LengthBase_t mapNmToGrid(LengthBase_t nanometers,
588  const Length& gridInterval) noexcept;
589 
602  static LengthBase_t mmStringToNm(const QString& millimeters);
603 
604  // Private Member Variables
605  LengthBase_t mNanometers;
606 
607  // Static Length Converting Constants
608  static constexpr LengthBase_t sNmPerInch = 25400000;
609  static constexpr LengthBase_t sNmPerMil = 25400;
610  static constexpr LengthBase_t sPixelsPerInch =
611  72;
612  static constexpr qreal sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch;
613  static constexpr qreal sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch;
614 };
615 
616 /*******************************************************************************
617  * Non-Member Functions
618  ******************************************************************************/
619 
620 template <>
621 inline SExpression serialize(const Length& obj) {
622  return SExpression::createToken(obj.toMmString());
623 }
624 
625 template <>
626 inline Length deserialize(const SExpression& sexpr, const Version& fileFormat) {
627  Q_UNUSED(fileFormat);
628  return Length::fromMm(sexpr.getValue());
629 }
630 
631 inline QDataStream& operator<<(QDataStream& stream, const Length& length) {
632  stream << length.toMm();
633  return stream;
634 }
635 
636 inline QDebug operator<<(QDebug stream, const Length& length) {
637  stream << QString("Length(%1mm)").arg(length.toMm());
638  return stream;
639 }
640 
641 inline uint qHash(const Length& key, uint seed = 0) noexcept {
642  return ::qHash(key.toNm(), seed);
643 }
644 
645 /*******************************************************************************
646  * Class UnsignedLength
647  ******************************************************************************/
648 
650  template <typename Value, typename Predicate>
651  static constexpr auto verify(Value&& val, const Predicate& p) ->
652  typename std::decay<Value>::type {
653  return p(val) ? std::forward<Value>(val)
654  : (throw RuntimeError(__FILE__, __LINE__,
655  Length::tr("Value must be >= 0!")),
656  std::forward<Value>(val));
657  }
658 };
659 
661  constexpr bool operator()(const Length& l) const noexcept { return l >= 0; }
662 };
663 
671 using UnsignedLength =
672  type_safe::constrained_type<Length, UnsignedLengthConstraint,
674 
676  const UnsignedLength& rhs) noexcept {
677  return UnsignedLength(*lhs +
678  *rhs); // will not throw as long as there's no overflow
679 }
680 
682  const UnsignedLength& rhs) noexcept {
683  lhs = lhs + rhs; // will not throw as long as there's no overflow
684  return lhs;
685 }
686 
687 inline Length operator*(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
688  return (*lhs) * rhs;
689 }
690 inline Length operator/(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
691  return (*lhs) / rhs;
692 }
693 inline Length operator+(const Length& lhs, const UnsignedLength& rhs) noexcept {
694  return lhs + *rhs;
695 }
696 inline Length operator+(const UnsignedLength& lhs, const Length& rhs) noexcept {
697  return *lhs + rhs;
698 }
699 inline Length operator-(const Length& lhs, const UnsignedLength& rhs) noexcept {
700  return lhs - *rhs;
701 }
702 inline Length operator-(const UnsignedLength& lhs, const Length& rhs) noexcept {
703  return *lhs - rhs;
704 }
705 inline Length operator-(const UnsignedLength& lhs) noexcept {
706  return -(*lhs);
707 }
708 inline bool operator>(const UnsignedLength& lhs, const Length& rhs) noexcept {
709  return (*lhs) > rhs;
710 }
711 inline bool operator>(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
712  return (*lhs) > rhs;
713 }
714 inline bool operator>=(const UnsignedLength& lhs, const Length& rhs) noexcept {
715  return (*lhs) >= rhs;
716 }
717 inline bool operator>=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
718  return (*lhs) >= rhs;
719 }
720 inline bool operator<(const UnsignedLength& lhs, const Length& rhs) noexcept {
721  return (*lhs) <= rhs;
722 }
723 inline bool operator<(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
724  return (*lhs) <= rhs;
725 }
726 inline bool operator==(const UnsignedLength& lhs, const Length& rhs) noexcept {
727  return (*lhs) == rhs;
728 }
729 inline bool operator==(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
730  return (*lhs) == rhs;
731 }
732 inline bool operator!=(const UnsignedLength& lhs, const Length& rhs) noexcept {
733  return (*lhs) != rhs;
734 }
735 inline bool operator!=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
736  return (*lhs) != rhs;
737 }
738 
739 template <>
741  return SExpression::createToken(obj->toMmString());
742 }
743 
744 template <>
746  const Version& fileFormat) {
747  return UnsignedLength(deserialize<Length>(sexpr, fileFormat)); // can throw
748 }
749 
750 inline QDataStream& operator<<(QDataStream& stream,
751  const UnsignedLength& length) {
752  stream << length->toMm();
753  return stream;
754 }
755 
756 inline QDebug operator<<(QDebug stream, const UnsignedLength& length) {
757  stream << QString("UnsignedLength(%1mm)").arg(length->toMm());
758  return stream;
759 }
760 
761 inline uint qHash(const UnsignedLength& key, uint seed = 0) noexcept {
762  return ::qHash(key->toNm(), seed);
763 }
764 
765 /*******************************************************************************
766  * Class PositiveLength
767  ******************************************************************************/
768 
770  template <typename Value, typename Predicate>
771  static constexpr auto verify(Value&& val, const Predicate& p) ->
772  typename std::decay<Value>::type {
773  return p(val) ? std::forward<Value>(val)
774  : (throw RuntimeError(__FILE__, __LINE__,
775  Length::tr("Value must be > 0!")),
776  std::forward<Value>(val));
777  }
778 };
779 
781  constexpr bool operator()(const Length& l) const noexcept { return l > 0; }
782 };
783 
791 using PositiveLength =
792  type_safe::constrained_type<Length, PositiveLengthConstraint,
794 
796  return UnsignedLength(*l);
797 }
798 
800  const PositiveLength& rhs) noexcept {
801  return PositiveLength(*lhs +
802  *rhs); // will not throw as long as there's no overflow
803 }
804 
806  const UnsignedLength& rhs) noexcept {
807  return PositiveLength(*lhs +
808  *rhs); // will not throw as long as there's no overflow
809 }
810 
812  const PositiveLength& rhs) noexcept {
813  return PositiveLength(*lhs +
814  *rhs); // will not throw as long as there's no overflow
815 }
816 
818  const PositiveLength& rhs) noexcept {
819  lhs = lhs + rhs; // will not throw as long as there's no overflow
820  return lhs;
821 }
822 
824  const UnsignedLength& rhs) noexcept {
825  lhs = lhs + rhs; // will not throw as long as there's no overflow
826  return lhs;
827 }
828 
830  const PositiveLength& rhs) noexcept {
831  lhs = positiveToUnsigned(
832  lhs + rhs); // will not throw as long as there's no overflow
833  return lhs;
834 }
835 
836 inline Length operator*(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
837  return (*lhs) * rhs;
838 }
839 inline Length operator/(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
840  return (*lhs) / rhs;
841 }
842 inline Length operator+(const Length& lhs, const PositiveLength& rhs) noexcept {
843  return lhs + *rhs;
844 }
845 inline Length operator+(const PositiveLength& lhs, const Length& rhs) noexcept {
846  return *lhs + rhs;
847 }
848 inline Length operator-(const Length& lhs, const PositiveLength& rhs) noexcept {
849  return lhs - *rhs;
850 }
851 inline Length operator-(const PositiveLength& lhs, const Length& rhs) noexcept {
852  return *lhs - rhs;
853 }
854 inline Length operator-(const UnsignedLength& lhs,
855  const PositiveLength& rhs) noexcept {
856  return *lhs - *rhs;
857 }
858 inline Length operator-(const PositiveLength& lhs,
859  const UnsignedLength& rhs) noexcept {
860  return *lhs - *rhs;
861 }
862 inline Length operator-(const PositiveLength& lhs) noexcept {
863  return -(*lhs);
864 }
865 inline bool operator>(const UnsignedLength& lhs,
866  const PositiveLength& rhs) noexcept {
867  return (*lhs) > (*rhs);
868 }
869 inline bool operator>(const PositiveLength& lhs,
870  const UnsignedLength& rhs) noexcept {
871  return (*lhs) > (*rhs);
872 }
873 inline bool operator>(const PositiveLength& lhs, const Length& rhs) noexcept {
874  return (*lhs) > rhs;
875 }
876 inline bool operator>(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
877  return (*lhs) > rhs;
878 }
879 inline bool operator>=(const UnsignedLength& lhs,
880  const PositiveLength& rhs) noexcept {
881  return (*lhs) >= (*rhs);
882 }
883 inline bool operator>=(const PositiveLength& lhs,
884  const UnsignedLength& rhs) noexcept {
885  return (*lhs) >= (*rhs);
886 }
887 inline bool operator>=(const PositiveLength& lhs, const Length& rhs) noexcept {
888  return (*lhs) >= rhs;
889 }
890 inline bool operator>=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
891  return (*lhs) >= rhs;
892 }
893 inline bool operator<(const UnsignedLength& lhs,
894  const PositiveLength& rhs) noexcept {
895  return (*lhs) < (*rhs);
896 }
897 inline bool operator<(const PositiveLength& lhs,
898  const UnsignedLength& rhs) noexcept {
899  return (*lhs) < (*rhs);
900 }
901 inline bool operator<(const PositiveLength& lhs, const Length& rhs) noexcept {
902  return (*lhs) <= rhs;
903 }
904 inline bool operator<(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
905  return (*lhs) <= rhs;
906 }
907 inline bool operator==(const UnsignedLength& lhs,
908  const PositiveLength& rhs) noexcept {
909  return (*lhs) == (*rhs);
910 }
911 inline bool operator==(const PositiveLength& lhs,
912  const UnsignedLength& rhs) noexcept {
913  return (*lhs) == (*rhs);
914 }
915 inline bool operator==(const PositiveLength& lhs, const Length& rhs) noexcept {
916  return (*lhs) == rhs;
917 }
918 inline bool operator==(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
919  return (*lhs) == rhs;
920 }
921 inline bool operator!=(const UnsignedLength& lhs,
922  const PositiveLength& rhs) noexcept {
923  return (*lhs) != (*rhs);
924 }
925 inline bool operator!=(const PositiveLength& lhs,
926  const UnsignedLength& rhs) noexcept {
927  return (*lhs) != (*rhs);
928 }
929 inline bool operator!=(const PositiveLength& lhs, const Length& rhs) noexcept {
930  return (*lhs) != rhs;
931 }
932 inline bool operator!=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
933  return (*lhs) != rhs;
934 }
935 
936 template <>
938  return SExpression::createToken(obj->toMmString());
939 }
940 
941 template <>
943  const Version& fileFormat) {
944  return PositiveLength(deserialize<Length>(sexpr, fileFormat)); // can throw
945 }
946 
947 inline QDataStream& operator<<(QDataStream& stream,
948  const PositiveLength& length) {
949  stream << length->toMm();
950  return stream;
951 }
952 
953 inline QDebug operator<<(QDebug stream, const PositiveLength& length) {
954  stream << QString("PositiveLength(%1mm)").arg(length->toMm());
955  return stream;
956 }
957 
958 inline uint qHash(const PositiveLength& key, uint seed = 0) noexcept {
959  return ::qHash(key->toNm(), seed);
960 }
961 
962 /*******************************************************************************
963  * End of File
964  ******************************************************************************/
965 
966 } // namespace librepcb
967 
969 
970 #endif
qreal toPx() const noexcept
Get the length in pixels (for QGraphics* objects)
Definition: length.h:274
Definition: length.h:660
The Version class represents a version number in the format "1.42.7".
Definition: version.h:60
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:110
Length operator-() const
Definition: length.h:508
Length & operator+=(const Length &rhs)
Definition: length.h:481
Length operator%(const Length &rhs) const
Definition: length.h:520
constexpr bool operator>=(LengthBase_t rhs) const
Definition: length.h:534
constexpr Length(const Length &length) noexcept
Copy Constructor.
Definition: length.h:101
Length mappedToGrid(const Length &gridInterval) const noexcept
Get a Length object which is mapped to a specific grid interval.
Definition: length.cpp:65
Length operator+(const Length &rhs) const
Definition: length.h:505
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:613
Definition: airwiresbuilder.cpp:34
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:958
QString toNmString() const noexcept
Get the length in nanometers as a QString.
Definition: length.h:222
void setLengthNm(LengthBase_t nanometers) noexcept
Set the length in nanometers.
Definition: length.h:124
static constexpr qreal sNmPerPixel
Definition: length.h:612
Q_DECLARE_METATYPE(QImage)
qint64 LengthBase_t
This type is the ONLY base type to store all lengths (always in nanometers)!
Definition: length.h:62
constexpr bool operator==(LengthBase_t rhs) const
Definition: length.h:546
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:661
qreal toMm() const noexcept
Get the length in millimeters.
Definition: length.h:231
LengthBase_t toNm() const noexcept
Get the length in nanometers.
Definition: length.h:214
constexpr bool operator<=(LengthBase_t rhs) const
Definition: length.h:540
constexpr bool operator!=(const Length &rhs) const
Definition: length.h:549
~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>(const Length &rhs) const
Definition: length.h:523
static Length min() noexcept
Get the smallest possible length value.
Definition: length.cpp:119
constexpr bool operator==(const Length &rhs) const
Definition: length.h:543
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:301
Length operator-(const Length &rhs) const
Definition: length.h:509
Definition: length.h:780
Length & operator*=(const Length &rhs)
Definition: length.h:489
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:651
Length & operator/=(LengthBase_t rhs)
Definition: length.h:501
constexpr bool operator>(LengthBase_t rhs) const
Definition: length.h:526
Length & operator-=(const Length &rhs)
Definition: length.h:485
AttributeKey deserialize(const SExpression &sexpr, const Version &fileFormat)
Definition: attributekey.h:104
void setLengthFromFloat(qreal nanometers)
Set the length from a floating point number in nanometers.
Definition: length.cpp:131
Length operator/(const Length &rhs) const
Definition: length.h:516
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
static Length max() noexcept
Get the highest possible length value.
Definition: length.cpp:123
constexpr bool operator>=(const Length &rhs) const
Definition: length.h:531
qreal toMil() const noexcept
Get the length in mils (1/1000 inches)
Definition: length.h:262
void setLengthPx(qreal pixels)
Set the length in pixels (from QGraphics* objects)
Definition: length.h:205
Length operator*(const Length &rhs) const
Definition: length.h:512
static constexpr LengthBase_t sNmPerMil
1 inch = 25.4mm
Definition: length.h:609
constexpr bool operator!=(LengthBase_t rhs) const
Definition: length.h:552
Definition: length.h:649
Length & operator*=(LengthBase_t rhs)
Definition: length.h:493
The RuntimeError class.
Definition: exceptions.h:216
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:781
Length & operator=(const Length &rhs)
Definition: length.h:477
LengthBase_t mNanometers
the length in nanometers
Definition: length.h:605
constexpr bool operator<(LengthBase_t rhs) const
Definition: length.h:530
constexpr bool operator<(const Length &rhs) const
Definition: length.h:527
static LengthBase_t mmStringToNm(const QString &millimeters)
Convert a length from a QString (in millimeters) to an integer (in nanometers)
Definition: length.cpp:186
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:146
Length operator/(LengthBase_t rhs) const
Definition: length.h:519
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:771
void setLengthInch(qreal inches)
Set the length in inches.
Definition: length.h:173
Length abs() const noexcept
Get a Length object with absolute value (mNanometers >= 0)
Definition: length.cpp:50
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:497
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:793
void setLengthMil(qreal mils)
Set the length in mils (1/1000 inch)
Definition: length.h:188
void setLengthMm(const QString &millimeters)
Set the length in millimeters, represented in a QString.
Definition: length.h:156
constexpr bool operator<=(const Length &rhs) const
Definition: length.h:537
static constexpr LengthBase_t sNmPerInch
1 inch = 25.4mm
Definition: length.h:608
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
UnsignedLength positiveToUnsigned(const PositiveLength &l) noexcept
Definition: length.h:795
qreal toInch() const noexcept
Get the length in inches.
Definition: length.h:253
void setLengthMm(qreal millimeters)
Set the length in millimeters.
Definition: length.h:141
SExpression serialize(const AttributeKey &obj)
Definition: attributekey.h:99
Length operator*(LengthBase_t rhs) const
Definition: length.h:515
static constexpr LengthBase_t sPixelsPerInch
72 dpi for the QGraphics* objects
Definition: length.h:610
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
const QString & getValue() const
Definition: sexpression.cpp:68
The SExpression class.
Definition: sexpression.h:72
uint qHash(const AttributeKey &key, uint seed=0) noexcept
Definition: attributekey.h:120
constexpr Length() noexcept
Default Constructor.
Definition: length.h:94
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:673
Definition: length.h:769
constexpr Length(LengthBase_t nanometers) noexcept
Constructor with length in nanometers.
Definition: length.h:109