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
Conversation
Investigating test failure... |
Problem is that the reflection logic will also extract LinearRings when LineString class is given. |
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. |
Agreed, I'll sleep on it and get back with something like one of your suggestions whatever seems nicest. |
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)) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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. :)
I see now I missed some JavaDocs updating. Will fix. |
Should be all done now, hopefully. |
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. |
Sure I'll give that a shot. :) But time is up for today. |
@dr-jts testcase added. Quite simplistic but does the intended verification I hope. |
@bjornharrtell This looks good. If it's complete I will merge. |
@bjornharrtell are you finished with this PR? Looks like Martin might be looking confirmation before merging. |
Good to go :) |
@dr-jts, gentle reminder that this is ready to merge. |
collecting PRs, @bjornharrtell + @dr-jts ? |
I believe this is ready. |
a398b51
to
e9fe1ad
Compare
Squashed and rebased on master, all tests pass. Still ready for merge AFAIK. :) |
Signed-off-by: Björn Harrtell <bjorn@wololo.org>
3e14ca0
to
c19df38
Compare
Signed-off-by: Björn Harrtell <bjorn@wololo.org>
@dr-jts and @jodygarnett I've just rebased this on master - I still think it's a general improvement and a necessity for JSTS. |
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.