Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qclipperutils.cpp
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qclipperutils_p.h"
6
#
include
<
clip2tri
.
h
>
7
8
QT_BEGIN_NAMESPACE
9
10
class
QClipperUtilsPrivate
11
{
12
public
:
13
c2t
::
clip2tri
m_clipper
;
14
Path
m_cachedPolygon
;
15
};
16
17
static
const
double
kClipperScaleFactor
= 281474976710656.0;
// 48 bits of precision
18
static
const
double
kClipperScaleFactorInv
= 1.0 /
kClipperScaleFactor
;
19
20
static
IntPoint
toIntPoint
(
const
QDoubleVector2D &p)
21
{
22
return
IntPoint(cInt(p.x() *
kClipperScaleFactor
), cInt(p.y() *
kClipperScaleFactor
));
23
}
24
25
static
QDoubleVector2D
toVector2D
(
const
IntPoint &p)
26
{
27
return
QDoubleVector2D(
double
(p.X) *
kClipperScaleFactorInv
,
double
(p.Y) *
kClipperScaleFactorInv
);
28
}
29
30
static
QList
<
QDoubleVector2D
>
pathToQList
(
const
Path &path)
31
{
32
QList<QDoubleVector2D> res;
33
res.reserve(
int
(path.size()));
34
for
(
const
IntPoint &ip: path)
35
res.append(toVector2D(ip));
36
return
res;
37
}
38
39
static
QList
<
QList
<
QDoubleVector2D
>>
pathsToQList
(
const
Paths &paths)
40
{
41
QList<QList<QDoubleVector2D> > res;
42
res.reserve(
int
(paths.size()));
43
for
(
const
Path &p: paths) {
44
res.append(pathToQList(p));
45
}
46
return
res;
47
}
48
49
static
Path
qListToPath
(
const
QList<QDoubleVector2D> &list)
50
{
51
Path res;
52
res.reserve(list.size());
53
for
(
const
QDoubleVector2D &p: list)
54
res.push_back(toIntPoint(p));
55
return
res;
56
}
57
58
QClipperUtils::QClipperUtils() : d_ptr(
new
QClipperUtilsPrivate)
59
{
60
}
61
62
QClipperUtils::QClipperUtils(
const
QClipperUtils &other) : d_ptr(
new
QClipperUtilsPrivate)
63
{
64
d_ptr->m_cachedPolygon = other.d_ptr->m_cachedPolygon;
65
}
66
67
QClipperUtils::~QClipperUtils()
68
{
69
delete
d_ptr;
70
}
71
72
double
QClipperUtils::clipperScaleFactor()
73
{
74
return
kClipperScaleFactor;
75
}
76
77
int
QClipperUtils::pointInPolygon(
const
QDoubleVector2D &point,
const
QList<QDoubleVector2D> &polygon)
78
{
79
if
(polygon.isEmpty())
80
qWarning(
"No vertices are specified for the polygon!"
);
81
return
c2t::clip2tri::pointInPolygon(toIntPoint(point), qListToPath(polygon));
82
}
83
84
void
QClipperUtils::clearClipper()
85
{
86
d_ptr->m_clipper.clearClipper();
87
}
88
89
void
QClipperUtils::addSubjectPath(
const
QList<QDoubleVector2D> &path,
bool
closed)
90
{
91
d_ptr->m_clipper.addSubjectPath(qListToPath(path), closed);
92
}
93
94
void
QClipperUtils::addClipPolygon(
const
QList<QDoubleVector2D> &path)
95
{
96
d_ptr->m_clipper.addClipPolygon(qListToPath(path));
97
}
98
99
QList<QList<QDoubleVector2D>> QClipperUtils::execute(QClipperUtils::Operation op,
100
QClipperUtils::PolyFillType subjFillType,
101
QClipperUtils::PolyFillType clipFillType)
102
{
103
auto
result = d_ptr->m_clipper.execute(
static_cast
<c2t::clip2tri::Operation>(op),
104
static_cast
<QtClipperLib::PolyFillType>(subjFillType),
105
static_cast
<QtClipperLib::PolyFillType>(clipFillType));
106
return
pathsToQList(result);
107
}
108
109
void
QClipperUtils::setPolygon(
const
QList<QDoubleVector2D> &polygon)
110
{
111
d_ptr->m_cachedPolygon = qListToPath(polygon);
112
}
113
114
int
QClipperUtils::pointInPolygon(
const
QDoubleVector2D &point)
const
115
{
116
if
(d_ptr->m_cachedPolygon.empty())
117
qWarning(
"No vertices are specified for the polygon!"
);
118
return
c2t::clip2tri::pointInPolygon(toIntPoint(point), d_ptr->m_cachedPolygon);
119
}
120
121
QT_END_NAMESPACE
QClipperUtilsPrivate
Definition
qclipperutils.cpp:11
QClipperUtilsPrivate::m_clipper
c2t::clip2tri m_clipper
Definition
qclipperutils.cpp:13
QClipperUtilsPrivate::m_cachedPolygon
Path m_cachedPolygon
Definition
qclipperutils.cpp:14
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
toIntPoint
static IntPoint toIntPoint(const QDoubleVector2D &p)
Definition
qclipperutils.cpp:20
kClipperScaleFactor
static const double kClipperScaleFactor
Definition
qclipperutils.cpp:17
toVector2D
static QDoubleVector2D toVector2D(const IntPoint &p)
Definition
qclipperutils.cpp:25
kClipperScaleFactorInv
static const double kClipperScaleFactorInv
Definition
qclipperutils.cpp:18
pathsToQList
static QList< QList< QDoubleVector2D > > pathsToQList(const Paths &paths)
Definition
qclipperutils.cpp:39
pathToQList
static QList< QDoubleVector2D > pathToQList(const Path &path)
Definition
qclipperutils.cpp:30
qListToPath
static Path qListToPath(const QList< QDoubleVector2D > &list)
Definition
qclipperutils.cpp:49
qtpositioning
src
positioning
qclipperutils.cpp
Generated on
for Qt by
1.18.0