-static int approximate2(struct cspline*s, struct qspline*q, double quality, double start, double end, int max, int depth)
-{
- int num=0;
- struct SPLINEPOINT qr1,qr2,cr1,cr2;
- double dist1,dist2;
- double qquality = quality*quality;
- int t;
- int recurse = 0;
- int probes = 15;
- struct qspline test;
- char left = 0;
- test.start = cspline_getpoint(s, start);
- test.control = cspline_getpoint(s, (start+end)/2);
- test.end = cspline_getpoint(s, end);
- fixcp(&test);
-
- if(start< 0.5) {
- test.control = cspline_getderivative(s, start);
- test.control.x *= (end-start)/2;
- test.control.y *= (end-start)/2;
- test.control.x += test.start.x;
- test.control.y += test.start.y;
- } else {
- test.control = cspline_getderivative(s, end);
- test.control.x *= -(end-start)/2;
- test.control.y *= -(end-start)/2;
- test.control.x += test.end.x;
- test.control.y += test.end.y;
- }
+ /* create simple approximation: a qspline which run's through the
+ qspline point at 0.5 */
+ test.start = cspline_getpoint(s, start);
+ test.control = cspline_getpoint(s, (start+end)/2);
+ test.end = cspline_getpoint(s, end);
+ /* fix the control point:
+ move it so that the new spline does runs through it */
+ test.control.x = -(test.end.x + test.start.x)/2 + 2*(test.control.x);
+ test.control.y = -(test.end.y + test.start.y)/2 + 2*(test.control.y);
+
+ /* depending on where we are in the spline, we either try to match
+ the left or right tangent */
+ if(start<0.5)
+ left=1;
+ /* get derivative */
+ pos = left?start:end;
+ qpos = pos*pos;
+ test.control.x = s->end.x*(3*qpos) + 3*s->control2.x*(2*pos-3*qpos) +
+ 3*s->control1.x*(1-4*pos+3*qpos) + s->start.x*(-3+6*pos-3*qpos);
+ test.control.y = s->end.y*(3*qpos) + 3*s->control2.y*(2*pos-3*qpos) +
+ 3*s->control1.y*(1-4*pos+3*qpos) + s->start.y*(-3+6*pos-3*qpos);
+ if(left) {
+ test.control.x *= (end-start)/2;
+ test.control.y *= (end-start)/2;
+ test.control.x += test.start.x;
+ test.control.y += test.start.y;
+ } else {
+ test.control.x *= -(end-start)/2;
+ test.control.y *= -(end-start)/2;
+ test.control.x += test.end.x;
+ test.control.y += test.end.y;
+ }