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_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 
466  static Length min() noexcept;
467 
473  static Length max() noexcept;
474 
475  // Operators
476  Length& operator=(const Length& rhs) {
477  mNanometers = rhs.mNanometers;
478  return *this;
479  }
480  Length& operator+=(const Length& rhs) {
481  mNanometers += rhs.mNanometers;
482  return *this;
483  }
484  Length& operator-=(const Length& rhs) {
485  mNanometers -= rhs.mNanometers;
486  return *this;
487  }
488  Length& operator*=(const Length& rhs) {
489  mNanometers *= rhs.mNanometers;
490  return *this;
491  }
492  Length& operator*=(LengthBase_t rhs) {
493  mNanometers *= rhs;
494  return *this;
495  }
496  Length& operator/=(const Length& rhs) {
497  mNanometers /= rhs.mNanometers;
498  return *this;
499  }
500  Length& operator/=(LengthBase_t rhs) {
501  mNanometers /= rhs;
502  return *this;
503  }
504  Length operator+(const Length& rhs) const {
505  return Length(mNanometers + rhs.mNanometers);
506  }
507  Length operator-() const { return Length(-mNanometers); }
508  Length operator-(const Length& rhs) const {
509  return Length(mNanometers - rhs.mNanometers);
510  }
511  Length operator*(const Length& rhs) const {
512  return Length(mNanometers * rhs.mNanometers);
513  }
514  Length operator*(LengthBase_t rhs) const { return Length(mNanometers * rhs); }
515  Length operator/(const Length& rhs) const {
516  return Length(mNanometers / rhs.mNanometers);
517  }
518  Length operator/(LengthBase_t rhs) const { return Length(mNanometers / rhs); }
519  Length operator%(const Length& rhs) const {
520  return Length(mNanometers % rhs.mNanometers);
521  }
522  constexpr bool operator>(const Length& rhs) const {
523  return mNanometers > rhs.mNanometers;
524  }
525  constexpr bool operator>(LengthBase_t rhs) const { return mNanometers > rhs; }
526  constexpr bool operator<(const Length& rhs) const {
527  return mNanometers < rhs.mNanometers;
528  }
529  constexpr bool operator<(LengthBase_t rhs) const { return mNanometers < rhs; }
530  constexpr bool operator>=(const Length& rhs) const {
531  return mNanometers >= rhs.mNanometers;
532  }
533  constexpr bool operator>=(LengthBase_t rhs) const {
534  return mNanometers >= rhs;
535  }
536  constexpr bool operator<=(const Length& rhs) const {
537  return mNanometers <= rhs.mNanometers;
538  }
539  constexpr bool operator<=(LengthBase_t rhs) const {
540  return mNanometers <= rhs;
541  }
542  constexpr bool operator==(const Length& rhs) const {
543  return mNanometers == rhs.mNanometers;
544  }
545  constexpr bool operator==(LengthBase_t rhs) const {
546  return mNanometers == rhs;
547  }
548  constexpr bool operator!=(const Length& rhs) const {
549  return mNanometers != rhs.mNanometers;
550  }
551  constexpr bool operator!=(LengthBase_t rhs) const {
552  return mNanometers != rhs;
553  }
554 
555 private:
556  // Private Functions
557 
571  void setLengthFromFloat(qreal nanometers);
572 
573  // Private Static Functions
574 
586  static LengthBase_t mapNmToGrid(LengthBase_t nanometers,
587  const Length& gridInterval) noexcept;
588 
601  static LengthBase_t mmStringToNm(const QString& millimeters);
602 
603  // Private Member Variables
604  LengthBase_t mNanometers;
605 
606  // Static Length Converting Constants
607  static constexpr LengthBase_t sNmPerInch = 25400000;
608  static constexpr LengthBase_t sNmPerMil = 25400;
609  static constexpr LengthBase_t sPixelsPerInch =
610  72;
611  static constexpr qreal sNmPerPixel = (qreal)sNmPerInch / sPixelsPerInch;
612  static constexpr qreal sPixelsPerNm = (qreal)sPixelsPerInch / sNmPerInch;
613 };
614 
615 /*******************************************************************************
616  * Non-Member Functions
617  ******************************************************************************/
618 
619 template <>
620 inline SExpression serialize(const Length& obj) {
621  return SExpression::createToken(obj.toMmString());
622 }
623 
624 template <>
625 inline Length deserialize(const SExpression& sexpr, const Version& fileFormat) {
626  Q_UNUSED(fileFormat);
627  return Length::fromMm(sexpr.getValue());
628 }
629 
630 inline QDataStream& operator<<(QDataStream& stream, const Length& length) {
631  stream << length.toMm();
632  return stream;
633 }
634 
635 inline QDebug operator<<(QDebug stream, const Length& length) {
636  stream << QString("Length(%1mm)").arg(length.toMm());
637  return stream;
638 }
639 
640 inline uint qHash(const Length& key, uint seed = 0) noexcept {
641  return ::qHash(key.toNm(), seed);
642 }
643 
644 /*******************************************************************************
645  * Class UnsignedLength
646  ******************************************************************************/
647 
649  template <typename Value, typename Predicate>
650  static constexpr auto verify(Value&& val, const Predicate& p) ->
651  typename std::decay<Value>::type {
652  return p(val) ? std::forward<Value>(val)
653  : (throw RuntimeError(__FILE__, __LINE__,
654  Length::tr("Value must be >= 0!")),
655  std::forward<Value>(val));
656  }
657 };
658 
660  constexpr bool operator()(const Length& l) const noexcept { return l >= 0; }
661 };
662 
670 using UnsignedLength =
671  type_safe::constrained_type<Length, UnsignedLengthConstraint,
673 
675  const UnsignedLength& rhs) noexcept {
676  return UnsignedLength(*lhs +
677  *rhs); // will not throw as long as there's no overflow
678 }
679 
681  const UnsignedLength& rhs) noexcept {
682  lhs = lhs + rhs; // will not throw as long as there's no overflow
683  return lhs;
684 }
685 
686 inline Length operator*(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
687  return (*lhs) * rhs;
688 }
689 inline Length operator/(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
690  return (*lhs) / rhs;
691 }
692 inline Length operator+(const Length& lhs, const UnsignedLength& rhs) noexcept {
693  return lhs + *rhs;
694 }
695 inline Length operator+(const UnsignedLength& lhs, const Length& rhs) noexcept {
696  return *lhs + rhs;
697 }
698 inline Length operator-(const Length& lhs, const UnsignedLength& rhs) noexcept {
699  return lhs - *rhs;
700 }
701 inline Length operator-(const UnsignedLength& lhs, const Length& rhs) noexcept {
702  return *lhs - rhs;
703 }
704 inline Length operator-(const UnsignedLength& lhs) noexcept {
705  return -(*lhs);
706 }
707 inline bool operator>(const UnsignedLength& lhs, const Length& rhs) noexcept {
708  return (*lhs) > rhs;
709 }
710 inline bool operator>(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
711  return (*lhs) > rhs;
712 }
713 inline bool operator>=(const UnsignedLength& lhs, const Length& rhs) noexcept {
714  return (*lhs) >= rhs;
715 }
716 inline bool operator>=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
717  return (*lhs) >= rhs;
718 }
719 inline bool operator<(const UnsignedLength& lhs, const Length& rhs) noexcept {
720  return (*lhs) <= rhs;
721 }
722 inline bool operator<(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
723  return (*lhs) <= rhs;
724 }
725 inline bool operator==(const UnsignedLength& lhs, const Length& rhs) noexcept {
726  return (*lhs) == rhs;
727 }
728 inline bool operator==(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
729  return (*lhs) == rhs;
730 }
731 inline bool operator!=(const UnsignedLength& lhs, const Length& rhs) noexcept {
732  return (*lhs) != rhs;
733 }
734 inline bool operator!=(const UnsignedLength& lhs, LengthBase_t rhs) noexcept {
735  return (*lhs) != rhs;
736 }
737 
738 template <>
740  return SExpression::createToken(obj->toMmString());
741 }
742 
743 template <>
745  const Version& fileFormat) {
746  return UnsignedLength(deserialize<Length>(sexpr, fileFormat)); // can throw
747 }
748 
749 inline QDataStream& operator<<(QDataStream& stream,
750  const UnsignedLength& length) {
751  stream << length->toMm();
752  return stream;
753 }
754 
755 inline QDebug operator<<(QDebug stream, const UnsignedLength& length) {
756  stream << QString("UnsignedLength(%1mm)").arg(length->toMm());
757  return stream;
758 }
759 
760 inline uint qHash(const UnsignedLength& key, uint seed = 0) noexcept {
761  return ::qHash(key->toNm(), seed);
762 }
763 
764 /*******************************************************************************
765  * Class PositiveLength
766  ******************************************************************************/
767 
769  template <typename Value, typename Predicate>
770  static constexpr auto verify(Value&& val, const Predicate& p) ->
771  typename std::decay<Value>::type {
772  return p(val) ? std::forward<Value>(val)
773  : (throw RuntimeError(__FILE__, __LINE__,
774  Length::tr("Value must be > 0!")),
775  std::forward<Value>(val));
776  }
777 };
778 
780  constexpr bool operator()(const Length& l) const noexcept { return l > 0; }
781 };
782 
790 using PositiveLength =
791  type_safe::constrained_type<Length, PositiveLengthConstraint,
793 
795  return UnsignedLength(*l);
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 UnsignedLength& rhs) noexcept {
806  return PositiveLength(*lhs +
807  *rhs); // will not throw as long as there's no overflow
808 }
809 
811  const PositiveLength& rhs) noexcept {
812  return PositiveLength(*lhs +
813  *rhs); // will not throw as long as there's no overflow
814 }
815 
817  const PositiveLength& rhs) noexcept {
818  lhs = lhs + rhs; // will not throw as long as there's no overflow
819  return lhs;
820 }
821 
823  const UnsignedLength& rhs) noexcept {
824  lhs = lhs + rhs; // will not throw as long as there's no overflow
825  return lhs;
826 }
827 
829  const PositiveLength& rhs) noexcept {
830  lhs = positiveToUnsigned(
831  lhs + rhs); // will not throw as long as there's no overflow
832  return lhs;
833 }
834 
835 inline Length operator*(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
836  return (*lhs) * rhs;
837 }
838 inline Length operator/(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
839  return (*lhs) / rhs;
840 }
841 inline Length operator+(const Length& lhs, const PositiveLength& rhs) noexcept {
842  return lhs + *rhs;
843 }
844 inline Length operator+(const PositiveLength& lhs, const Length& rhs) noexcept {
845  return *lhs + rhs;
846 }
847 inline Length operator-(const Length& lhs, const PositiveLength& rhs) noexcept {
848  return lhs - *rhs;
849 }
850 inline Length operator-(const PositiveLength& lhs, const Length& rhs) noexcept {
851  return *lhs - rhs;
852 }
853 inline Length operator-(const UnsignedLength& lhs,
854  const PositiveLength& rhs) noexcept {
855  return *lhs - *rhs;
856 }
857 inline Length operator-(const PositiveLength& lhs,
858  const UnsignedLength& rhs) noexcept {
859  return *lhs - *rhs;
860 }
861 inline Length operator-(const PositiveLength& lhs) noexcept {
862  return -(*lhs);
863 }
864 inline bool operator>(const UnsignedLength& lhs,
865  const PositiveLength& rhs) noexcept {
866  return (*lhs) > (*rhs);
867 }
868 inline bool operator>(const PositiveLength& lhs,
869  const UnsignedLength& rhs) noexcept {
870  return (*lhs) > (*rhs);
871 }
872 inline bool operator>(const PositiveLength& lhs, const Length& rhs) noexcept {
873  return (*lhs) > rhs;
874 }
875 inline bool operator>(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
876  return (*lhs) > rhs;
877 }
878 inline bool operator>=(const UnsignedLength& lhs,
879  const PositiveLength& rhs) noexcept {
880  return (*lhs) >= (*rhs);
881 }
882 inline bool operator>=(const PositiveLength& lhs,
883  const UnsignedLength& rhs) noexcept {
884  return (*lhs) >= (*rhs);
885 }
886 inline bool operator>=(const PositiveLength& lhs, const Length& rhs) noexcept {
887  return (*lhs) >= rhs;
888 }
889 inline bool operator>=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
890  return (*lhs) >= rhs;
891 }
892 inline bool operator<(const UnsignedLength& lhs,
893  const PositiveLength& rhs) noexcept {
894  return (*lhs) < (*rhs);
895 }
896 inline bool operator<(const PositiveLength& lhs,
897  const UnsignedLength& rhs) noexcept {
898  return (*lhs) < (*rhs);
899 }
900 inline bool operator<(const PositiveLength& lhs, const Length& rhs) noexcept {
901  return (*lhs) <= rhs;
902 }
903 inline bool operator<(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
904  return (*lhs) <= rhs;
905 }
906 inline bool operator==(const UnsignedLength& lhs,
907  const PositiveLength& rhs) noexcept {
908  return (*lhs) == (*rhs);
909 }
910 inline bool operator==(const PositiveLength& lhs,
911  const UnsignedLength& rhs) noexcept {
912  return (*lhs) == (*rhs);
913 }
914 inline bool operator==(const PositiveLength& lhs, const Length& rhs) noexcept {
915  return (*lhs) == rhs;
916 }
917 inline bool operator==(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
918  return (*lhs) == rhs;
919 }
920 inline bool operator!=(const UnsignedLength& lhs,
921  const PositiveLength& rhs) noexcept {
922  return (*lhs) != (*rhs);
923 }
924 inline bool operator!=(const PositiveLength& lhs,
925  const UnsignedLength& rhs) noexcept {
926  return (*lhs) != (*rhs);
927 }
928 inline bool operator!=(const PositiveLength& lhs, const Length& rhs) noexcept {
929  return (*lhs) != rhs;
930 }
931 inline bool operator!=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
932  return (*lhs) != rhs;
933 }
934 
935 template <>
937  return SExpression::createToken(obj->toMmString());
938 }
939 
940 template <>
942  const Version& fileFormat) {
943  return PositiveLength(deserialize<Length>(sexpr, fileFormat)); // can throw
944 }
945 
946 inline QDataStream& operator<<(QDataStream& stream,
947  const PositiveLength& length) {
948  stream << length->toMm();
949  return stream;
950 }
951 
952 inline QDebug operator<<(QDebug stream, const PositiveLength& length) {
953  stream << QString("PositiveLength(%1mm)").arg(length->toMm());
954  return stream;
955 }
956 
957 inline uint qHash(const PositiveLength& key, uint seed = 0) noexcept {
958  return ::qHash(key->toNm(), seed);
959 }
960 
961 /*******************************************************************************
962  * End of File
963  ******************************************************************************/
964 
965 } // namespace librepcb
966 
967 Q_DECLARE_METATYPE(librepcb::Length)
968 
969 #endif // LIBREPCB_LENGTH_H
qreal toPx() const noexcept
Get the length in pixels (for QGraphics* objects)
Definition: length.h:273
Definition: length.h:659
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:507
Length & operator+=(const Length &rhs)
Definition: length.h:480
Length operator%(const Length &rhs) const
Definition: length.h:519
constexpr bool operator>=(LengthBase_t rhs) const
Definition: length.h:533
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 operator+(const Length &rhs) const
Definition: length.h:504
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:612
SExpression serialize(const HAlign &obj)
Definition: alignment.h:76
Definition: airwiresbuilder.cpp:32
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:957
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:611
HAlign deserialize(const SExpression &sexpr, const Version &fileFormat)
Definition: alignment.h:90
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:545
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:660
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
constexpr bool operator<=(LengthBase_t rhs) const
Definition: length.h:539
constexpr bool operator!=(const Length &rhs) const
Definition: length.h:548
~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:522
static Length min() noexcept
Get the smallest possible length value.
Definition: length.cpp:119
constexpr bool operator==(const Length &rhs) const
Definition: length.h:542
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:290
Length operator-(const Length &rhs) const
Definition: length.h:508
Definition: length.h:779
Length & operator*=(const Length &rhs)
Definition: length.h:488
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:650
Length & operator/=(LengthBase_t rhs)
Definition: length.h:500
constexpr bool operator>(LengthBase_t rhs) const
Definition: length.h:525
Length & operator-=(const Length &rhs)
Definition: length.h:484
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:515
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:530
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
Length operator*(const Length &rhs) const
Definition: length.h:511
static constexpr LengthBase_t sNmPerMil
1 inch = 25.4mm
Definition: length.h:608
constexpr bool operator!=(LengthBase_t rhs) const
Definition: length.h:551
Definition: length.h:648
Length & operator*=(LengthBase_t rhs)
Definition: length.h:492
The RuntimeError class.
Definition: exceptions.h:216
constexpr bool operator()(const Length &l) const noexcept
Definition: length.h:780
Length & operator=(const Length &rhs)
Definition: length.h:476
LengthBase_t mNanometers
the length in nanometers
Definition: length.h:604
constexpr bool operator<(LengthBase_t rhs) const
Definition: length.h:529
constexpr bool operator<(const Length &rhs) const
Definition: length.h:526
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:518
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: length.h:770
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
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:496
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:792
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:536
static constexpr LengthBase_t sNmPerInch
1 inch = 25.4mm
Definition: length.h:607
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:794
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
Length operator*(LengthBase_t rhs) const
Definition: length.h:514
static constexpr LengthBase_t sPixelsPerInch
72 dpi for the QGraphics* objects
Definition: length.h:609
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:77
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:93
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:672
Definition: length.h:768
constexpr Length(LengthBase_t nanometers) noexcept
Constructor with length in nanometers.
Definition: length.h:108