Boost logo

Boost :

From: Mark Gilbert (markgilbert_at_[hidden])
Date: 2005-06-09 18:02:09


"Guillaume Melquiond" <guillaume.melquiond_at_[hidden]> wrote in message
news:1118349671.6045.19.camel_at_saline...
>Le jeudi 09 juin 2005 à 14:23 -0500, Mark Gilbert a écrit :

>> T evaluate(T t) const { return low + t * extent(); }
>> T normalize(T t) const { return (t - low) / extent(); }
>> evaluate and normalize map the interval to a normalized interval with
>> values
>> in the range [0,1].

>Concerning 'evaluate' and 'normalize' though, they don't strike me as
>necessary. First, the names are not really indicative of their semantic.
>Second, the interval [0,1] seems a bit arbitrary: [-1,1] would make as
>much sense to me.

Hi Guillaume,

Let me argue for evaluate and normalize a little. Here is code that
generates 21 points on a line from (x0,y0) to (x1,y1):
for (int i = 0; i <= 20; i++)
{
    double p = i / 20.0;
    dopoint(interval(x0,x1).evaluate(p), interval(y0,y1).evaluate(p));
}

Here is a linear interpolator for a function that is known only at integer
values:
double interpolate(double values[], double x)
{
    int x0 = ifloor(x);
    int x1 = iceil(x);
    double xfrac = x - x0;
    return interval(values[x0],values[x1]).evaluate(xfrac));
}

Mapping to and from the range [0,1] lets you get at the ideas "where does
this value fall in my interval?" and "what value is at this position in my
interval?" Your median function is similar to evaluate, but 0.5 is just one
position in the interval that might be interesting. Perhaps evaluate(0.25)
or evaluate(x) are more interesting for some applications.

Regarding the names. I work a lot with parameterized curves in space, which
are "normally" parameterized on [0,1]. I "evaluate" a value in that range
to get a point on the curve (or a value in an interval). Perhaps without
that context, other names would be better, though normalize might still be
analogous to normalizing a vector to a unit vector.

Instead of evaluate and normalize:
scale and normalize?
at_position and position (or get_position)?
map_from_01 and map_to_01?

I'm not sure I like any of those, but we can probably think of something
better if you decide the functions themselves might be handy.

Cheers,
Mark Gilbert


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk