1// Copyright (C) 2016 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
4#ifndef QTRIANGULATOR_P_H
5#define QTRIANGULATOR_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/private/qtguiglobal_p.h>
19#include <QtGui/private/qvectorpath_p.h>
20#include <QtCore/qlist.h>
21
22QT_BEGIN_NAMESPACE
23
24class QVertexIndexVector
25{
26public:
27 enum Type {
28 UnsignedInt,
29 UnsignedShort
30 };
31
32 inline Type type() const { return t; }
33
34 inline void setDataUint(const QList<quint32> &data)
35 {
36 t = UnsignedInt;
37 indices32 = data;
38 }
39
40 inline void setDataUshort(const QList<quint16> &data)
41 {
42 t = UnsignedShort;
43 indices16 = data;
44 }
45
46 inline const void* data() const
47 {
48 if (t == UnsignedInt)
49 return indices32.data();
50 return indices16.data();
51 }
52
53 inline int size() const
54 {
55 if (t == UnsignedInt)
56 return indices32.size();
57 return indices16.size();
58 }
59
60private:
61
62 Type t;
63 QList<quint32> indices32;
64 QList<quint16> indices16;
65};
66
67struct QTriangleSet
68{
69 // The vertices of a triangle are given by: (x[i[n]], y[i[n]]), (x[j[n]], y[j[n]]), (x[k[n]], y[k[n]]), n = 0, 1, ...
70 QList<qreal> vertices; // [x[0], y[0], x[1], y[1], x[2], ...]
71 QVertexIndexVector indices; // [i[0], j[0], k[0], i[1], j[1], k[1], i[2], ...]
72};
73
74struct QPolylineSet
75{
76 QList<qreal> vertices; // [x[0], y[0], x[1], y[1], x[2], ...]
77 QVertexIndexVector indices; // End of polyline is marked with -1.
78};
79
80// The vertex coordinates of the returned triangle set will be rounded to a grid with a mesh size
81// of 1/32. The polygon is first transformed, then scaled by 32, the coordinates are rounded to
82// integers, the polygon is triangulated, and then scaled back by 1/32.
83// 'hint' should be a combination of QVectorPath::Hints.
84// 'lod' is the level of detail. Default is 1. Curves are split into more lines when 'lod' is higher.
85QTriangleSet Q_GUI_EXPORT qTriangulate(const qreal *polygon, int count,
86 uint hint = QVectorPath::PolygonHint | QVectorPath::OddEvenFill,
87 const QTransform &matrix = QTransform(),
88 bool allowUintIndices = true);
89QTriangleSet Q_GUI_EXPORT qTriangulate(const QVectorPath &path, const QTransform &matrix = QTransform(),
90 qreal lod = 1, bool allowUintIndices = true);
91QTriangleSet Q_GUI_EXPORT qTriangulate(const QPainterPath &path, const QTransform &matrix = QTransform(),
92 qreal lod = 1, bool allowUintIndices = true);
93QPolylineSet qPolyline(const QVectorPath &path, const QTransform &matrix = QTransform(),
94 qreal lod = 1, bool allowUintIndices = true);
95QPolylineSet Q_GUI_EXPORT qPolyline(const QPainterPath &path, const QTransform &matrix = QTransform(),
96 qreal lod = 1, bool allowUintIndices = true);
97
98QT_END_NAMESPACE
99
100#endif
101

source code of qtbase/src/gui/painting/qtriangulator_p.h