[GRASS5] Bug: vector maps shifted (d.area / d.vect)

Glynn Clements glynn.clements at virgin.net
Sat Oct 20 20:47:15 EDT 2001

Glynn Clements wrote:

> > just found an inconsistency: d.area draws maps
> > shifted to north-west.
> > 
> > I have generated a polygon with r.digit, the vectorized
> > with r.poly. Comparing d.vect and d.rast the overlay
> > looks perfect, while d.area produces a shifted result.
> > Also v.area is not consistent (I guess d.area and v.area
> > have a similar code history).
> d.vect uses G_plot_line() (in src/libes/gis/plot.c), which (in
> fastline()) adds 0.5 to each coordinate. d.area doesn't use this
> function.
> If you remove the +0.5 from fastline(), d.vect and d.area coincide. 
> However, G_plot_line() is used in many places, so changing it to suit
> d.vect may break other things.

OTOH, d.area uses D_u_to_d_{col,row}. Although these functions return
a double, they truncated the value to an integer (they don't any more;
I've changed them). Then, in every place where these functions are
called, the returned double is typecast to an int.

Now that the full precision is returned, the caller has the choice of
whether to truncate or round.

For drawing lines, I suspect that truncation is the correct operation. 
The (integer) pixel coordinate <X,Y> covers the area [X,X+1]*[Y,Y+1]. 
E.g. the point <1.999,2.999> lies within square corresponding to the
pixel with coordinates <1,2>.

So, d.vect (and, by implication, anything which is consistent with
it), is probably wrong.

Glynn Clements <glynn.clements at virgin.net>

More information about the grass-dev mailing list