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

Expose ordinal constants and use instead of reflection #222

Merged
merged 2 commits into from May 21, 2020

Conversation

bjornharrtell
Copy link
Contributor

Primary goal of this PR is to avoid use of reflection in GeometryExtracter. Keeps existing API as deprecated.

The rename of SORTINDEX_* to ORDINAL_* is a suggestion from previous discussion.

@bjornharrtell
Copy link
Contributor Author

Investigating test failure...

@bjornharrtell
Copy link
Contributor Author

Problem is that the reflection logic will also extract LinearRings when LineString class is given.

@dr-jts
Copy link
Contributor

dr-jts commented Nov 13, 2017

Since the use of the numeric code is expanding beyond the Geometry class internals, I think a better name would be TYPECODE_XXX. This echoes the current Geometry type concept.

Or perhaps the Geometry type should be used for GeometryExtracter? This would require exposing them as named constants, which is no bad thing.

@bjornharrtell
Copy link
Contributor Author

Agreed, I'll sleep on it and get back with something like one of your suggestions whatever seems nicest.

@bjornharrtell
Copy link
Contributor Author

bjornharrtell commented Nov 14, 2017

Opted to rename to TYPECODE and protect, and make GeometryType public (+ named constants) and use that for the GeometryExtractor.

}

public void filter(Geometry geom)
{
if (ordinal == -1 || geom.getOrdinal() == ordinal || isLinear(geom, ordinal))
if (geometryType == null || geom.getGeometryType() == geometryType || isLinear(geom, geometryType))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the presence of isLinear here. Wouldn't that mean that linear geometries are always added no matter what the requested type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original logic extracted LinearRings when the clz was set to LineString, which I didn't expect at first but I suppose that's how isAssignableFrom works. So that's why I added this exception to the rule. But perhaps it's the name isLinear which isn't right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I understand the logic now. Wasn't clear because the logic for linear is split between that function and the isLinear one.

How about this instead?

protected static boolean isOfType(Geometry geom, int geometryType) {
  if (geom.getGeometryType() == geometryType) return true;
  if (geometryType == Geometry.TYPENAME_LINESTRING 
  	&& geom.getGeometryType() == Geometry.TYPENAME_LINEARRING && ) return true;
  return false;
}

public void filter(Geometry geom) {
  if (geometryType == null || isOfType(geom, geometryType))
    comps.add(geom);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, much clearer - taken. :)

@bjornharrtell
Copy link
Contributor Author

I see now I missed some JavaDocs updating. Will fix.

@bjornharrtell
Copy link
Contributor Author

Should be all done now, hopefully.

@dr-jts
Copy link
Contributor

dr-jts commented Nov 14, 2017

Ideally GeometryExtracter should have a unit test too... :) (That would surface the subtle logic about linear handling).

Feel like giving this a shot? Or I can probably add one when this is merged.

@bjornharrtell
Copy link
Contributor Author

Sure I'll give that a shot. :) But time is up for today.

@bjornharrtell
Copy link
Contributor Author

@dr-jts testcase added. Quite simplistic but does the intended verification I hope.

@dr-jts
Copy link
Contributor

dr-jts commented Nov 16, 2017

@bjornharrtell This looks good. If it's complete I will merge.

@jnh5y
Copy link
Contributor

jnh5y commented Dec 8, 2017

@bjornharrtell are you finished with this PR? Looks like Martin might be looking confirmation before merging.

@bjornharrtell
Copy link
Contributor Author

Good to go :)

@bjornharrtell
Copy link
Contributor Author

@dr-jts, gentle reminder that this is ready to merge.

@jodygarnett
Copy link
Contributor

collecting PRs, @bjornharrtell + @dr-jts ?

@bjornharrtell
Copy link
Contributor Author

I believe this is ready.

@bjornharrtell
Copy link
Contributor Author

Squashed and rebased on master, all tests pass. Still ready for merge AFAIK. :)

Signed-off-by: Björn Harrtell <bjorn@wololo.org>
@bjornharrtell bjornharrtell force-pushed the ordinal branch 2 times, most recently from 3e14ca0 to c19df38 Compare May 21, 2020 08:45
Signed-off-by: Björn Harrtell <bjorn@wololo.org>
@bjornharrtell
Copy link
Contributor Author

@dr-jts and @jodygarnett I've just rebased this on master - I still think it's a general improvement and a necessity for JSTS.

@dr-jts dr-jts merged commit 511c3d9 into locationtech:master May 21, 2020
@bjornharrtell bjornharrtell deleted the ordinal branch May 21, 2020 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants