LibrePCB Developers Documentation
vertex.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_VERTEX_H
21 #define LIBREPCB_CORE_VERTEX_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../qtcompat.h"
27 #include "../types/angle.h"
28 #include "../types/point.h"
29 
30 #include <QtCore>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 /*******************************************************************************
38  * Class Vertex
39  ******************************************************************************/
40 
44 class Vertex final {
45 public:
46  // Constructors / Destructor
47  Vertex() noexcept : mPos(), mAngle() {}
48  Vertex(const Vertex& other) noexcept
49  : mPos(other.mPos), mAngle(other.mAngle) {}
50  explicit Vertex(const Point& pos, const Angle& angle = Angle::deg0()) noexcept
51  : mPos(pos), mAngle(angle) {}
52  explicit Vertex(const SExpression& node);
53  ~Vertex() noexcept {}
54 
55  // Getters
56  const Point& getPos() const noexcept { return mPos; }
57  const Angle& getAngle() const noexcept { return mAngle; }
58 
59  // Setters
60  void setPos(const Point& pos) noexcept { mPos = pos; }
61  void setAngle(const Angle& angle) noexcept { mAngle = angle; }
62 
63  // General Methods
64 
70  void serialize(SExpression& root) const;
71 
72  // Operator Overloadings
73  Vertex& operator=(const Vertex& rhs) noexcept;
74  bool operator==(const Vertex& rhs) const noexcept;
75  bool operator!=(const Vertex& rhs) const noexcept { return !(*this == rhs); }
76 
87  bool operator<(const Vertex& rhs) const noexcept;
88 
89 private: // Data
92 };
94 
95 /*******************************************************************************
96  * Non-Member Functions
97  ******************************************************************************/
98 
99 QDebug operator<<(QDebug stream, const Vertex& vertex);
100 
101 inline QtCompat::Hash qHash(const Vertex& key,
102  QtCompat::Hash seed = 0) noexcept {
103  return ::qHash(qMakePair(key.getPos(), key.getAngle()), seed);
104 }
105 
106 /*******************************************************************************
107  * End of File
108  ******************************************************************************/
109 
110 } // namespace librepcb
111 
112 #endif
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
QtCompat::Hash qHash(const Vertex &key, QtCompat::Hash seed=0) noexcept
Definition: vertex.h:101
The Vertex class.
Definition: vertex.h:44
QDataStream & operator<<(QDataStream &stream, const AttributeKey &obj)
Definition: attributekey.h:109
Vertex(const Vertex &other) noexcept
Definition: vertex.h:48
Definition: occmodel.cpp:77
Angle mAngle
Definition: vertex.h:91
Vertex() noexcept
Definition: vertex.h:47
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
Vertex(const Point &pos, const Angle &angle=Angle::deg0()) noexcept
Definition: vertex.h:50
Vertex & operator=(const Vertex &rhs) noexcept
Definition: vertex.cpp:56
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:79
static Angle deg0() noexcept
0 degrees
Definition: angle.h:351
const Angle & getAngle() const noexcept
Definition: vertex.h:57
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: vertex.cpp:47
bool operator==(const Vertex &rhs) const noexcept
Definition: vertex.cpp:62
void setAngle(const Angle &angle) noexcept
Definition: vertex.h:61
~Vertex() noexcept
Definition: vertex.h:53
uint Hash
Return type of Qt&#39;s qHash() function.
Definition: qtcompat.h:58
Point mPos
Definition: vertex.h:90
bool operator<(const Vertex &rhs) const noexcept
The "<" operator to compare two librepcb::Vertex objects.
Definition: vertex.cpp:66
const Point & getPos() const noexcept
Definition: vertex.h:56
The SExpression class.
Definition: sexpression.h:69
bool operator!=(const Vertex &rhs) const noexcept
Definition: vertex.h:75
void setPos(const Point &pos) noexcept
Definition: vertex.h:60