[GRASS5] color table

Radim Blazek blazek at itc.it
Tue Aug 26 03:42:22 EDT 2003


On Tuesday 26 August 2003 02:52, Glynn Clements wrote:
> Radim Blazek wrote:
> > Bug?:
>
> Yep. In libgis.
>
> > r.mapcalc pok1=-6.0
> > echo -e "-10.1 green\n-5 green\n-5 blue\n10 blue" | r.colors map=pok1
> > color=rules r.mapcalc pok2="int(pok1)"
> > r.colors map=pok2 rast=pok1
> > d.rast map=pok2 ---> blue!!!
>
> It's due to an inconsistency in the convertion of negative FP values
> to integers. organize_lookup() in color_org.c simply truncates:
>
>   121:    x = (CELL ) cp->min;
>
>
> while G__lookup_colors() in color_look.c uses floor():
>
>   156:    dmin = cp->min;
>   157:    dmax = cp->max;
>   158:    min = floor(dmin);
>
> Truncating rounds towards zero, while floor() rounds downwards
> (towards minus infinity), so if cp->min is -10.1, truncating gives -10
> while floor gives -11. This causes lookups in cp->lookup.{red,grn,blu}
> to be off by one.
>
> Try the attached patch.

OK, are you going to submit it to CVS?

Ra




More information about the grass-dev mailing list