7#ifndef KISBEZIERUTILS_H
8#define KISBEZIERUTILS_H
10#include "kritaglobal_export.h"
28 const qreal t_2 =
pow2(t);
29 const qreal t_inv = 1.0 - t;
30 const qreal t_inv_2 =
pow2(t_inv);
33 3 * t_inv_2 * (
p1 -
p0) +
34 6 * t_inv * t * (
p2 -
p1) +
44 const qreal t_inv = 1.0 - t;
47 6 * t_inv * (
p2 - 2 *
p1 +
p0) +
48 6 * t * (
p3 - 2 *
p2 +
p1);
74 for (
unsigned short j = 1; j <= 3; ++j) {
75 for (
unsigned short i = 0; i <= 3 - j; ++i) {
76 q[i] = (1.0 - t) * q[i] + t * q[i + 1];
95 const qreal t_2 =
pow2(t);
96 const qreal t_3 = t_2 * t;
97 const qreal t_inv = 1.0 - t;
98 const qreal t_inv_2 =
pow2(t_inv);
99 const qreal t_inv_3 = t_inv_2 * t_inv;
103 3 * t_inv_2 * t *
p1 +
104 3 * t_inv * t_2 *
p2 +
118 if (points.size() == 2) {
119 result =
lerp(points.first(), points.last(), t);
120 }
else if (points.size() == 3) {
121 result =
bezierCurve(points[0], points[1], points[1], points[2], t);
122 }
else if (points.size() == 4) {
123 result =
bezierCurve(points[0], points[1], points[2], points[3], t);
132 const QPointF &
p1,
const QPointF &d1,
133 const qreal
eps = 1e-4)
135 const QPointF diff =
p1 -
p0;
138 const qreal normCoeff = 1.0 / 3.0 / dist;
140 const qreal offset1 =
142 if (offset1 >
eps)
return false;
144 const qreal offset2 =
146 if (offset2 >
eps)
return false;
152 const QPointF &
p2,
const QPointF &
p3,
153 const qreal
eps = 1e-4)
163 const qreal
eps = 1e-4;
186qreal
nearestPoint(
const QList<QPointF> controlPoints,
const QPointF &point, qreal *resultDistance = 0, QPointF *resultPoint = 0);
202 const QPointF &globalPoint);
214QPointF
calculateGlobalPos(
const std::array<QPointF, 12> &points,
const QPointF &localPoint);
227 const QPointF &globalPoint);
257std::pair<QPointF, QPointF>
offsetSegment(qreal t,
const QPointF &offset);
332 const QPointF &nearestAnchor,
QPointF lerp(const QPointF &p1, const QPointF &p2, qreal t)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Point lerp(const Point &pt1, const Point &pt2, qreal t)
PointTypeTraits< T >::value_type crossProduct(const T &a, const T &b)
bool fuzzyPointCompare(const QPointF &p1, const QPointF &p2)
qreal curveParamByProportion(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal proportion, const qreal error)
QPointF calculateLocalPos(const std::array< QPointF, 12 > &points, const QPointF &globalPoint)
calculates local (u,v) coordinates of the patch corresponding to globalPoint
void deCasteljau(const QPointF &q0, const QPointF &q1, const QPointF &q2, const QPointF &q3, qreal t, QPointF *p0, QPointF *p1, QPointF *p2, QPointF *p3, QPointF *p4)
QPointF calculateLocalPosSVG2(const std::array< QPointF, 12 > &points, const QPointF &globalPoint)
calculates local (u,v) coordinates of the patch corresponding to globalPoint
QVector< qreal > intersectWithLine(const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const QLineF &line, qreal eps)
qreal curveProportionByParam(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t, const qreal error)
QVector< qreal > linearizeCurve(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, const qreal eps)
qreal curveLengthAtPoint(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t, const qreal error)
QPointF calculateGlobalPos(const std::array< QPointF, 12 > &points, const QPointF &localPoint)
calculates global coordinate corresponding to the patch coordinate (u, v)
bool isLinearSegmentByDerivatives(const QPointF &p0, const QPointF &d0, const QPointF &p1, const QPointF &d1, const qreal eps=1e-4)
int controlPolygonZeros(const QList< QPointF > &controlPoints)
QPointF calculateGlobalPosSVG2(const std::array< QPointF, 12 > &points, const QPointF &localPoint)
calculates global coordinate corresponding to the patch coordinate (u, v)
QPointF bezierCurveDeriv(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t)
bool isLinearSegmentByControlPoints(const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const qreal eps=1e-4)
std::pair< QPointF, QPointF > offsetSegment(qreal t, const QPointF &offset)
moves point t of the curve by offset offset
QPointF bezierCurve(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t)
QPointF bezierCurveDeriv2(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, qreal t)
qreal nearestPoint(const QList< QPointF > controlPoints, const QPointF &point, qreal *resultDistance, QPointF *resultPoint)
std::pair< QPointF, QPointF > removeBezierNode(const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const QPointF &q1, const QPointF &q2, const QPointF &q3)
Adjusts position for the bezier control points after removing a node.
qreal curveLength(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3, const qreal error)
QVector< qreal > mergeLinearizationSteps(const QVector< qreal > &a, const QVector< qreal > &b)
boost::optional< qreal > intersectWithLineNearest(const QPointF &p0, const QPointF &p1, const QPointF &p2, const QPointF &p3, const QLineF &line, const QPointF &nearestAnchor, qreal eps)
QPointF interpolateQuadric(const QPointF &p0, const QPointF &p2, const QPointF &pt, qreal t)
Interpolates quadric curve passing through given points.
int bezierDegree(const QPointF p0, const QPointF p1, const QPointF p2, const QPointF p3)