Nowadays, when you create an Envelope is initialized to (0,0) - (0,0). This is a big bug source. Per example: Point p1 = geometryManager.createPoint(5.0,5.0,SUBTYPES.GEOM2D); Point p2 = geometryManager.createPoint(10.0,10.0,SUBTYPES.GEOM2D); Envelope env = geometryManager.createEnvelope(SUBTYPES.GEOM2D); env.add(p1.getEnvelope()); env.add(p2.getEnvelope()); You'd think you'll get (5,5)-(10,10) envelope but you really get (0,0)-(10,10). You can see an example of bug like this in libFmap_dal:MemoryStoreProvider.java:188-189
OperatingSystem | None |
BuildNumber | OS/2 |
SubprojectResolveBuildNumber | OSF/1 |
Resolution | Fixed |
Severity | normal |
SubprojectName | gvSIG |
Component | None |
Version | gvSIG - 2.0.0 |
SubprojectVersion | gvSIG - 2.0.0 |
SubprojectResolveVersion | None |
Has patch | None |
Category
Bugs
Login or
create an account to comment.
Comments
Chema: "You'd think you'll get (5,5)-(10,10) envelope but you really get (0,0)-(10,10)." I totally agree with you Chema, but I don't know If the solution is the best one. If we initialize the internal points to "null" we have to add a null comparation in all the methods that use these points. I can do that, but: There are other methods that I don't have clear how implement them (e.g: getLength, getCenter, getMaximum, getMinimum, etc). All of them have to return null? I've seen the other usages of the "envelope.add" method and the normal use of this method is: while (it.hasNext()){ Feature feature=(Feature) iter.next(); Geometry geom = feature.getDefaultGeometry(); if (envelope == null) { envelope = geom.getEnvelope(); } else { envelope.add(geom.getEnvelope()); } } If you don't want to check if the envelope is null you can two whiles (just for performance) while (it.hasNext()){ Feature feature=(Feature) iter.next(); Geometry geom = feature.getDefaultGeometry(); envelope = geom.getEnvelope(); break; } while (it.hasNext()){ Feature feature=(Feature) iter.next(); Geometry geom = feature.getDefaultGeometry(); envelope.add(geom.getEnvelope()); break; } I can review all the usages of the add method and fix it. I can also add a comment to the Javadoc to explain that the Envelope is initialized to 0. I don't have clear which is the best solution....
> There are other methods that I don't have clear how implement > them (e.g: getLength, getCenter, getMaximum, getMinimum, etc). > All of them have to return null? IMHO I prefer a NPE (or any sort of Initialization Exception) in first test. This makes me known the bug early.
I've added a runtime exception in the methods that need a value for the coordinates. This update could have secondary effects in the usage of the Envelope. I've checked a shape and a DXF without geometries and it works fine.