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
95 const
Point& center =
Point(0, 0)) const noexcept;
99 const
Point& center =
Point(0, 0)) const noexcept;
111 bool clean() noexcept;
112 bool close() noexcept;
113 bool open() noexcept;
123 Path& operator=(const
Path& rhs) noexcept;
124 bool operator==(const
Path& rhs) const noexcept {
197 template <
typename Value,
typename Predicate>
198 static constexpr auto verify(Value&& val,
const Predicate& p) ->
199 typename std::decay<Value>::type {
201 ? std::forward<Value>(val)
203 Path::tr(
"Path doesn't contain vertices!")),
204 std::forward<Value>(val));
210 return p.getVertices().count() > 0;
238 template <
typename Value,
typename Predicate>
239 static constexpr auto verify(Value&& val,
const Predicate& p) ->
240 typename std::decay<Value>::type {
241 return p(val) ? std::forward<Value>(val)
244 Path::tr(
"Path is not fillable or contains arcs!")),
245 std::forward<Value>(val));
251 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:265
Path toOpenPath() const noexcept
Definition: path.cpp:143
QVector< Path > toOutlineStrokes(const PositiveLength &width) const noexcept
Definition: path.cpp:149
Path & mirror(Qt::Orientation orientation, const Point ¢er=Point(0, 0)) noexcept
Definition: path.cpp:239
Path flattenedArcs(const PositiveLength &maxTolerance) const noexcept
Definition: path.cpp:289
const QPainterPath & toQPainterPathPx() const noexcept
Definition: path.cpp:169
static Path octagon(const PositiveLength &width, const PositiveLength &height, const UnsignedLength &cornerRadius=UnsignedLength(0)) noexcept
Definition: path.cpp:492
const QVector< Vertex > & getVertices() const noexcept
Definition: path.h:78
Path & reverse() noexcept
Definition: path.cpp:253
QVector< Vertex > & getVertices() noexcept
Definition: path.h:74
bool operator<(const Path &rhs) const noexcept
The "<" operator to compare two librepcb::Path objects.
Definition: path.cpp:366
QVector< Vertex > mVertices
Definition: path.h:180
static Path rect(const Point &p1, const Point &p2) noexcept
Definition: path.cpp:452
Path translated(const Point &offset) const noexcept
Definition: path.cpp:211
Path & flattenArcs(const PositiveLength &maxTolerance) noexcept
Definition: path.cpp:269
Path mirrored(Qt::Orientation orientation, const Point ¢er=Point(0, 0)) const noexcept
Definition: path.cpp:248
static Path arcObround(const Point &p1, const Point &p2, const Angle &angle, const PositiveLength &width) noexcept
Definition: path.cpp:417
bool clean() noexcept
Definition: path.cpp:316
bool close() noexcept
Definition: path.cpp:329
Path & mapToGrid(const PositiveLength &gridInterval) noexcept
Definition: path.cpp:215
static Path centeredRect(const PositiveLength &width, const PositiveLength &height, const UnsignedLength &cornerRadius=UnsignedLength(0)) noexcept
Definition: path.cpp:462
Path cleaned() const noexcept
Definition: path.cpp:131
void insertVertex(int index, const Vertex &vertex) noexcept
Definition: path.cpp:306
static Path flatArc(const Point &p1, const Point &p2, const Angle &angle, const PositiveLength &maxTolerance) noexcept
Definition: path.cpp:543
Point calcNearestPointBetweenVertices(const Point &p) const noexcept
Definition: path.cpp:114
bool isZeroLength() const noexcept
Definition: path.cpp:73
Path mappedToGrid(const PositiveLength &gridInterval) const noexcept
Definition: path.cpp:223
Path() noexcept
Definition: path.h:63
static Path circle(const PositiveLength &diameter) noexcept
Definition: path.cpp:378
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:374
void invalidatePainterPath() const noexcept
Definition: path.h:175
qreal calcAreaOfStraightSegments() const noexcept
Definition: path.cpp:99
Path & rotate(const Angle &angle, const Point ¢er=Point(0, 0)) noexcept
Definition: path.cpp:227
QPainterPath mPainterPathPx
Definition: path.h:181
static Path obround(const PositiveLength &width, const PositiveLength &height) noexcept
Definition: path.cpp:382
void addVertex(const Vertex &vertex) noexcept
Definition: path.cpp:297
~Path() noexcept
Definition: path.h:68
Path rotated(const Angle &angle, const Point ¢er=Point(0, 0)) const noexcept
Definition: path.cpp:235
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: path.cpp:348
Path & translate(const Point &offset) noexcept
Definition: path.cpp:203
bool isCurved() const noexcept
Definition: path.cpp:63
UnsignedLength getTotalStraightLength() const noexcept
Definition: path.cpp:86
bool open() noexcept
Definition: path.cpp:339
bool operator!=(const Path &rhs) const noexcept
Definition: path.h:127
bool isClosed() const noexcept
Definition: path.cpp:55
Path toClosedPath() const noexcept
Definition: path.cpp:137
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:222
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:265
NonEmptyPath makeNonEmptyPath(const Point &pos) noexcept
Definition: path.h:229
QtCompat::Hash qHash(const StraightAreaPath &key, QtCompat::Hash seed=0) noexcept
Definition: path.h:267
bool operator()(const Path &p) const noexcept
Definition: path.h:209
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: path.h:198
bool operator()(const Path &p) const noexcept
Definition: path.h:250
static constexpr auto verify(Value &&val, const Predicate &p) -> typename std::decay< Value >::type
Definition: path.h:239