-
Notifications
You must be signed in to change notification settings - Fork 443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Geometry.equals(Geometry) to have equalsExact semantics #159
Comments
Wouldn't the more painful part be that i.e., assuming JTS works the same as NTS, you ought to wind up with this apparent inconsistency, which seems more confusing (to me) than the exact truth value on either line (especially in real-world scenarios where static void tst()
{
Geometry g1 = createNewGeom();
Geometry g2 = createSimilarGeom(); /* such that g1.equalsTopo(g2) && !g1.equalsExact(g2) */
Object o2 = g2;
g1.equals(g2); /* true */
g1.equals(o2); /* false */
} Also, rather than being impossible*, *In fact, you can always trivially make a correct **This actually wouldn't be unambiguously "better" overall, though: in many real-world cases, I expect that |
Yes, correct. My error. So this is not a driver for this change. Updated the issue to reflect this. And agreed that the current hashcode based on extent is a good balance of performance and selectivity. |
Yes, exactly. That's why this is a breaking change. The example you give is why this change would improve the API, by removing the un-obvious difference between |
I'm missing something in general, I guess. The way the issue is described, it sounds like the implementation of But then as it goes on, it justifies itself as though the method to be changed is The description doesn't (and definitely didn't) read like "change |
Good point - I will clarify the issue description. |
Please do this change, or implement equalsTopo support for GeometryCollection. |
The reason there is no Will have to think about the effects of this breaking change before implementing it. |
Just stumbled into this by doing some PMD related cleanups in GeoTools. Now, doing the migration, with a and b being geometries, ended up changing the semantics of the comparison, from equalsTopo to equalsExact, because the assertEquals method in JUnit uses |
@aaime yes, that's the kind of crazy-making thing that happens with the current API semantics. I take it then that you would be in favour of this change? |
@aaime actually it seems to me to be suspect that the topological equality would be used in a unit test. It is a relatively weak condition, which might mask certain kinds of errors. And in a unit test it should be possible to be more precise about what the expected value is. |
@airbreather Are you in favour of this change? |
Hm. I am in favor of removing the inconsistency that I posted earlier, and if we have to change the semantics of one, then I wonder if it might not make more sense to deprecate and start working towards removing
Personally, I prefer the |
Good.
Agreed. Start with deprecation, then remove.
Agreed. Will keep |
I'm in agreement with any move that resolves the inconsistencies, the current situation is hard explain and reason about. The test that failed after migration from assertTrue to assertEquals really needed the equalsTopo behavior, but we can just update the tests to explicitly use that method when the chanage in JTS happens. |
Why not update it now, so that it works? |
Cause I already have spent enough time on this. Those upgrading JTS in GeoTools will have a reason to change the tests (they are not many, I'm not setting a major roadblock in front of them). |
@aaime thanks for pointing that out! Hopefully @jodygarnett and I will remember when the time comes! |
A long-standing confusion in the JTS
Geometry
class is thatGeometry.equals(Geometry)
has the semantics of topological-equality, rather than exact-equality (which is more usual for Java). This impacts using JTS in collections or frameworks which rely onequals
having standard Java semantics (for example, ORMs such as JPA). In most use cases for collections and containers the desire is for exact-equality semantics.Even more confusingly, to mitigate this the method
Geometry.equals(Object)
was added, which has exact-equality semantics. This helps ensure that some container classes "do the right thing" of using the faster exact-equality, but it's hard to be sure they are doing this without close inspection.Geometry.equals(Geometry)
should be changed to have exact-equality semantics.To compute topological-equality the
Geometry.equalsTopo(Geometry)
method can be used. The use cases fortopological-equality
seem to be fairly rare, so having a slightly more verbose method name should not be a problem. This causes a slight discrepancy with the standard OGC Spatial Predicate definition, but the benefits of comprehension and safety outweigh this.When this change is made the existing
Geometry.equalsExact(Geometry)
method will be redundant and can be deprecated. EDIT:Geometry.equalsExact(Geometry)
will be kept, since the name clearly indicates the semantics.equals
will delegate to it.NOTE that this is definitely a breaking API change.
NOTE 2: As pointed out below, this does not affect the implentation of
hashCode()
, which is currently appropriate for either definition of equality.The text was updated successfully, but these errors were encountered: