20#ifndef LIBREPCB_CORE_PATH_H
21#define LIBREPCB_CORE_PATH_H
26#include "../exceptions.h"
27#include "../qtcompat.h"
30#include <type_safe/constrained_type.hpp>
59 Q_DECLARE_TR_FUNCTIONS(
Path)
65 explicit Path(
const QVector<Vertex>& vertices) noexcept
94 const
Point& center =
Point(0, 0)) const noexcept;
98 const
Point& center =
Point(0, 0)) const noexcept;
110 bool clean() noexcept;
111 bool close() noexcept;
112 bool open() noexcept;
122 Path& operator=(const
Path& rhs) noexcept;
123 bool operator==(const
Path& rhs) const noexcept {
196 template <
typename Value,
typename Predicate>
197 static constexpr auto verify(Value&& val,
const Predicate& p) ->
198 typename std::decay<Value>::type {
200 ? std::forward<Value>(val)
202 Path::tr(
"Path doesn't contain vertices!")),
203 std::forward<Value>(val));
209 return p.getVertices().count() > 0;
237 template <
typename Value,
typename Predicate>
238 static constexpr auto verify(Value&& val,
const Predicate& p) ->
239 typename std::decay<Value>::type {
240 return p(val) ? std::forward<Value>(val)
243 Path::tr(
"Path is not fillable or contains arcs!")),
244 std::forward<Value>(val));
250 return (p.getVertices().count() >= 4) && p.isClosed() && (!p.isCurved());
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
static Angle deg0() noexcept
0 degrees
Definition: angle.h:351
The Path class represents a list of vertices connected by straight lines or circular arc segments.
Definition: path.h:58
Path reversed() const noexcept
Definition: path.cpp:252
Path toOpenPath() const noexcept
Definition: path.cpp:130
QVector< Path > toOutlineStrokes(const PositiveLength &width) const noexcept
Definition: path.cpp:136
Path & mirror(Qt::Orientation orientation, const Point ¢er=Point(0, 0)) noexcept
Definition: path.cpp:226
Path flattenedArcs(const PositiveLength &maxTolerance) const noexcept
Definition: path.cpp:276
const QPainterPath & toQPainterPathPx() const noexcept
Definition: path.cpp:156
static Path octagon(const PositiveLength &width, const PositiveLength &height, const UnsignedLength &cornerRadius=UnsignedLength(0)) noexcept
Definition: path.cpp:485
const QVector< Vertex > & getVertices() const noexcept
Definition: path.h:77
Path & reverse() noexcept
Definition: path.cpp:240
QVector< Vertex > & getVertices() noexcept
Definition: path.h:73
bool operator<(const Path &rhs) const noexcept
The "<" operator to compare two librepcb::Path objects.
Definition: path.cpp:353
QVector< Vertex > mVertices
Definition: path.h:179
static Path rect(const Point &p1, const Point &p2) noexcept
Definition: path.cpp:445
Path translated(const Point &offset) const noexcept
Definition: path.cpp:198
Path & flattenArcs(const PositiveLength &maxTolerance) noexcept
Definition: path.cpp:256
Path mirrored(Qt::Orientation orientation, const Point ¢er=Point(0, 0)) const noexcept
Definition: path.cpp:235
static Path arcObround(const Point &p1, const Point &p2, const Angle &angle, const PositiveLength &width) noexcept
Definition: path.cpp:410
bool clean() noexcept
Definition: path.cpp:303
bool close() noexcept
Definition: path.cpp:316
Path & mapToGrid(const PositiveLength &gridInterval) noexcept
Definition: path.cpp:202
static Path centeredRect(const PositiveLength &width, const PositiveLength &height, const UnsignedLength &cornerRadius=UnsignedLength(0)) noexcept
Definition: path.cpp:455
Path cleaned() const noexcept
Definition: path.cpp:118
void insertVertex(int index, const Vertex &vertex) noexcept
Definition: path.cpp:293
static Path flatArc(const Point &p1, const Point &p2, const Angle &angle, const PositiveLength &maxTolerance) noexcept
Definition: path.cpp:536
Point calcNearestPointBetweenVertices(const Point &p) const noexcept
Definition: path.cpp:101
Path mappedToGrid(const PositiveLength &gridInterval) const noexcept
Definition: path.cpp:210
Path() noexcept
Definition: path.h:63
static Path circle(const PositiveLength &diameter) noexcept
Definition: path.cpp:371
Path(const QVector< Vertex > &vertices) noexcept
Definition: path.h:65
static Path line(const Point &p1, const Point &p2, const Angle &angle=Angle::deg0()) noexcept
Definition: path.cpp:367
void invalidatePainterPath() const noexcept
Definition: path.h:174
qreal calcAreaOfStraightSegments() const noexcept
Definition: path.cpp:86
Path & rotate(const Angle &angle, const Point ¢er=Point(0, 0)) noexcept
Definition: path.cpp:214
QPainterPath mPainterPathPx
Definition: path.h:180
static Path obround(const PositiveLength &width, const PositiveLength &height) noexcept
Definition: path.cpp:375
void addVertex(const Vertex &vertex) noexcept
Definition: path.cpp:284
~Path() noexcept
Definition: path.h:68
Path rotated(const Angle &angle, const Point ¢er=Point(0, 0)) const noexcept
Definition: path.cpp:222
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: path.cpp:335
Path & translate(const Point &offset) noexcept
Definition: path.cpp:190
bool isCurved() const noexcept
Definition: path.cpp:63
UnsignedLength getTotalStraightLength() const noexcept
Definition: path.cpp:73
bool open() noexcept
Definition: path.cpp:326
bool operator!=(const Path &rhs) const noexcept
Definition: path.h:126
bool isClosed() const noexcept
Definition: path.cpp:55
Path toClosedPath() const noexcept
Definition: path.cpp:124
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
uint Hash
Return type of Qt's qHash() function.
Definition: qtcompat.h:58
The RuntimeError class.
Definition: exceptions.h:218
The SExpression class.
Definition: sexpression.h:69
The Vertex class.
Definition: vertex.h:44
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
type_safe::constrained_type< Path, NonEmptyPathConstraint, NonEmptyPathVerifier > NonEmptyPath
Definition: path.h:221
QtCompat::Hash qHash(const AttributeKey &key, QtCompat::Hash seed=0) noexcept
Definition: attributekey.h:119
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
type_safe::constrained_type< Path, StraightAreaPathConstraint, StraightAreaPathVerifier > StraightAreaPath
Definition: path.h:264
NonEmptyPath makeNonEmptyPath(const Point &pos) noexcept
Definition: path.h:228
QtCompat::Hash qHash(const StraightAreaPath &key, QtCompat::Hash seed=0) noexcept
Definition: path.h:266
bool operator()(const Path &p) const noexcept
Definition: path.h:208
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: path.h:197
bool operator()(const Path &p) const noexcept
Definition: path.h:249
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: path.h:238