LUCENE-7955: Adjust degenerate path logic to not consider endpoints unless needed.

This commit is contained in:
Karl Wright 2017-09-10 07:00:20 -04:00
parent a4fc14baed
commit 80ae2699cf
2 changed files with 26 additions and 10 deletions

View File

@ -259,10 +259,11 @@ class GeoDegeneratePath extends GeoBasePath {
// Well, sort of. We can detect intersections also due to overlap of segments with each other.
// But that's an edge case and we won't be optimizing for it.
//System.err.println(" Looking for intersection of plane "+plane+" with path "+this);
for (final SegmentEndpoint pathPoint : endPoints) {
if (pathPoint.intersects(planetModel, plane, notablePoints, bounds)) {
return true;
}
// Since the endpoints are included in the path segments, we only need to do this if there are
// no path segments
if (endPoints.size() == 1) {
return endPoints.get(0).intersects(planetModel, plane, notablePoints, bounds);
}
for (final PathSegment pathSegment : segments) {
@ -276,10 +277,10 @@ class GeoDegeneratePath extends GeoBasePath {
@Override
public boolean intersects(GeoShape geoShape) {
for (final SegmentEndpoint pathPoint : endPoints) {
if (pathPoint.intersects(geoShape)) {
return true;
}
// Since the endpoints are included in the path segments, we only need to do this if there are
// no path segments
if (endPoints.size() == 1) {
return endPoints.get(0).intersects(geoShape);
}
for (final PathSegment pathSegment : segments) {
@ -300,8 +301,8 @@ class GeoDegeneratePath extends GeoBasePath {
for (PathSegment pathSegment : segments) {
pathSegment.getBounds(planetModel, bounds);
}
for (SegmentEndpoint pathPoint : endPoints) {
pathPoint.getBounds(planetModel, bounds);
if (endPoints.size() == 1) {
endPoints.get(0).getBounds(planetModel, bounds);
}
}

View File

@ -736,6 +736,21 @@ public class SimpleGeoPolygonRelationshipsTest {
assertEquals(GeoArea.CONTAINS, rel);
}
@Test
public void testDegeneratePathShape(){
GeoPoint point1 = new GeoPoint(PlanetModel.SPHERE, 0, 0);
GeoPoint point2 = new GeoPoint(PlanetModel.SPHERE, 0, 1);
GeoPoint[] pointPath1 = new GeoPoint[] {point1, point2};
GeoPath path1 = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 0, pointPath1);
GeoPath path2 = GeoPathFactory.makeGeoPath(PlanetModel.SPHERE, 1, pointPath1);
int rel = path1.getRelationship(path2);
//if an end point is inside the shape it will always return intersects
assertEquals(GeoArea.CONTAINS, rel); //should be contains?
rel = path2.getRelationship(path1);
assertEquals(GeoArea.WITHIN, rel);
}
private GeoPolygon buildConvexGeoPolygon(double lon1, double lat1,
double lon2, double lat2,
double lon3, double lat3,