#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.
|
| 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 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,
113 c = 3 * tp * 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}
References p.
◆ goldenSearch()
Definition at line 122 of file SplineAssistant.cc.
128{
133
134 const qreal ratio = 1 - 2/(1 + sqrt(5));
139
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
149 while ( qAbs(
p[2].xnorm -
p[1].xnorm) > tolerance && i < max_iter) {
150
151 if (
p[1].fval <
p[2].fval) {
154 p[1].
x =
p[0].x + (
p[2].x -
p[1].x);
156
158 p[1].fval =
D(
p[1].xnorm, *handles[0], *handles[2], *handles[3], *handles[1], pt);
159
160 } else {
163 p[2].
x =
p[1].x + (
p[3].x -
p[2].x);
165
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 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.