Logo Search packages:      
Sourcecode: inkscape version File versions

static void Geom::chord_length_parameterize ( Point const   d[],
double  u[],
unsigned const   len 
) [static]

Assign parameter values to digitized points using relative distances between points.

Precondition:
Parameter array u must have space for len items.

Todo:
It's been reported that u[len - 1] can differ from 1.0 on some systems (amd64), despite it having been calculated as x / x where x is isFinite and non-zero.

Definition at line 841 of file bezier-utils.cpp.

Referenced by bezier_fit_cubic_full().

{
    if(!( 2 <= len ))
        return;

    /* First let u[i] equal the distance travelled along the path from d[0] to d[i]. */
    u[0] = 0.0;
    for (unsigned i = 1; i < len; i++) {
        double const dist = distance(d[i], d[i-1]);
        u[i] = u[i-1] + dist;
    }

    /* Then scale to [0.0 .. 1.0]. */
    double tot_len = u[len - 1];
    if(!( tot_len != 0 ))
        return;
    if (IS_FINITE(tot_len)) {
        for (unsigned i = 1; i < len; ++i) {
            u[i] /= tot_len;
        }
    } else {
        /* We could do better, but this probably never happens anyway. */
        for (unsigned i = 1; i < len; ++i) {
            u[i] = i / (double) ( len - 1 );
        }
    }

    /** \todo
     * It's been reported that u[len - 1] can differ from 1.0 on some 
     * systems (amd64), despite it having been calculated as x / x where x 
     * is isFinite and non-zero.
     */
    if (u[len - 1] != 1) {
        double const diff = u[len - 1] - 1;
        if (fabs(diff) > 1e-13) {
            assert(0); // No warnings in 2geom
            //g_warning("u[len - 1] = %19g (= 1 + %19g), expecting exactly 1",
            //          u[len - 1], diff);
        }
        u[len - 1] = 1;
    }

#ifdef BEZIER_DEBUG
    assert( u[0] == 0.0 && u[len - 1] == 1.0 );
    for (unsigned i = 1; i < len; i++) {
        assert( u[i] >= u[i-1] );
    }
#endif
}


Generated by  Doxygen 1.6.0   Back to index