-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
LUCENE-8620: LatLonShape contains #546
Conversation
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.
I had a (very) quick look, I'll try to do a deeper review later.
@@ -101,6 +101,60 @@ public Relation relateTriangle(double ax, double ay, double bx, double by, doubl | |||
return Relation.CELL_OUTSIDE_QUERY; | |||
} | |||
|
|||
/** Used by {@link withinTriangle} to check the relationship between a triangle and the query shape */ | |||
public enum WithinRelation { | |||
/** If the shape is a candidate for within. Tipically this is return if the query shape is fully inside |
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.
s/Tipically/Typically/
* the triangle or if the query shape intersects only edges that do not belong to the original shape. */ | ||
CANDIDATE, | ||
/** Return this if if the query shape intersects an edge that does belong to the original shape. */ | ||
INTERSECTS, |
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.
is it what we call CROSSES
elsewhere?
@@ -150,9 +204,88 @@ private Relation internalComponentRelateTriangle(double ax, double ay, double bx | |||
if (tree.crossesTriangle(ax, ay, bx, by, cx, cy)) { | |||
return Relation.CELL_CROSSES_QUERY; | |||
} | |||
if (pointInTriangle(tree.lon1, tree.lat1, ax, ay, bx, by, cx, cy) == true) { | |||
return Relation.CELL_CROSSES_QUERY; | |||
} |
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.
This looks like an unrelated bug, let's have a dedicated issue for it?
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.
@@ -118,19 +118,21 @@ public static Query newPolygonQuery(String field, QueryRelation queryRelation, P | |||
* these triangles are encoded and inserted as separate indexed POINT fields | |||
*/ | |||
private static class LatLonTriangle extends Field { | |||
|
|||
//Constructor for points and lines |
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.
👍
int cY = scratchTriangle.cY; | ||
int cX = scratchTriangle.cX; | ||
|
||
return rectangle2D.withinTriangle(aX, aY, scratchTriangle.ab, bX, bY, scratchTriangle.bc, cX, cY, scratchTriangle.ca); |
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.
extracting variables doesn't seem helpful here?
@@ -202,7 +286,7 @@ private boolean queryIntersects(int ax, int ay, int bx, int by, int cx, int cy) | |||
return false; | |||
} | |||
|
|||
/** returns true if the edge (defined by (ax, ay) (bx, by)) intersects the query */ | |||
/** returns true if the edge (defined by (ax, ay) (bx, by)) crosses the query */ |
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.
docs don't match the method name
@@ -224,7 +313,7 @@ private static boolean bboxContainsTriangle(int ax, int ay, int bx, int by, int | |||
&& bboxContainsPoint(cx, cy, minX, maxX, minY, maxY); | |||
} | |||
|
|||
/** returns true if the edge (defined by (ax, ay) (bx, by)) intersects the query */ | |||
/** returns true if the edge (defined by (ax, ay) (bx, by)) crosses the query */ |
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.
docs don't match the method name?
return false; | ||
} | ||
} else if(queryRelation == QueryRelation.CONTAINS) { |
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.
let's add one space between if
and (
?
return false; | ||
} | ||
} else if(queryRelation == QueryRelation.CONTAINS) { | ||
EdgeTree.WithinRelation relation = rectangle2D.withinTriangle(decoded.aX, decoded.aY, decoded.ab, decoded.bX, decoded.bY, decoded.bc, decoded.cX, decoded.cY, decoded.ca); | ||
if (relation == EdgeTree.WithinRelation.INTERSECTS) { |
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.
only one space between if
and (
? :)
return true; | ||
} | ||
Polygon[] currentPolygons = new Polygon[totalPolygons]; | ||
for (int i =0; i < totalPolygons; i++) { |
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.
add a space between =
and 0
?
/** If the shape is a candidate for within. Typically this is return if the query shape is fully inside | ||
* the triangle or if the query shape intersects only edges that do not belong to the original shape. */ | ||
CANDIDATE, | ||
/** Return this if if the query shape intersects an edge that does belong to the original shape. */ |
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.
update javadocs to say "crosses" instead of intersects?
double maxLat = StrictMath.max(StrictMath.max(ay, by), cy); | ||
double maxLon = StrictMath.max(StrictMath.max(ax, bx), cx); | ||
|
||
//disjoint then we return null |
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.
outdated?
* @param cx longitude of point c of the triangle | ||
* @param cy latitude of point c of the triangle | ||
* @param ca if edge ca belongs to the original shape | ||
* @return |
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.
let's either have it in the javadocs with a description or remove it?
|
||
if (minLat <= maxY && minLon <= maxX) { | ||
WithinRelation relation = internalWithinTriangle(ax, ay, ab, bx, by, bc, cx, cy, ca); | ||
if (relation != null) { |
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.
internalWithinTriangle never returns null?
|
||
return bboxWithinTriangle(ax, ay, ab, bx, by, bc, cx, cy, ca, minX, maxX, minY, maxY); | ||
} | ||
public EdgeTree.WithinRelation bboxWithinTriangle(int ax, int ay, boolean ab, int bx, int by, boolean bc, int cx, int cy, boolean ca, int minLon, int maxLon, int minLat, int maxLat) { |
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.
this can be made private?
if ((tMinX <= minLon && tMaxX >= maxLon && tMinY <= minLat && tMaxY >= maxLat) == false) { | ||
return EdgeTree.WithinRelation.DISJOINT; | ||
} | ||
//We check the min and max points, if true it is inside |
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.
we only check the min point?
int tMaxY = StrictMath.max(StrictMath.max(ay, by), cy); | ||
if ((tMinX <= minLon && tMaxX >= maxLon && tMinY <= minLat && tMaxY >= maxLat) == false) { | ||
return EdgeTree.WithinRelation.DISJOINT; | ||
} |
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.
we don't seem to need this as this is only called from withinTriangle which checks this for us?
double maxX = StrictMath.max(ax, StrictMath.max(bx, cx)); | ||
double maxY = StrictMath.max(ay, StrictMath.max(by, cy)); | ||
//check the bounding box because if the triangle is degenerated, e.g points and lines, we need to filter out | ||
//coplanar points that are not part of the triangle. |
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.
++
@@ -43,7 +44,7 @@ | |||
* Base LatLonShape Query class providing common query logic for | |||
* {@link LatLonShapeBoundingBoxQuery} and {@link LatLonShapePolygonQuery} | |||
* | |||
* Note: this class implements the majority of the INTERSECTS, WITHIN, DISJOINT relation logic | |||
* Note: this class implements the majority of the CROSSES, WITHIN, DISJOINT relation logic |
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.
bad search/replace? also add CONTAINS to the list?
IntersectVisitor visitor; | ||
IntersectVisitor disjointVisitor; | ||
if (queryRelation == QueryRelation.CONTAINS) { | ||
visitor = getDenseIntersectVisitor(within, disjoint, queryRelation); |
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 within
/disjoint
naming of the bitsets feels a bit weird now (my fault, sorry!). Maybe candidates
/rejected
or something like that instead?
I have decided to refractor the triangles method in EdgeTree. I think now they are much clear as the spatial logic has been moved to the subclasses. |
# Conflicts: # lucene/core/src/java/org/apache/lucene/geo/EdgeTree.java # lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java # lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java
# Conflicts: # lucene/core/src/java/org/apache/lucene/geo/EdgeTree.java # lucene/core/src/java/org/apache/lucene/geo/Polygon2D.java # lucene/sandbox/src/java/org/apache/lucene/geo/Line2D.java
This PR is a bit polluted so I have opened a new one (#608) and I close this. |
LatLonShape's implementation for spatial relationship CONTAINS.