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 #include <memory>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 /*******************************************************************************
40  * Class ClipperHelpers
41  ******************************************************************************/
42 
46 class ClipperHelpers final {
47  Q_DECLARE_TR_FUNCTIONS(ClipperHelpers)
48 
49 public:
50  // Disable instantiation
51  ClipperHelpers() = delete;
52  ~ClipperHelpers() = delete;
53 
54  // General Methods
55  static void unite(ClipperLib::Paths& paths);
56  static void unite(ClipperLib::Paths& subject, const ClipperLib::Path& clip);
57  static void unite(ClipperLib::Paths& subject, const ClipperLib::Paths& clip);
58  static std::unique_ptr<ClipperLib::PolyTree> intersect(
59  const ClipperLib::Paths& subject, const ClipperLib::Paths& clip);
60  static void subtract(ClipperLib::Paths& subject,
61  const ClipperLib::Paths& clip);
62  static void offset(ClipperLib::Paths& paths, const Length& offset,
63  const PositiveLength& maxArcTolerance);
64  static ClipperLib::Paths flattenTree(const ClipperLib::PolyNode& node);
65 
66  // Type Conversions
67  static QVector<Path> convert(const ClipperLib::Paths& paths) noexcept;
68  static Path convert(const ClipperLib::Path& path) noexcept;
69  static Point convert(const ClipperLib::IntPoint& point) noexcept;
70  static ClipperLib::Paths convert(
71  const QVector<Path>& paths,
72  const PositiveLength& maxArcTolerance) noexcept;
73  static ClipperLib::Path convert(
74  const Path& path, const PositiveLength& maxArcTolerance) noexcept;
75  static ClipperLib::IntPoint convert(const Point& point) noexcept;
76 
77 private: // Internal Helper Methods
78  static ClipperLib::Path convertHolesToCutIns(const ClipperLib::Path& outline,
79  const ClipperLib::Paths& holes);
80  static ClipperLib::Paths prepareHoles(
81  const ClipperLib::Paths& holes) noexcept;
82  static ClipperLib::Path rotateCutInHole(
83  const ClipperLib::Path& hole) noexcept;
84  static int getHoleConnectionPointIndex(const ClipperLib::Path& hole) noexcept;
85  static void addCutInToPath(ClipperLib::Path& outline,
86  const ClipperLib::Path& hole);
87  static int insertConnectionPointToPath(ClipperLib::Path& path,
88  const ClipperLib::IntPoint& p);
89  static bool calcIntersectionPos(const ClipperLib::IntPoint& p1,
90  const ClipperLib::IntPoint& p2,
91  const ClipperLib::cInt& x,
92  ClipperLib::cInt& y) noexcept;
93 };
94 
95 /*******************************************************************************
96  * End of File
97  ******************************************************************************/
98 
99 } // namespace librepcb
100 
101 #endif // LIBREPCB_CLIPPERHELPERS_H
static std::unique_ptr< ClipperLib::PolyTree > intersect(const ClipperLib::Paths &subject, const ClipperLib::Paths &clip)
Definition: clipperhelpers.cpp:76
static void unite(ClipperLib::Paths &paths)
Definition: clipperhelpers.cpp:36
static ClipperLib::Paths prepareHoles(const ClipperLib::Paths &holes) noexcept
Definition: clipperhelpers.cpp:222
static void offset(ClipperLib::Paths &paths, const Length &offset, const PositiveLength &maxArcTolerance)
Definition: clipperhelpers.cpp:109
static void addCutInToPath(ClipperLib::Path &outline, const ClipperLib::Path &hole)
Definition: clipperhelpers.cpp:263
static void subtract(ClipperLib::Paths &subject, const ClipperLib::Paths &clip)
Definition: clipperhelpers.cpp:95
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
static ClipperLib::Paths flattenTree(const ClipperLib::PolyNode &node)
Definition: clipperhelpers.cpp:121
static QVector< Path > convert(const ClipperLib::Paths &paths) noexcept
Definition: clipperhelpers.cpp:145
static int getHoleConnectionPointIndex(const ClipperLib::Path &hole) noexcept
Definition: clipperhelpers.cpp:252
static ClipperLib::Path rotateCutInHole(const ClipperLib::Path &hole) noexcept
Definition: clipperhelpers.cpp:242
static int insertConnectionPointToPath(ClipperLib::Path &path, const ClipperLib::IntPoint &p)
Definition: clipperhelpers.cpp:269
static ClipperLib::Path convertHolesToCutIns(const ClipperLib::Path &outline, const ClipperLib::Paths &holes)
Definition: clipperhelpers.cpp:212
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:780
The ClipperHelpers class.
Definition: clipperhelpers.h:46
static bool calcIntersectionPos(const ClipperLib::IntPoint &p1, const ClipperLib::IntPoint &p2, const ClipperLib::cInt &x, ClipperLib::cInt &y) noexcept
Definition: clipperhelpers.cpp:296
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:82