Skip to content
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

OGCGeometry.equals #110

Closed
randallwhitman opened this issue Mar 8, 2016 · 5 comments
Closed

OGCGeometry.equals #110

randallwhitman opened this issue Mar 8, 2016 · 5 comments
Assignees
Milestone

Comments

@randallwhitman
Copy link
Contributor

Let me know if there is something wrong with the following test, but I think it indicates an issue with OGCGeometry.equals(Object).

    public void testEquals() {
        Point pt = new Point(15.0, 5.0);
        // For comparison/reference
        assertEquals(new MapGeometry(pt, null), new MapGeometry(pt, null));
        assertEquals(new MapGeometry(new Point(1.0, 2.0), null), new MapGeometry(new Point(1.0, 2.0), null));
        // Test OGCGeometry#equals
        assertTrue(OGCGeometry.createFromEsriGeometry(pt, null).equals(OGCGeometry.createFromEsriGeometry(pt, null)));  // ok
        assertEquals(OGCGeometry.createFromEsriGeometry(pt, null), OGCGeometry.createFromEsriGeometry(pt, null));  // fail
        assertEquals(OGCGeometry.createFromEsriGeometry(new Point(1.0, 2.0), null), OGCGeometry.createFromEsriGeometry(new Point(1.0, 2.0), null));  // fail

    }

Maybe need OGCGeometry.equals(Object) similar to that of MapGeometry, such as:

    @Override
    public boolean equals(Object other) {
        if (other == this)
            return true;
        if (other == null  ||  other.getClass() != getClass())
            return false;
        return equals((OGCGeometry)other);
    }

(Ran across this issue while writing unit tests for JSON SerDe classes in Spatial-Framework-for-Hadoop.)

@randallwhitman
Copy link
Contributor Author

As mentioned in the incomplete patch, it would then also need hashCode.

@stolstov
Copy link
Member

stolstov commented Mar 9, 2016

@randallwhitman I have different fix in the full version. Note that the OGC equals is not same as java equals. Java equals is identity comparison, while OGC equals is topological.

@stolstov
Copy link
Member

stolstov commented Mar 9, 2016

Name is not good. Maybe we should rename OGC equals to Equals(OGCGeometry), and leave java equals(Object) to do Java identity thing.

@randallwhitman
Copy link
Contributor Author

In Java, operator == is identity, whereas CustomType.equals is conceptual equality.

@stolstov
Copy link
Member

stolstov commented Mar 9, 2016

The ogc equals is slow, and also, probably not what one expects when storing a class in a container, such a hash map. I think ogc equals it should be different from identity equals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants