#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.
|
| 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) |
| |
◆ 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,
114 c = 3 * tp * 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}
References p.
◆ goldenSearch()
Definition at line 123 of file SplineAssistant.cc.
129{
134
135 const qreal ratio = 1 - 2/(1 + sqrt(5));
140
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
150 while ( qAbs(
p[2].xnorm -
p[1].xnorm) > tolerance && i < max_iter) {
151
152 if (
p[1].fval <
p[2].fval) {
155 p[1].
x =
p[0].x + (
p[2].x -
p[1].x);
157
159 p[1].fval =
D(
p[1].xnorm, *handles[0], *handles[2], *handles[3], *handles[1], pt);
160
161 } else {
164 p[2].
x =
p[1].x + (
p[3].x -
p[2].x);
166
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 D(qreal t, const QPointF &P0, const QPointF &P1, const QPointF &P2, const QPointF &P3, const QPointF &p)
void inv_norm(qreal l, qreal u)
QVector< GoldenSearchPoint > samples
References D(), GoldenSearchParams::GoldenSearchPoint::inv_norm(), GoldenSearchParams::lbound, p, GoldenSearchParams::samples, u, GoldenSearchParams::ubound, and GoldenSearchParams::GoldenSearchPoint::x.