/** Determines if two point vertices are equal. **/ private static final boolean isVertexEquals(final Node a, final Node b) { return isVertexEquals(a, b.getX(), b.getY()); }
/** Determines if the diagonal of a polygon is intersecting with any polygon elements. **/ private static final boolean isIntersectingPolygon(final Node start, final double x0, final double y0, final double x1, final double y1) { Node node = start; Node nextNode; do { nextNode = node.next; if(isVertexEquals(node, x0, y0) == false && isVertexEquals(node, x1, y1) == false) { if (linesIntersect(node.getX(), node.getY(), nextNode.getX(), nextNode.getY(), x0, y0, x1, y1)) { return true; } } node = nextNode; } while (node != start); return false; }
/** Creates a circular doubly linked list using polygon points. The order is governed by the specified winding order */ private static final Node createDoublyLinkedList(final Polygon polygon, int startIndex, final WindingOrder windingOrder) { Node lastNode = null; // Link points into the circular doubly-linked list in the specified winding order if (windingOrder == polygon.getWindingOrder()) { for (int i = 0; i < polygon.numPoints(); ++i) { lastNode = insertNode(polygon, startIndex++, i, lastNode); } } else { for (int i = polygon.numPoints() - 1; i >= 0; --i) { lastNode = insertNode(polygon, startIndex++, i, lastNode); } } // if first and last node are the same then remove the end node and set lastNode to the start if (lastNode != null && isVertexEquals(lastNode, lastNode.next)) { removeNode(lastNode); lastNode = lastNode.next; } // Return the last node in the Doubly-Linked List return filterPoints(lastNode, null); }
nextNode = node.next; prevNode = node.previous; if (node.isSteiner == false && isVertexEquals(node, nextNode) || area(prevNode.getX(), prevNode.getY(), node.getX(), node.getY(), nextNode.getX(), nextNode.getY()) == 0) {
/** Iterate through all polygon nodes and remove small local self-intersections **/ private static final Node cureLocalIntersections(Node startNode, final List<Triangle> tessellation) { Node node = startNode; Node nextNode; do { nextNode = node.next; Node a = node.previous; Node b = nextNode.next; // a self-intersection where edge (v[i-1],v[i]) intersects (v[i+1],v[i+2]) if (isVertexEquals(a, b) == false && isIntersectingPolygon(a, a.getX(), a.getY(), b.getX(), b.getY()) == false && linesIntersect(a.getX(), a.getY(), node.getX(), node.getY(), nextNode.getX(), nextNode.getY(), b.getX(), b.getY()) && isLocallyInside(a, b) && isLocallyInside(b, a)) { // Return the triangulated vertices to the tessellation tessellation.add(new Triangle(a, node, b)); // remove two nodes involved removeNode(node); removeNode(node.next); node = startNode = b; } node = node.next; } while (node != startNode); return node; }