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 <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 93 of file SplineAssistant.cc.

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

◆ D()

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

Definition at line 105 of file SplineAssistant.cc.

106{
107 const qreal
108 tp = 1 - t,
109 tp2 = tp * tp,
110 t2 = t * t,
111 a = tp2 * tp,
112 b = 3 * tp2 * t,
113 c = 3 * tp * t2,
114 d = t * t2,
115 x_dist = a*P0.x() + b*P1.x() + c*P2.x() + d*P3.x() - p.x(),
116 y_dist = a*P0.y() + b*P1.y() + c*P2.y() + d*P3.y() - p.y();
117
118 return x_dist * x_dist + y_dist * y_dist;
119}
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 122 of file SplineAssistant.cc.

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