Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgMeshPatch.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Sharaf Zaman <sharafzaz121@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef SVGMESHPATCH_H
7#define SVGMESHPATCH_H
8
9#include <array>
10
11#include <QColor>
12#include <QPointF>
13#include <QVector>
14#include <QMap>
15#include <QPainterPath>
16
17#include <KoPathShape.h>
18
20 QColor color;
21 QPointF point;
22
24 {}
25
26 SvgMeshStop(QColor color, QPointF point)
28 {}
29
30 bool isValid() const { return color.isValid(); }
31};
32
33using SvgMeshPath = std::array<QPointF, 4>;
34
35class KRITAFLAKE_EXPORT SvgMeshPatch
36{
37public:
39 enum Type {
40 Top = 0,
45 };
46
47 SvgMeshPatch(QPointF startingPoint);
48 SvgMeshPatch(const SvgMeshPatch& other);
49
50 // NOTE: NO path is created here
51 // sets a new starting point for the patch
52 void moveTo(const QPointF& p);
54 void lineTo(const QPointF& p);
56 void curveTo(const QPointF& c1, const QPointF& c2, const QPointF& p);
57
59 SvgMeshStop getStop(Type type) const;
60
62 inline QPointF getMidpointParametric(Type type) const {
63 return (m_parametricCoords[type] + m_parametricCoords[(type + 1) % Size]) * 0.5;
64 }
65
67 QPointF segmentPointAt(Type type, qreal t) const;
68
70 QPair<std::array<QPointF, 4>, std::array<QPointF, 4>> segmentSplitAt(Type type, qreal t) const;
71
73 std::array<QPointF, 4> getSegment(Type type) const;
74
76 QPainterPath getPath() const;
77
79 QSizeF size() const;
80
81 QRectF boundingRect() const;
82
84 std::array<QPointF, 4> getMidCurve(bool isVertical) const;
85
86 void subdivideHorizontally(QVector<SvgMeshPatch*>& subdivided,
87 const QVector<QColor>& colors) const;
88
89 void subdivideVertically(QVector<SvgMeshPatch*>& subdivided,
90 const QVector<QColor>& colors) const;
91
92 void subdivide(QVector<SvgMeshPatch*>& subdivided,
93 const QVector<QColor>& colors) const;
94
95 bool isDivisibleVertically() const;
96 bool isDivisibleHorizontally() const;
97
98 int countPoints() const;
99
100 /* Parses raw pathstr and adds path to the shape, if the path isn't
101 * complete, it will have to be computed and given with pathIncomplete = true
102 * (Ideal case for std::optional)
103 */
104 void addStop(const QString& pathStr, QColor color, Type edge, bool pathIncomplete = false, QPointF lastPoint = QPointF());
105
107 void addStop(const std::array<QPointF, 4>& pathPoints, QColor color, Type edge);
108
110 void addStopLinear(const std::array<QPointF, 2>& pathPoints, QColor color, Type edge);
111
112 void modifyPath(SvgMeshPatch::Type type, std::array<QPointF, 4> newPath);
113 void modifyCorner(SvgMeshPatch::Type type, const QPointF &delta);
114
115 void setStopColor(SvgMeshPatch::Type type, const QColor &color);
116
117 void setTransform(const QTransform& matrix);
118
119private:
120 /* Parses path and adds it to m_path and returns the last point of the curve/line
121 * see also: SvgMeshPatch::addStop
122 */
123 QPointF parseMeshPath(const QString& path, bool pathIncomplete = false, const QPointF lastPoint = QPointF());
124 const char* getCoord(const char* ptr, qreal& number);
125
126private:
128 int counter {0};
129
132
133 std::array<SvgMeshStop, Size> m_nodes;
134 std::array<std::array<QPointF, 4>, 4> controlPoints;
136 std::array<QPointF, 4> m_parametricCoords;
137};
138
139#endif // SVGMESHPATCH_H
const Params2D p
std::array< QPointF, 4 > SvgMeshPath
Type
Position of stop in the patch.
QPointF getMidpointParametric(Type type) const
returns the midPoint in parametric space
QPointF m_startingPoint
This is the starting point for each path.
std::array< SvgMeshStop, Size > m_nodes
std::array< std::array< QPointF, 4 >, 4 > controlPoints
std::array< QPointF, 4 > m_parametricCoords
Coordinates in UV space.
bool isValid() const
SvgMeshStop(QColor color, QPointF point)
QPointF point