/** * Creates the levels higher than the given level * * @param boundablesOfALevel the level to build on * @param level the level of the Boundables, or -1 if the boundables are item boundables (that is, * below level 0) * @return the root, which may be a ParentNode or a LeafNode */ private AbstractNode createHigherLevels(List boundablesOfALevel, int level) { Assert.isTrue(!boundablesOfALevel.isEmpty()); List parentBoundables = createParentBoundables(boundablesOfALevel, level + 1); if (parentBoundables.size() == 1) { return (AbstractNode) parentBoundables.get(0); } return createHigherLevels(parentBoundables, level + 1); }
public Geometry buffer(Geometry g, double distance) { PrecisionModel precisionModel = workingPrecisionModel; if (precisionModel == null) precisionModel = g.getPrecisionModel(); // factory must be the same as the one used by the input geomFact = g.getFactory(); OffsetCurveBuilder curveBuilder = new OffsetCurveBuilder(precisionModel, bufParams); OffsetCurveSetBuilder curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder); List bufferSegStrList = curveSetBuilder.getCurves(); // short-circuit test if (bufferSegStrList.size() <= 0) { return createEmptyResultGeometry(); } // BufferDebug.runCount++; // String filename = "run" + BufferDebug.runCount + "_curves"; // System.out.println("saving " + filename); // BufferDebug.saveEdges(bufferEdgeList, filename); // DEBUGGING ONLY // WKTWriter wktWriter = new WKTWriter(); // Debug.println("Rings: " + wktWriter.write(convertSegStrings(bufferSegStrList.iterator()))); // wktWriter.setMaxCoordinatesPerLine(10); // System.out.println(wktWriter.writeFormatted(convertSegStrings(bufferSegStrList.iterator()))); computeNodedEdges(bufferSegStrList, precisionModel); graph = new PlanarGraph(new OverlayNodeFactory()); graph.addEdges(edgeList.getEdges()); List subgraphList = createSubgraphs(graph); PolygonBuilder polyBuilder = new PolygonBuilder(geomFact); buildSubgraphs(subgraphList, polyBuilder); List resultPolyList = polyBuilder.getPolygons(); // just in case... if (resultPolyList.size() <= 0) { return createEmptyResultGeometry(); } Geometry resultGeom = geomFact.buildGeometry(resultPolyList); return resultGeom; }
private void query(Object searchBounds, AbstractNode node, ItemVisitor visitor) { List childBoundables = node.getChildBoundables(); for (int i = 0; i < childBoundables.size(); i++) { Boundable childBoundable = (Boundable) childBoundables.get(i); if (!getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds)) { continue; } if (childBoundable instanceof AbstractNode) { query(searchBounds, (AbstractNode) childBoundable, visitor); } else if (childBoundable instanceof ItemBoundable) { visitor.visitItem(((ItemBoundable) childBoundable).getItem()); } else { Assert.shouldNeverReachHere(); } } }
private List itemsTree(AbstractNode node) { List valuesTreeForNode = new ArrayList(); for (Iterator i = node.getChildBoundables().iterator(); i.hasNext(); ) { Boundable childBoundable = (Boundable) i.next(); if (childBoundable instanceof AbstractNode) { List valuesTreeForChild = itemsTree((AbstractNode) childBoundable); // only add if not null (which indicates an item somewhere in this tree if (valuesTreeForChild != null) valuesTreeForNode.add(valuesTreeForChild); } else if (childBoundable instanceof ItemBoundable) { valuesTreeForNode.add(((ItemBoundable) childBoundable).getItem()); } else { Assert.shouldNeverReachHere(); } } if (valuesTreeForNode.size() <= 0) return null; return valuesTreeForNode; }
protected AbstractNode lastNode(List nodes) { return (AbstractNode) nodes.get(nodes.size() - 1); }