The part that seems to give problems is when we define D2<> segment with linear interpolation:

for(unsigned ix = 0; ix < K.segs.size(); ix++) {
            D2<SBasis> Kxy;
            Kxy[1] = Linear(450) - K.segs[ix]*400;
            Kxy[0] = Linear(300*K.cuts[ix] + 150, 300*K.cuts[ix+1] + 150);
            cairo_d2_sb(cr, Kxy);
    cairo_set_source_rgba (cr, 1., 0., 0., 0.8);
            cairo_stroke(cr);
        }

I did something similar to this in other toy example and got the same instability. I believe that the instability comes from using K.segs[] to define new SBasis (K is a Piecewise<SBasis> that contains curvature of the curve). If I create D2<SBasis> by purely linear segments, my output is very stable:

dd = 0.1;
for (double tt = 0; tt < 1.0; tt += dd)
{
D2<SBasis> Kxy;
            Kxy[1] = SBasis(450 - K(tt)*400, 450 - K(tt+dd)*400);
            Kxy[0] = SBasis(150 + 300*(tt), 150 + 300*(tt+dd));
            cairo_d2_sb(cr, Kxy);
cairo_set_source_rgba (cr, 1., 0., 0., 0.8);
            cairo_stroke(cr);
}

Would appreciate some helps to fix the issue here.

Regards,
_______________________
Papoj "Hua" Thamjaroenporn
pt2277@...3110...