You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/02/14 09:08:24 UTC

[GitHub] [lucene-solr] jpountz commented on a change in pull request #587: LUCENE-8707: Add LatLonShape and XYShape distance query

jpountz commented on a change in pull request #587: LUCENE-8707: Add LatLonShape and XYShape distance query
URL: https://github.com/apache/lucene-solr/pull/587#discussion_r379317415
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/geo/Circle2D.java
 ##########
 @@ -0,0 +1,463 @@
+/*
+ * 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.geo;
+
+import org.apache.lucene.index.PointValues.Relation;
+import org.apache.lucene.util.SloppyMath;
+
+/**
+ * 2D circle implementation containing spatial logic.
+ */
+class Circle2D implements Component2D {
+
+  private final DistanceCalculator calculator;
+
+  private Circle2D(DistanceCalculator calculator) {
+    this.calculator = calculator;
+  }
+
+  @Override
+  public double getMinX() {
+    return calculator.getMinX();
+  }
+
+  @Override
+  public double getMaxX() {
+    return calculator.getMaxX();
+  }
+
+  @Override
+  public double getMinY() {
+    return calculator.getMinY();
+  }
+
+  @Override
+  public double getMaxY() {
+    return calculator.getMaxY();
+  }
+
+  @Override
+  public boolean contains(double x, double y) {
+    return calculator.contains(x, y);
+  }
+
+  @Override
+  public Relation relate(double minX, double maxX, double minY, double maxY) {
+    if (calculator.disjoint(minX, maxX, minY, maxY)) {
+      return Relation.CELL_OUTSIDE_QUERY;
+    }
+    if (calculator.within(minX, maxX, minY, maxY)) {
+      return Relation.CELL_CROSSES_QUERY;
+    }
+    return calculator.relate(minX, maxX, minY, maxY);
+  }
+
+  @Override
+  public Relation relateTriangle(double minX, double maxX, double minY, double maxY,
+                                 double ax, double ay, double bx, double by, double cx, double cy) {
+    if (calculator.disjoint(minX, maxX, minY, maxY)) {
+      return Relation.CELL_OUTSIDE_QUERY;
+    }
+    if (ax == bx && bx == cx && ay == by && by == cy) {
+      // indexed "triangle" is a point: shortcut by checking contains
+      return contains(ax, ay) ? Relation.CELL_INSIDE_QUERY : Relation.CELL_OUTSIDE_QUERY;
+    } else if (ax == cx && ay == cy) {
+      // indexed "triangle" is a line segment: shortcut by calling appropriate method
+      return relateIndexedLineSegment(ax, ay, bx, by);
+    } else if (ax == bx && ay == by) {
+      // indexed "triangle" is a line segment: shortcut by calling appropriate method
+      return relateIndexedLineSegment(bx, by, cx, cy);
+    } else if (bx == cx && by == cy) {
+      // indexed "triangle" is a line segment: shortcut by calling appropriate method
+      return relateIndexedLineSegment(cx, cy, ax, ay);
+    }
+    // indexed "triangle" is a triangle:
+    return relateIndexedTriangle(minX, maxX, minY, maxY, ax, ay, bx, by, cx, cy);
+  }
+
+  @Override
+  public WithinRelation withinTriangle(double minX, double maxX, double minY, double maxY,
+                                       double ax, double ay, boolean ab, double bx, double by, boolean bc, double cx, double cy, boolean ca) {
+    // short cut, lines and points cannot contain this type of shape
+    if ((ax == bx && ay == by) || (ax == cx && ay == cy) || (bx == cx && by == cy)) {
+      return WithinRelation.DISJOINT;
 
 Review comment:
   couldn't it be NOTWITHIN in some cases?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

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