19 #ifndef __CANVAS_INTERPOLATED_CURVE_H__
20 #define __CANVAS_INTERPOLATED_CURVE_H__
58 if (points_per_segment < 2) {
64 if (coordinates.size() < 3) {
65 results = coordinates;
70 Points vertices = coordinates;
77 Duple p2 = vertices[1];
79 Duple pn1 = vertices[vertices.size() - 2];
84 vertices.insert(vertices.begin(), pn1);
86 vertices.push_back(p2);
92 double dx = vertices[1].
x - vertices[0].x;
93 double dy = vertices[1].y - vertices[0].y;
96 double x1 = vertices[0].x - dx;
97 double y1 = vertices[0].y - dy;
103 int n = vertices.size() - 1;
104 dx = vertices[n].x - vertices[n - 1].x;
105 dy = vertices[n].y - vertices[n - 1].y;
106 double xn = vertices[n].x + dx;
107 double yn = vertices[n].y + dy;
111 vertices.insert (vertices.begin(),
start);
114 vertices.push_back (end);
120 for (Points::size_type i = 0; i < vertices.size() - 3; i++) {
125 _interpolate (vertices, i, points_per_segment, curve_type, r);
131 if (results.size() > 0) {
137 results.insert (results.end(), r.begin(), r.end());
157 const double L01 = p[0] * (time[1] - t) / (time[1] - time[0]) + p[1] * (t - time[0]) / (time[1] - time[0]);
158 const double L12 = p[1] * (time[2] - t) / (time[2] - time[1]) + p[2] * (t - time[1]) / (time[2] - time[1]);
159 const double L23 = p[2] * (time[3] - t) / (time[3] - time[2]) + p[3] * (t - time[2]) / (time[3] - time[2]);
160 const double L012 = L01 * (time[2] - t) / (time[2] - time[0]) + L12 * (t - time[0]) / (time[2] - time[0]);
161 const double L123 = L12 * (time[3] - t) / (time[3] - time[1]) + L23 * (t - time[1]) / (time[3] - time[1]);
162 const double C12 = L012 * (time[2] - t) / (time[2] - time[1]) + L123 * (t - time[1]) / (time[2] - time[1]);
191 for (
int i = 0; i < 4; i++) {
192 x[i] = points[index + i].x;
193 y[i] = points[index + i].y;
200 if (curve_type != CatmullRomUniform) {
202 for (
int i = 1; i < 4; i++) {
203 double dx = x[i] - x[i - 1];
204 double dy = y[i] - y[i - 1];
205 if (curve_type == CatmullRomCentripetal) {
206 total += pow (dx * dx + dy * dy, .25);
208 total += pow (dx * dx + dy * dy, .5);
216 int segments = points_per_segment - 1;
217 results.push_back (points[index + 1]);
219 for (
int i = 1; i < segments; i++) {
220 double xi = __interpolate (x, time, tstart + (i * (tend - tstart)) / segments);
221 double yi = __interpolate (y, time, tstart + (i * (tend - tstart)) / segments);
222 results.push_back (
Duple (xi, yi));
225 results.push_back (points[index + 2]);
static void _interpolate(const Points &points, Points::size_type index, int points_per_segment, SplineType curve_type, Points &results)
static void interpolate(const Points &coordinates, uint32_t points_per_segment, SplineType curve_type, bool closed, Points &results)
static double __interpolate(double p[4], double time[4], double t)
PBD::PropertyDescriptor< timepos_t > start
std::vector< Duple > Points