LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
clipperhelpers.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_CLIPPERHELPERS_H
21 #define LIBREPCB_CLIPPERHELPERS_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../geometry/path.h"
27 
28 #include <clipper/clipper.hpp>
29 
30 #include <QtCore>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 /*******************************************************************************
38  * Class ClipperHelpers
39  ******************************************************************************/
40 
44 class ClipperHelpers final {
45  Q_DECLARE_TR_FUNCTIONS(ClipperHelpers)
46 
47 public:
48  // Disable instantiation
49  ClipperHelpers() = delete;
50  ~ClipperHelpers() = delete;
51 
52  // General Methods
53  static void offset(ClipperLib::Paths& paths, const Length& offset,
54  const PositiveLength& maxArcTolerance);
55  static ClipperLib::Paths flattenTree(const ClipperLib::PolyNode& node);
56 
57  // Type Conversions
58  static QVector<Path> convert(const ClipperLib::Paths& paths) noexcept;
59  static Path convert(const ClipperLib::Path& path) noexcept;
60  static Point convert(const ClipperLib::IntPoint& point) noexcept;
61  static ClipperLib::Paths convert(
62  const QVector<Path>& paths,
63  const PositiveLength& maxArcTolerance) noexcept;
64  static ClipperLib::Path convert(
65  const Path& path, const PositiveLength& maxArcTolerance) noexcept;
66  static ClipperLib::IntPoint convert(const Point& point) noexcept;
67 
68 private: // Internal Helper Methods
69  static ClipperLib::Path convertHolesToCutIns(const ClipperLib::Path& outline,
70  const ClipperLib::Paths& holes);
71  static ClipperLib::Paths prepareHoles(
72  const ClipperLib::Paths& holes) noexcept;
73  static ClipperLib::Path rotateCutInHole(
74  const ClipperLib::Path& hole) noexcept;
75  static int getHoleConnectionPointIndex(const ClipperLib::Path& hole) noexcept;
76  static void addCutInToPath(ClipperLib::Path& outline,
77  const ClipperLib::Path& hole);
78  static int insertConnectionPointToPath(ClipperLib::Path& path,
79  const ClipperLib::IntPoint& p);
80  static bool calcIntersectionPos(const ClipperLib::IntPoint& p1,
81  const ClipperLib::IntPoint& p2,
82  const ClipperLib::cInt& x,
83  ClipperLib::cInt& y) noexcept;
84 };
85 
86 /*******************************************************************************
87  * End of File
88  ******************************************************************************/
89 
90 } // namespace librepcb
91 
92 #endif // LIBREPCB_CLIPPERHELPERS_H
static ClipperLib::Paths prepareHoles(const ClipperLib::Paths &holes) noexcept
Definition: clipperhelpers.cpp:149
static void offset(ClipperLib::Paths &paths, const Length &offset, const PositiveLength &maxArcTolerance)
Definition: clipperhelpers.cpp:36
static void addCutInToPath(ClipperLib::Path &outline, const ClipperLib::Path &hole)
Definition: clipperhelpers.cpp:190
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
static ClipperLib::Paths flattenTree(const ClipperLib::PolyNode &node)
Definition: clipperhelpers.cpp:48
static QVector< Path > convert(const ClipperLib::Paths &paths) noexcept
Definition: clipperhelpers.cpp:72
static int getHoleConnectionPointIndex(const ClipperLib::Path &hole) noexcept
Definition: clipperhelpers.cpp:179
static ClipperLib::Path rotateCutInHole(const ClipperLib::Path &hole) noexcept
Definition: clipperhelpers.cpp:169
static int insertConnectionPointToPath(ClipperLib::Path &path, const ClipperLib::IntPoint &p)
Definition: clipperhelpers.cpp:196
static ClipperLib::Path convertHolesToCutIns(const ClipperLib::Path &outline, const ClipperLib::Paths &holes)
Definition: clipperhelpers.cpp:139
The Path class represents a list of vertices connected by straight lines or circular arc segments...
Definition: path.h:53
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:783
The ClipperHelpers class.
Definition: clipperhelpers.h:44
static bool calcIntersectionPos(const ClipperLib::IntPoint &p1, const ClipperLib::IntPoint &p2, const ClipperLib::cInt &x, ClipperLib::cInt &y) noexcept
Definition: clipperhelpers.cpp:223
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:85