Skip to content

Conversation

@DaveCTurner
Copy link
Contributor

@DaveCTurner DaveCTurner commented Dec 6, 2017

Normally the hole is assigned to the component of the first edge to the south
of one of its vertices, but if the chosen hole vertex is south of everything
then the binary search returns -1 yielding an ArrayIndexOutOfBoundsException.
Instead, assign the vertex to the component of the first edge to its north.
Subsequent validation catches the fact that the hole is outside its component.

Fixes #25933

Normally the hole is assigned to the component of the first edge to the south
of one of its vertices, but if the chosen hole vertex is south of everything
then the binary search returns -1 yielding an ArrayIndexOutOfBoundsException.
Instead, assign the vertex to the component of the first edge to its north.
Subsequent validation catches the fact that the hole is outside its component.

Fixes elastic#25933
@DaveCTurner DaveCTurner added :Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v6.2.0 v7.0.0 labels Dec 6, 2017
@DaveCTurner DaveCTurner requested a review from cbuescher December 6, 2017 08:35
pb.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(4, 2).coordinate(3, 1).coordinate(4, 1).close()));
pb.build();
} catch (InvalidShapeException e) {
assertEquals("Hole lies outside shell at or near point (4.0, 1.0, NaN)", e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

nit: there is the neat expectThrows() utility in LuceneTestCase that makes test for exceptions a little more succinct. MIght help here (and in the other test) as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

D'oh, I forgot about that. I pushed dc88dac

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@DaveCTurner I had a look at the PR and left a small comment, other than that I'm not too familiar with the validation of polygons wt. holes and cannot comment with much certainty on the proposed fix. I think @nknize should have a look at this as well.

@DaveCTurner DaveCTurner requested a review from nknize December 6, 2017 08:54
@DaveCTurner
Copy link
Contributor Author

@nknize does this look ok to you?

throw new InvalidShapeException("Invalid shape: Hole is not within polygon");
}
final int index = -((sharedVertex) ? 0 : pos+2);
final int index = sharedVertex || pos == -1 ? 0 : -(pos+2);
Copy link
Member

Choose a reason for hiding this comment

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

@DaveCTurner thanks for walking me trough this f2f, it took some time for me to understand but now I think I understand this whole method a lot better. This looks right to me now after some longer thought, I think we should add some comments to this part after that explains the three(?) cases that might be true at this point and what that means for the index of the edge we assign this component to.

Copy link
Member

@cbuescher cbuescher left a comment

Choose a reason for hiding this comment

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

@DaveCTurner thanks a lot for the additional comments. More verbose but definitely more readable IMHO.

@DaveCTurner DaveCTurner merged commit e6da564 into elastic:master Dec 18, 2017
@DaveCTurner DaveCTurner deleted the 2017-12-05-issue-25933 branch December 18, 2017 08:50
DaveCTurner added a commit to DaveCTurner/elasticsearch that referenced this pull request Dec 18, 2017
…s) (elastic#27685)

Normally the hole is assigned to the component of the first edge to the south
of one of its vertices, but if the chosen hole vertex is south of everything
then the binary search returns -1 yielding an ArrayIndexOutOfBoundsException.
Instead, assign the vertex to the component of the first edge to its north.
Subsequent validation catches the fact that the hole is outside its component.

Fixes elastic#25933
@DaveCTurner
Copy link
Contributor Author

Merged as e6da564 and backported to 6.x as ba83eda.

martijnvg added a commit that referenced this pull request Dec 18, 2017
* es/6.x: (170 commits)
  Allow TrimFilter to be used in custom normalizers (#27758)
  recovery from snapshot should fill gaps (#27850)
  Remove unused class PreBuiltTokenFilters (#27839)
  Reject scroll query if size is 0 (#22552) (#27842)
  Mutes ‘Rollover no condition matched’ YAML test
  Make randomNonNegativeLong() draw from a uniform distribution (#27856)
  Adapt rest test after backport. Relates #27833
  Handle case where the hole vertex is south of the containing polygon(s) (#27685)
  Move range field mapper back to core
  Fix publication of elasticsearch-cli to Maven
  Do not use system properties when building the HttpAsyncClient (#27829)
  Optimize version map for append-only indexing (#27752)
  Add NioGroup for use in different transports (#27737)
  adapt field collapsing skip test version. relates #27833
  Add version support for inner hits in field collapsing (#27822) (#27833)
  Clarify that number of threads is set by packages
  Register HTTP read timeout setting
  Fixes Checkstyle
  Remove `operationThreaded` from Java API (#27836)
  Fixes failing BytesSizeValues tests
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/Geo Indexing, search aggregations of geo points and shapes >bug v6.2.0 v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants