nknize commented on a change in pull request #771: LUCENE-8620: Update 
Tessellator logic to label if triangle edges belongs to the original polygon
URL: https://github.com/apache/lucene-solr/pull/771#discussion_r321718423
 
 

 ##########
 File path: lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java
 ##########
 @@ -590,14 +601,123 @@ private static final boolean splitEarcut(Object 
polygon, final Node start, final
     return false;
   }
 
+  /** Computes if edge defined by a and b overlaps with a polygon edge **/
+  private static boolean edgeFromPolygon(final Node a, final Node b, final 
boolean isMorton) {
+    if (isMorton) {
+      return mortonEdgeFromPolygon(a, b);
+    }
+    Node next = a;
+    do {
+      if (pointInLine(next, next.next, a) && pointInLine(next, next.next, b)) {
+        return next.nextEdgeFromPolygon;
+      }
+      if (pointInLine(next, next.previous, a) && pointInLine(next, 
next.previous, b)) {
+        return next.previous.nextEdgeFromPolygon;
+      }
+      next = next.next;
+    } while(next != a);
+    return false;
+  }
+
+  /** Uses morton code for speed to determine whether or not and edge defined 
by a and b overlaps with a polygon edge */
+  private static final boolean mortonEdgeFromPolygon(final Node a, final Node 
b) {
+    // edge bbox (flip the bits so negative encoded values are < positive 
encoded values)
+    final int minTX = StrictMath.min(a.x, b.x) ^ 0x80000000;
+    final int minTY = StrictMath.min(a.y, b.y) ^ 0x80000000;
+    final int maxTX = StrictMath.max(a.x, b.x) ^ 0x80000000;
+    final int maxTY = StrictMath.max(a.y, b.y) ^ 0x80000000;
+
+    // z-order range for the current edge;
+    final long minZ = BitUtil.interleave(minTX, minTY);
+    final long maxZ = BitUtil.interleave(maxTX, maxTY);
+
+    // now make sure we don't have other points inside the potential ear;
+
+    // look for points inside edge in both directions
+    Node p = a.previousZ;
+    Node n = a.nextZ;
+    while (p != null && Long.compareUnsigned(p.morton, minZ) >= 0
+        && n != null && Long.compareUnsigned(n.morton, maxZ) <= 0) {
+      if (pointInLine(p, p.next, a) && pointInLine(p, p.next, b)) {
+        return p.nextEdgeFromPolygon;
+      }
+      if (pointInLine(p, p.previous, a) && pointInLine(p, p.previous, b)) {
+        return p.previous.nextEdgeFromPolygon;
+      }
+
+      p = p.previousZ;
+
+      if (pointInLine(n, n.next, a) && pointInLine(n, n.next, b)) {
+        return n.nextEdgeFromPolygon;
+      }
+      if (pointInLine(n, n.previous, a) && pointInLine(n, n.previous, b)) {
+        return n.previous.nextEdgeFromPolygon;
+      }
+
+      n = n.nextZ;
+    }
+
+    // first look for points inside the edge in decreasing z-order
+    while (p != null && Long.compareUnsigned(p.morton, minZ) >= 0) {
+      if (pointInLine(p, p.next, a) && pointInLine(p, p.next, b)) {
+        return p.nextEdgeFromPolygon;
+      }
+      if (pointInLine(p, p.previous, a) && pointInLine(p, p.previous, b)) {
+        return p.previous.nextEdgeFromPolygon;
+      }
+      p = p.previousZ;
+    }
+    // then look for points in increasing z-order
+    while (n != null &&
+        Long.compareUnsigned(n.morton, maxZ) <= 0) {
+      if (pointInLine(n, n.next, a) && pointInLine(n, n.next, b)) {
+        return n.nextEdgeFromPolygon;
+      }
+      if (pointInLine(n, n.previous, a) && pointInLine(n, n.previous, b)) {
+        return n.previous.nextEdgeFromPolygon;
+      }
+      n = n.nextZ;
+    }
+    return false;
+  }
+
+  private static boolean pointInLine(final Node a, final Node b, final Node 
point) {
 
 Review comment:
   ```suggestion
     private static boolean isPointInLine(final Node a, final Node b, final 
Node point) {
   ```

----------------------------------------------------------------
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: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to