[geos-devel] CoordinateSequence::reverse(CoordinateSequence *cl) bug

strk at refractions.net strk at refractions.net
Thu Sep 23 17:37:54 EDT 2004


On Thu, Sep 23, 2004 at 09:59:41AM -0700, Elliott Edwards wrote:
> Greetings all.
> 
> I am not certain that this issue hasn't already been addressed, but I 
> thought that I would submit it anyway.

Thanks Elliot.
It was still bogus.
Now fixed in CVS.
--strk;

> 
> //The existing version
> void CoordinateSequence::reverse(CoordinateSequence *cl){
> 	int last=cl->getSize()-1;
> 	int mid=last/2;
> 	for(int i=0;i<=mid;i++) {
> 		const Coordinate& tmp=cl->getAt(i);
> 		cl->setAt(cl->getAt(last-i),i);
> 		cl->setAt(tmp,last-i);
> 	}
> }
> 
> The result of this code is not to reverse the coordinate sequence, but 
> rather to reflect the first half of it.
> 
> Ex: If A-Z are coordinates:
> 
> A B C D E F G
> 
> would incorrectly become
> 
> A B C D C B A
> 
> instead of
> 
> G F E D C B A
> 
> This is a result of the "tmp" variable being a "Coordinate&" rather than 
>  a "Coordinate".
> 
> //The corrected version
> void CoordinateSequence::reverse(CoordinateSequence *cl){
> 	int last=cl->getSize()-1;
> 	int mid=last/2;
> 	for(int i=0;i<=mid;i++) {
> 		const Coordinate tmp=cl->getAt(i);
> 		cl->setAt(cl->getAt(last-i),i);
> 		cl->setAt(tmp,last-i);
> 	}
> }
> 
> Note: This also affects the correctness of Polygon::normalize() because 
> it uses the CoordinateSequence::reverse to normalize the polygon winding.
> 
> Please disregard this message if this issue has already been resolved or 
> a resolution is in the works.
> 
> -Elliott Edwards-
> _______________________________________________
> geos-devel mailing list
> geos-devel at geos.refractions.net
> http://geos.refractions.net/mailman/listinfo/geos-devel



More information about the geos-devel mailing list