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 <>
621  return SExpression::createToken(obj.toMmString());
622 }
623 
624 template <>
626  bool throwIfEmpty) {
627  QString str = sexpr.getStringOrToken(throwIfEmpty);
628  return Length::fromMm(str);
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  bool throwIfEmpty) {
747  QString str = sexpr.getStringOrToken(throwIfEmpty);
748  return UnsignedLength(Length::fromMm(str));
749 }
750 
751 inline QDataStream& operator<<(QDataStream& stream,
752  const UnsignedLength& length) {
753  stream << length->toMm();
754  return stream;
755 }
756 
757 inline QDebug operator<<(QDebug stream, const UnsignedLength& length) {
758  stream << QString("UnsignedLength(%1mm)").arg(length->toMm());
759  return stream;
760 }
761 
762 inline uint qHash(const UnsignedLength& key, uint seed = 0) noexcept {
763  return ::qHash(key->toNm(), seed);
764 }
765 
766 /*******************************************************************************
767  * Class PositiveLength
768  ******************************************************************************/
769 
771  template <typename Value, typename Predicate>
772  static constexpr auto verify(Value&& val, const Predicate& p) ->
773  typename std::decay<Value>::type {
774  return p(val) ? std::forward<Value>(val)
775  : (throw RuntimeError(__FILE__, __LINE__,
776  Length::tr("Value must be > 0!")),
777  std::forward<Value>(val));
778  }
779 };
780 
782  constexpr bool operator()(const Length& l) const noexcept { return l > 0; }
783 };
784 
792 using PositiveLength =
793  type_safe::constrained_type<Length, PositiveLengthConstraint,
795 
797  return UnsignedLength(*l);
798 }
799 
801  const PositiveLength& rhs) noexcept {
802  return PositiveLength(*lhs +
803  *rhs); // will not throw as long as there's no overflow
804 }
805 
807  const UnsignedLength& rhs) noexcept {
808  return PositiveLength(*lhs +
809  *rhs); // will not throw as long as there's no overflow
810 }
811 
813  const PositiveLength& rhs) noexcept {
814  return PositiveLength(*lhs +
815  *rhs); // will not throw as long as there's no overflow
816 }
817 
819  const PositiveLength& rhs) noexcept {
820  lhs = lhs + rhs; // will not throw as long as there's no overflow
821  return lhs;
822 }
823 
825  const UnsignedLength& rhs) noexcept {
826  lhs = lhs + rhs; // will not throw as long as there's no overflow
827  return lhs;
828 }
829 
831  const PositiveLength& rhs) noexcept {
832  lhs = positiveToUnsigned(
833  lhs + rhs); // will not throw as long as there's no overflow
834  return lhs;
835 }
836 
837 inline Length operator*(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
838  return (*lhs) * rhs;
839 }
840 inline Length operator/(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
841  return (*lhs) / rhs;
842 }
843 inline Length operator+(const Length& lhs, const PositiveLength& rhs) noexcept {
844  return lhs + *rhs;
845 }
846 inline Length operator+(const PositiveLength& lhs, const Length& rhs) noexcept {
847  return *lhs + rhs;
848 }
849 inline Length operator-(const Length& lhs, const PositiveLength& rhs) noexcept {
850  return lhs - *rhs;
851 }
852 inline Length operator-(const PositiveLength& lhs, const Length& rhs) noexcept {
853  return *lhs - rhs;
854 }
855 inline Length operator-(const UnsignedLength& lhs,
856  const PositiveLength& rhs) noexcept {
857  return *lhs - *rhs;
858 }
859 inline Length operator-(const PositiveLength& lhs,
860  const UnsignedLength& rhs) noexcept {
861  return *lhs - *rhs;
862 }
863 inline Length operator-(const PositiveLength& lhs) noexcept {
864  return -(*lhs);
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 inline bool operator!=(const UnsignedLength& lhs,
923  const PositiveLength& rhs) noexcept {
924  return (*lhs) != (*rhs);
925 }
926 inline bool operator!=(const PositiveLength& lhs,
927  const UnsignedLength& rhs) noexcept {
928  return (*lhs) != (*rhs);
929 }
930 inline bool operator!=(const PositiveLength& lhs, const Length& rhs) noexcept {
931  return (*lhs) != rhs;
932 }
933 inline bool operator!=(const PositiveLength& lhs, LengthBase_t rhs) noexcept {
934  return (*lhs) != rhs;
935 }
936 
937 template <>
939  return SExpression::createToken(obj->toMmString());
940 }
941 
942 template <>
944  bool throwIfEmpty) {
945  QString str = sexpr.getStringOrToken(throwIfEmpty);
946  return PositiveLength(Length::fromMm(str));
947 }
948 
949 inline QDataStream& operator<<(QDataStream& stream,
950  const PositiveLength& length) {
951  stream << length->toMm();
952  return stream;
953 }
954 
955 inline QDebug operator<<(QDebug stream, const PositiveLength& length) {
956  stream << QString("PositiveLength(%1mm)").arg(length->toMm());
957  return stream;
958 }
959 
960 inline uint qHash(const PositiveLength& key, uint seed = 0) noexcept {
961  return ::qHash(key->toNm(), seed);
962 }
963 
964 /*******************************************************************************
965  * End of File
966  ******************************************************************************/
967 
968 } // namespace librepcb
969 
970 Q_DECLARE_METATYPE(librepcb::Length)
971 
972 #endif // LIBREPCB_LENGTH_H
qreal toPx() const noexcept
Get the length in pixels (for QGraphics* objects)
Definition: length.h:273
Definition: length.h:660
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:109
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
const QString & getStringOrToken(bool throwIfEmpty=false) const
Definition: sexpression.cpp:101
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
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:960
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
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:661
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
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>(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
HAlign deserializeFromSExpression(const SExpression &sexpr, bool throwIfEmpty)
Definition: alignment.h:90
static SExpression createToken(const QString &token)
Definition: sexpression.cpp:278
Length operator-(const Length &rhs) const
Definition: length.h:508
Definition: length.h:781
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:651
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:649
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:782
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:772
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:794
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:796
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
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:673
Definition: length.h:770
constexpr Length(LengthBase_t nanometers) noexcept
Constructor with length in nanometers.
Definition: length.h:108