[geos-devel] CoordinateSequence::reverse(CoordinateSequence *cl) bug
Elliott Edwards
eedwards at hachisoft.com
Thu Sep 23 12:59:41 EDT 2004
Greetings all.
I am not certain that this issue hasn't already been addressed, but I
thought that I would submit it anyway.
//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-
More information about the geos-devel
mailing list