13#ifndef INKSCAPE_LPE_POWERSTROKE_INTERPOLATORS_H
14#define INKSCAPE_LPE_POWERSTROKE_INTERPOLATORS_H
25namespace Interpolate {
57 path.
start( points.at(0) );
58 for (
unsigned int i = 1 ; i < points.size(); ++i) {
76 unsigned int n_points = points.
size();
78 int max_segs = 8*n_points;
81 for (
unsigned i = 0; i < n_points; ++i) {
82 points_array[i] = points.at(i);
85 double tolerance_sq = 0;
88 tolerance_sq, max_segs);
94 for (
int c = 0;
c < n_segs;
c++) {
118 fit.
start(points.at(0));
119 for (
unsigned int i = 1; i < points.size(); ++i) {
120 Point p0 = points.at(i-1);
121 Point p1 = points.at(i);
149 fit.
start(points.at(0));
150 unsigned int num_points = points.size();
151 for (
unsigned int i = 1; i < num_points; ++i) {
152 Point p0 = points.at(i-1);
153 Point p1 = points.at(i);
157 }
else if (i == points.size() - 1) {
183 Coord scale_y = 100.;
187 for (
unsigned int i = 0; i <
len; ++i) {
188 controlpoints[i].
x = points[i][
X];
189 controlpoints[i].
y = points[i][
Y] / scale_y;
190 controlpoints[i].
ty =
'c';
192 controlpoints[0].
ty =
'{';
193 controlpoints[1].
ty =
'v';
194 controlpoints[
len-2].
ty =
'v';
195 controlpoints[
len-1].
ty =
'}';
199 fit *=
Scale(1,scale_y);
200 g_free(controlpoints);
216 unsigned int n_points = points.
size();
220 if (n_points < 3)
return fit;
227 for (std::size_t i = 0; i < n_points-2; ++i) {
228 Point p0 = points[i];
229 Point p1 = points[i+1];
230 Point p2 = points[i+2];
231 Point p3 = (i < n_points-3) ? points[i+3] : points[i+2];
265 Point tan1 = (p1 - p0) / dt0 - (p2 - p0) / (dt0 + dt1) + (p2 - p1) / dt1;
266 Point tan2 = (p2 - p1) / dt1 - (p3 - p1) / (dt1 + dt2) + (p3 - p2) / dt2;
278 Point b1 = p1 + tan1 / 3;
Path - a sequence of contiguous curves.
Bezier fitting algorithms.
CentripetalCatmullRomInterpolator(const CentripetalCatmullRomInterpolator &)=delete
CubicBezier calc_bezier(Point p0, Point p1, Point p2, Point p3) const
~CentripetalCatmullRomInterpolator() override=default
CentripetalCatmullRomInterpolator & operator=(const CentripetalCatmullRomInterpolator &)=delete
CentripetalCatmullRomInterpolator()=default
Path interpolateToPath(std::vector< Point > const &points) const override
CubicBezierFit & operator=(const CubicBezierFit &)=delete
CubicBezierFit(const CubicBezierFit &)=delete
~CubicBezierFit() override=default
Path interpolateToPath(std::vector< Point > const &points) const override
void setBeta(double beta)
CubicBezierJohan & operator=(const CubicBezierJohan &)=delete
CubicBezierJohan(double beta=0.2)
Path interpolateToPath(std::vector< Point > const &points) const override
CubicBezierJohan(const CubicBezierJohan &)=delete
~CubicBezierJohan() override=default
CubicBezierSmooth(double beta=0.2)
Path interpolateToPath(std::vector< Point > const &points) const override
void setBeta(double beta)
CubicBezierSmooth & operator=(const CubicBezierSmooth &)=delete
CubicBezierSmooth(const CubicBezierSmooth &)=delete
~CubicBezierSmooth() override=default
virtual ~Interpolator()=default
Interpolator(const Interpolator &)=delete
virtual Geom::Path interpolateToPath(std::vector< Point > const &points) const =0
Interpolator & operator=(const Interpolator &)=delete
static Interpolator * create(InterpolatorType type)
~Linear() override=default
Linear & operator=(const Linear &)=delete
Linear(const Linear &)=delete
Path interpolateToPath(std::vector< Point > const &points) const override
SpiroInterpolator & operator=(const SpiroInterpolator &)=delete
SpiroInterpolator(const SpiroInterpolator &)=delete
Path interpolateToPath(std::vector< Point > const &points) const override
~SpiroInterpolator() override=default
SpiroInterpolator()=default
Sequence of contiguous curves, aka spline.
void append(Curve *curve)
Add a new curve to the end of the path.
size_type size() const
Natural size of the path.
void appendNew(Args &&... args)
Append a new curve to the path.
void start(Point const &p)
Two-dimensional point that doubles as a vector.
BezierCurveN< 3 > CubicBezier
Cubic (order 3) Bezier curve.
double Coord
Floating point type used to store coordinates.
constexpr Coord EPSILON
Default "acceptably small" value.
@ INTERP_CUBICBEZIER_JOHAN
@ INTERP_CUBICBEZIER_SMOOTH
@ INTERP_CENTRIPETAL_CATMULLROM
Various utility functions.
Coord distanceSq(Point const &p, Rect const &rect)
int bezier_fit_cubic_r(Point bezier[], Point const data[], int len, double error, unsigned max_beziers)
Fit a multi-segment Bezier curve to a set of digitized points, with possible weedout of identical poi...
D2< Piecewise< SBasis > > tan2(SBasis const &angle, double tol=.01, unsigned order=3)
Geom::Path spiro_run(const spiro_cp *src, int src_len)
Conversion between SBasis and Bezier basis polynomials.
C implementation of third-order polynomial spirals.