mirror of https://github.com/apache/lucene.git
LUCENE-7955: Adjust degenerate path logic to not consider endpoints unless needed.
This commit is contained in:
parent
a4fc14baed
commit
80ae2699cf
|
@ -259,10 +259,11 @@ class GeoDegeneratePath extends GeoBasePath {
|
||||||
// Well, sort of. We can detect intersections also due to overlap of segments with each other.
|
// 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.
|
// 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);
|
//System.err.println(" Looking for intersection of plane "+plane+" with path "+this);
|
||||||
for (final SegmentEndpoint pathPoint : endPoints) {
|
|
||||||
if (pathPoint.intersects(planetModel, plane, notablePoints, bounds)) {
|
// Since the endpoints are included in the path segments, we only need to do this if there are
|
||||||
return true;
|
// no path segments
|
||||||
}
|
if (endPoints.size() == 1) {
|
||||||
|
return endPoints.get(0).intersects(planetModel, plane, notablePoints, bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final PathSegment pathSegment : segments) {
|
for (final PathSegment pathSegment : segments) {
|
||||||
|
@ -276,10 +277,10 @@ class GeoDegeneratePath extends GeoBasePath {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean intersects(GeoShape geoShape) {
|
public boolean intersects(GeoShape geoShape) {
|
||||||
for (final SegmentEndpoint pathPoint : endPoints) {
|
// Since the endpoints are included in the path segments, we only need to do this if there are
|
||||||
if (pathPoint.intersects(geoShape)) {
|
// no path segments
|
||||||
return true;
|
if (endPoints.size() == 1) {
|
||||||
}
|
return endPoints.get(0).intersects(geoShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final PathSegment pathSegment : segments) {
|
for (final PathSegment pathSegment : segments) {
|
||||||
|
@ -300,8 +301,8 @@ class GeoDegeneratePath extends GeoBasePath {
|
||||||
for (PathSegment pathSegment : segments) {
|
for (PathSegment pathSegment : segments) {
|
||||||
pathSegment.getBounds(planetModel, bounds);
|
pathSegment.getBounds(planetModel, bounds);
|
||||||
}
|
}
|
||||||
for (SegmentEndpoint pathPoint : endPoints) {
|
if (endPoints.size() == 1) {
|
||||||
pathPoint.getBounds(planetModel, bounds);
|
endPoints.get(0).getBounds(planetModel, bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -736,6 +736,21 @@ public class SimpleGeoPolygonRelationshipsTest {
|
||||||
assertEquals(GeoArea.CONTAINS, rel);
|
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,
|
private GeoPolygon buildConvexGeoPolygon(double lon1, double lat1,
|
||||||
double lon2, double lat2,
|
double lon2, double lat2,
|
||||||
double lon3, double lat3,
|
double lon3, double lat3,
|
||||||
|
|
Loading…
Reference in New Issue