nknize commented on a change in pull request #762: LUCENE-8903: Add LatLonShape 
point query
URL: https://github.com/apache/lucene-solr/pull/762#discussion_r301264563
 
 

 ##########
 File path: 
lucene/sandbox/src/java/org/apache/lucene/document/LatLonShapePointQuery.java
 ##########
 @@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.document;
+
+import java.util.Arrays;
+
+import org.apache.lucene.geo.GeoEncodingUtils;
+import org.apache.lucene.index.PointValues;
+import org.apache.lucene.index.PointValues.Relation;
+import org.apache.lucene.util.NumericUtils;
+
+import static java.lang.Integer.BYTES;
+import static org.apache.lucene.geo.GeoUtils.orient;
+
+/**
+ * Finds all previously indexed shapes that intersect the specified bounding 
box.
+ *
+ * <p>The field must be indexed using
+ * {@link LatLonShape#createIndexableFields} added per document.
+ *
+ *  @lucene.experimental
+ **/
+final class LatLonShapePointQuery extends LatLonShapeQuery {
+  final double lat;
+  final double lon;
+  final int latEnc;
+  final int lonEnc;
+  final byte[] point;
+
+  public LatLonShapePointQuery(String field, LatLonShape.QueryRelation 
queryRelation, double lat, double lon) {
+    super(field, queryRelation);
+    this.lat = lat;
+    this.lon = lon;
+    this.point = new byte[2 * LatLonShape.BYTES];
+    this.lonEnc = GeoEncodingUtils.encodeLongitude(lon);
+    this.latEnc = GeoEncodingUtils.encodeLatitude(lat);
+    NumericUtils.intToSortableBytes(latEnc, this.point, 0);
+    NumericUtils.intToSortableBytes(lonEnc, this.point, LatLonShape.BYTES);
+  }
+
+  @Override
+  protected Relation relateRangeBBoxToQuery(int minXOffset, int minYOffset, 
byte[] minTriangle,
+                                            int maxXOffset, int maxYOffset, 
byte[] maxTriangle) {
+    if (Arrays.compareUnsigned(minTriangle, minXOffset, minXOffset + BYTES, 
point,  BYTES, 2 * BYTES) > 0 ||
+        Arrays.compareUnsigned(maxTriangle, maxXOffset, maxXOffset + BYTES, 
point, BYTES, 2 * BYTES) < 0 ||
+        Arrays.compareUnsigned(minTriangle, minYOffset, minYOffset + BYTES, 
point, 0, BYTES) > 0 ||
+        Arrays.compareUnsigned(maxTriangle, maxYOffset, maxYOffset + BYTES, 
point, 0, BYTES) < 0) {
+      return PointValues.Relation.CELL_OUTSIDE_QUERY;
+    }
+    return PointValues.Relation.CELL_CROSSES_QUERY;
+  }
+
+  /** returns true if the query matches the encoded triangle */
+  @Override
+  protected boolean queryMatches(byte[] t, int[] scratchTriangle, 
LatLonShape.QueryRelation queryRelation) {
+
+    // decode indexed triangle
+    LatLonShape.decodeTriangle(t, scratchTriangle);
+
+    int aY = scratchTriangle[0];
+    int aX = scratchTriangle[1];
+    int bY = scratchTriangle[2];
+    int bX = scratchTriangle[3];
+    int cY = scratchTriangle[4];
+    int cX = scratchTriangle[5];
+
+    if (queryRelation == LatLonShape.QueryRelation.WITHIN) {
+       if (aY == bY && cY == aY && aX == bX && cX == aX) {
+         return lonEnc == aX && latEnc == aY;
+       }
+      return false;
+    }
+    return pointInTriangle(lonEnc, latEnc, aX, aY, bX, bY, cX, cY);
+  }
+
+  //This should be moved when LatLonShape is moved from sandbox!
+  /**
+   * Compute whether the given x, y point is in a triangle; uses the winding 
order method */
+  private static boolean pointInTriangle (double x, double y, double ax, 
double ay, double bx, double by, double cx, double cy) {
 
 Review comment:
   duplicate of? 
https://github.com/apache/lucene-solr/blob/ac209b637d68c84ce1402b6b8967514ce9cf6854/lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java#L795

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to