Krita Source Code Documentation
Loading...
Searching...
No Matches
SplineAssistant.cc File Reference
#include "SplineAssistant.h"
#include <klocalizedstring.h>
#include <QPainter>
#include <QPainterPath>
#include <QLinearGradient>
#include <QTransform>
#include <kis_canvas2.h>
#include <kis_coordinates_converter.h>
#include "kis_debug.h"
#include "KisBezierUtils.h"
#include <KoColorDisplayRendererInterface.h>
#include <math.h>
#include <limits>
#include <algorithm>

Go to the source code of this file.

Classes

struct  GoldenSearchParams
 
struct  GoldenSearchParams::GoldenSearchPoint
 
struct  SplineAssistant::Private
 

Functions

QPointF B (qreal t, const QPointF &P0, const QPointF &P1, const QPointF &P2, const QPointF &P3)
 
qreal D (qreal t, const QPointF &P0, const QPointF &P1, const QPointF &P2, const QPointF &P3, const QPointF &p)
 
qreal goldenSearch (const QPointF &pt, const QList< KisPaintingAssistantHandleSP > handles, qreal low, qreal high, qreal tolerance, uint max_iter)
 

Function Documentation

◆ B()

QPointF B ( qreal t,
const QPointF & P0,
const QPointF & P1,
const QPointF & P2,
const QPointF & P3 )
inline

Definition at line 94 of file SplineAssistant.cc.

95{
96 const qreal tp = 1 - t;
97 const qreal tp2 = tp * tp;
98 const qreal t2 = t * t;
99
100 return ( tp2 * tp) * P0 +
101 (3 * tp2 * t ) * P1 +
102 (3 * tp * t2) * P2 +
103 ( t * t2) * P3;
104}

◆ D()

qreal D ( qreal t,
const QPointF & P0,
const QPointF & P1,
const QPointF & P2,
const QPointF & P3,
const QPointF & p )
inline

Definition at line 106 of file SplineAssistant.cc.

107{
108 const qreal
109 tp = 1 - t,
110 tp2 = tp * tp,
111 t2 = t * t,
112 a = tp2 * tp,
113 b = 3 * tp2 * t,
114 c = 3 * tp * t2,
115 d = t * t2,
116 x_dist = a*P0.x() + b*P1.x() + c*P2.x() + d*P3.x() - p.x(),
117 y_dist = a*P0.y() + b*P1.y() + c*P2.y() + d*P3.y() - p.y();
118
119 return x_dist * x_dist + y_dist * y_dist;
120}
const Params2D p

References p.

◆ goldenSearch()

qreal goldenSearch ( const QPointF & pt,
const QList< KisPaintingAssistantHandleSP > handles,
qreal low,
qreal high,
qreal tolerance,
uint max_iter )
inline

Definition at line 123 of file SplineAssistant.cc.

129{
130 GoldenSearchParams ovalues = GoldenSearchParams(low,high);
132 qreal u = ovalues.ubound;
133 qreal l = ovalues.lbound;
134
135 const qreal ratio = 1 - 2/(1 + sqrt(5));
136 p[0].x = 0;
137 p[1].x = ratio;
138 p[2].x = 1 - p[1].x;
139 p[3].x = 1;
140
141 p[1].inv_norm(l,u);
142 p[2].inv_norm(l,u);
143
144 p[1].fval = D(p[1].xnorm, *handles[0], *handles[2], *handles[3], *handles[1], pt);
145 p[2].fval = D(p[2].xnorm, *handles[0], *handles[2], *handles[3], *handles[1], pt);
146
148
149 uint i = 0; // used to force early exit
150 while ( qAbs(p[2].xnorm - p[1].xnorm) > tolerance && i < max_iter) {
151
152 if (p[1].fval < p[2].fval) {
153 xtemp = p[1];
154 p[3] = p[2];
155 p[1].x = p[0].x + (p[2].x - p[1].x);
156 p[2] = xtemp;
157
158 p[1].inv_norm(l,u);
159 p[1].fval = D(p[1].xnorm, *handles[0], *handles[2], *handles[3], *handles[1], pt);
160
161 } else {
162 xtemp = p[2];
163 p[0] = p[1];
164 p[2].x = p[1].x + (p[3].x - p[2].x);
165 p[1] = xtemp;
166
167 p[2].inv_norm(l,u);
168 p[2].fval = D(p[2].xnorm, *handles[0], *handles[2], *handles[3], *handles[1], pt);
169
170 }
171 i++;
172 }
173 return (p[2].xnorm + p[1].xnorm) / 2;
174}
qreal u
unsigned int uint
qreal D(qreal t, const QPointF &P0, const QPointF &P1, const QPointF &P2, const QPointF &P3, const QPointF &p)
QVector< GoldenSearchPoint > samples

References D(), GoldenSearchParams::GoldenSearchPoint::inv_norm(), GoldenSearchParams::lbound, p, GoldenSearchParams::samples, u, GoldenSearchParams::ubound, and GoldenSearchParams::GoldenSearchPoint::x.