iverase commented on a change in pull request #726: LUCENE-8632: New XYShape Field and Queries for indexing and searching general cartesian geometries URL: https://github.com/apache/lucene-solr/pull/726#discussion_r298475736
########## File path: lucene/sandbox/src/java/org/apache/lucene/geo/Tessellator.java ########## @@ -119,17 +118,67 @@ private Tessellator() {} return result; } + + public static final List<Triangle> tessellate(final XYPolygon polygon) { + // Attempt to establish a doubly-linked list of the provided shell points (should be CCW, but this will correct); + // then filter instances of intersections. + Node outerNode = createDoublyLinkedList(polygon, 0, WindingOrder.CW); + // If an outer node hasn't been detected, the shape is malformed. (must comply with OGC SFA specification) + if(outerNode == null) { + throw new IllegalArgumentException("Malformed shape detected in Tessellator!"); + } + + // Determine if the specified list of points contains holes + if (polygon.numHoles() > 0) { + // Eliminate the hole triangulation. + outerNode = eliminateHoles(polygon, outerNode); + } + + // If the shape crosses VERTEX_THRESHOLD, use z-order curve hashing: + final boolean mortonOptimized; + { + int threshold = VERTEX_THRESHOLD - polygon.numPoints(); + for (int i = 0; threshold >= 0 && i < polygon.numHoles(); ++i) { + threshold -= polygon.getHole(i).numPoints(); + } + + // Link polygon nodes in Z-Order + mortonOptimized = threshold < 0; + if (mortonOptimized == true) { + sortByMorton(outerNode); + } + } + // Calculate the tessellation using the doubly LinkedList. + List<Triangle> result = earcutLinkedList(polygon, outerNode, new ArrayList<>(), State.INIT, mortonOptimized); + if (result.size() == 0) { + throw new IllegalArgumentException("Unable to Tessellate shape [" + polygon + "]. Possible malformed shape detected."); + } + + return result; + } + + private static final Node createDoublyLinkedList(XYPolygon polygon, int startIndex, final WindingOrder windingOrder) { Review comment: We can remove this method and make the tessellate method call directly the other one in either case (Polygon and XYPolygon) ---------------------------------------------------------------- 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