Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgMeshPatch.cpp File Reference
#include "SvgMeshPatch.h"
#include <array>
#include <math.h>
#include <QDebug>
#include <kis_global.h>

Go to the source code of this file.

Functions

static qreal controlrectLen (const SvgMeshPath &path)
 
void deCasteljau (const std::array< QPointF, 4 > &points, qreal t, QPointF *p1, QPointF *p2, QPointF *p3, QPointF *p4, QPointF *p5)
 
QPointF lerp (const QPointF &p1, const QPointF &p2, qreal t)
 
QPair< std::array< QPointF, 4 >, std::array< QPointF, 4 > > splitAt (const std::array< QPointF, 4 > &points, qreal t)
 

Function Documentation

◆ controlrectLen()

static qreal controlrectLen ( const SvgMeshPath & path)
static

Definition at line 418 of file SvgMeshPatch.cpp.

418 {
419 return QLineF(path[0], path[1]).length() +
420 QLineF(path[1], path[2]).length() +
421 QLineF(path[2], path[3]).length();
422}

◆ deCasteljau()

void deCasteljau ( const std::array< QPointF, 4 > & points,
qreal t,
QPointF * p1,
QPointF * p2,
QPointF * p3,
QPointF * p4,
QPointF * p5 )

Definition at line 20 of file SvgMeshPatch.cpp.

23{
24 QPointF q[4];
25
26 q[0] = points[0];
27 q[1] = points[1];
28 q[2] = points[2];
29 q[3] = points[3];
30
31 // points of the new segment after the split point
32 QPointF p[3];
33
34 // the De Casteljau algorithm
35 for (unsigned short j = 1; j <= 3; ++j) {
36 for (unsigned short i = 0; i <= 3 - j; ++i) {
37 q[i] = (1.0 - t) * q[i] + t * q[i + 1];
38 }
39 p[j - 1] = q[0];
40 }
41
42 if (p1)
43 *p1 = p[0];
44 if (p2)
45 *p2 = p[1];
46 if (p3)
47 *p3 = p[2];
48 if (p4)
49 *p4 = q[1];
50 if (p5)
51 *p5 = q[2];
52}
const Params2D p
QPointF p2
QPointF p3
QPointF p1

References p, p1, p2, and p3.

◆ lerp()

QPointF lerp ( const QPointF & p1,
const QPointF & p2,
qreal t )
inline

Definition at line 15 of file SvgMeshPatch.cpp.

16{
17 return (1 - t) * p1 + t * p2;
18}

References p1, and p2.

◆ splitAt()

QPair< std::array< QPointF, 4 >, std::array< QPointF, 4 > > splitAt ( const std::array< QPointF, 4 > & points,
qreal t )

Definition at line 54 of file SvgMeshPatch.cpp.

55{
56 QPointF newCP2, newCP1, splitP, splitCP1, splitCP2;
57 deCasteljau(points, t, &newCP2, &splitCP1, &splitP, &splitCP2, &newCP1);
58 return {{points[0], newCP2, splitCP1, splitP},
59 {splitP, splitCP2, newCP1, points[3]}};
60}
void deCasteljau(const std::array< QPointF, 4 > &points, qreal t, QPointF *p1, QPointF *p2, QPointF *p3, QPointF *p4, QPointF *p5)

References deCasteljau().