[GRASS5] [bug #2333] (grass) r.colors: 0.0%, 100.0% doesn't match 'r.info -r'

Hamish hamish_nospam at yahoo.com
Tue Feb 24 00:56:07 EST 2004


[bug #2333]
> > Subject: r.colors: 0.0%, 100.0% doesn't match 'r.info -r'
...
> > setting r.colors' by percentage value isn't correct, making boundary
> > values show up on the map as patches of no colour.
...
> src/raster/r.colors/cmd/rules.c, lines 190 and 247:
> 
> 	    *val = min + ((double)max-(double)min)*(n+0.5)/100.0;
> 
> It adds 0.5% to the specified value. In 4.3, the corresponding lines
> look like this:
> 
> 	    *cat = min + ((double)max-(double)min)*n/100.0 + .5;
> 
> where *cat, min, max and n are all integers.
> 
> Simply removing the +0.5 would result in a significant improvement,
> but there could still be residual problems with the actual min/max
> values due to rounding errors.


To solve that, could we add something along the lines of:

if(&val < (double)min)
    *val = (double)min;
if(&val > (double)max)
    *val = (double)max;


as n>100% and n<0% are illegal, from the lines directly above:
 if (!lookup_color (color, r,g,b) || n < 0 || n > 100)
	    {
		badrule(buf,line);
		continue;
	    }



[is it bad to do (n < 0) when n is a double? cast of "0" is automatic?]


shrug

thanks,
Hamish




More information about the grass-dev mailing list