Logo Search packages:      
Sourcecode: inkscape version File versions

static void chord_length_parameterize ( NR::Point const   d[],
gdouble  u[],
unsigned const   len 
) [static]

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

Parameter array u must have space for len items.

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

{
    g_return_if_fail( 2 <= len );

    /* 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 = L2( d[i] - d[i-1] );
        u[i] = u[i-1] + dist;
    }

    /* Then scale to [0.0 .. 1.0]. */
    gdouble tot_len = u[len - 1];
    g_return_if_fail( tot_len != 0 );
    if (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 / (gdouble) ( len - 1 );
        }
    }

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


Generated by  Doxygen 1.6.0   Back to index