/** * Constructs an AbstractSTRtree with the specified maximum number of child * nodes that a node may have * * @param nodeCapacity the maximum number of child nodes in a node */ public AbstractSTRtree(int nodeCapacity) { Assert.isTrue(nodeCapacity > 1, "Node capacity must be greater than 1"); this.nodeCapacity = nodeCapacity; }
public Interval(double min, double max) { Assert.isTrue(min <= max); this.min = min; this.max = max; }
/** * Throws an <code>AssertionFailedException</code> if the given assertion is * not true. * *@param assertion a condition that is supposed to be true *@throws AssertionFailedException if the condition is false */ public static void isTrue(boolean assertion) { isTrue(assertion, null); }
/** * Adds either an AbstractNode, or if this is a leaf node, a data object * (wrapped in an ItemBoundable) */ public void addChildBoundable(Boundable childBoundable) { Assert.isTrue(bounds == null); childBoundables.add(childBoundable); } }
protected void insert(Object bounds, Object item) { Assert.isTrue(!built, "Cannot insert items into an STR packed R-tree after it has been built."); itemBoundables.add(new ItemBoundable(bounds, item)); }
protected void init(Coordinate p0, Coordinate p1) { this.p0 = p0; this.p1 = p1; dx = p1.x - p0.x; dy = p1.y - p0.y; quadrant = Quadrant.quadrant(dx, dy); Assert.isTrue(! (dx == 0 && dy == 0), "EdgeEnd with identical endpoints found"); }
private List createParentBoundablesFromVerticalSlices(List[] verticalSlices, int newLevel) { Assert.isTrue(verticalSlices.length > 0); List parentBoundables = new ArrayList(); for (int i = 0; i < verticalSlices.length; i++) { parentBoundables.addAll( createParentBoundablesFromVerticalSlice(verticalSlices[i], newLevel)); } return parentBoundables; }
/** * This function is non-robust, since it may compute the square of large numbers. * Currently not sure how to improve this. */ public static double nonRobustComputeEdgeDistance( Coordinate p, Coordinate p1, Coordinate p2) { double dx = p.x - p1.x; double dy = p.y - p1.y; double dist = Math.sqrt(dx * dx + dy * dy); // dummy value Assert.isTrue(! (dist == 0.0 && ! p.equals(p1)), "Invalid distance calculation"); return dist; }
private void computeSequence() { if (isRun) { return; } isRun = true; List sequences = findSequences(); if (sequences == null) return; sequencedGeometry = buildSequencedGeometry(sequences); isSequenceable = true; int finalLineCount = sequencedGeometry.getNumGeometries(); Assert.isTrue(lineCount == finalLineCount, "Lines were missing from result"); Assert.isTrue(sequencedGeometry instanceof LineString || sequencedGeometry instanceof MultiLineString, "Result is not lineal"); }
/** * Creates the parent level for the given child level. First, orders the items * by the x-values of the midpoints, and groups them into vertical slices. * For each slice, orders the items by the y-values of the midpoints, and * group them into runs of size M (the node capacity). For each run, creates * a new (parent) node. */ protected List createParentBoundables(List childBoundables, int newLevel) { Assert.isTrue(!childBoundables.isEmpty()); int minLeafCount = (int) Math.ceil((childBoundables.size() / (double) getNodeCapacity())); ArrayList sortedChildBoundables = new ArrayList(childBoundables); Collections.sort(sortedChildBoundables, xComparator); List[] verticalSlices = verticalSlices(sortedChildBoundables, (int) Math.ceil(Math.sqrt(minLeafCount))); return createParentBoundablesFromVerticalSlices(verticalSlices, newLevel); }
/** * 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); }
protected void visitLinkedDirectedEdges(DirectedEdge start) { DirectedEdge startDe = start; DirectedEdge de = start; do { Assert.isTrue(de != null, "found null Directed Edge"); de.setVisited(true); de = de.getNext(); } while (de != startDe); }
/** * Update the IM with the contribution for this component. * A component only contributes if it has a labelling for both parent geometries */ public void updateIM(IntersectionMatrix im) { Assert.isTrue(label.getGeometryCount() >= 2, "found partial label"); computeIM(im); }
private void buildEdgeStringsForUnprocessedNodes() { for (Iterator i = graph.getNodes().iterator(); i.hasNext(); ) { Node node = (Node) i.next(); if (!node.isMarked()) { Assert.isTrue(node.getDegree() == 2); buildEdgeStringsStartingAt(node); node.setMarked(true); } } } private void buildEdgeStringsForNonDegree2Nodes() {
private EdgeRing findEdgeRing(PolygonizeDirectedEdge startDE) { PolygonizeDirectedEdge de = startDE; EdgeRing er = new EdgeRing(factory); do { er.add(de); de.setRing(er); de = de.getNext(); Assert.isTrue(de != null, "found null DE in ring"); Assert.isTrue(de == startDE || ! de.isInRing(), "found DE already in ring"); } while (de != startDE); return er; }
private void init(CoordinateSequence coordinates) { if (coordinates == null) { coordinates = getFactory().getCoordinateSequenceFactory().create(new Coordinate[]{}); } Assert.isTrue(coordinates.size() <= 1); this.coordinates = coordinates; }
void insert(Node node) { Assert.isTrue(interval == null || interval.contains(node.interval)); int index = getSubnodeIndex(node.interval, centre); if (node.level == level - 1) { subnode[index] = node; } else { // the node is not a direct child, so make a new child node to contain it // and recursively insert the node Node childNode = createSubnode(index); childNode.insert(node); subnode[index] = childNode; } }
/** * Removes an item from the tree. * (Builds the tree, if necessary.) */ protected boolean remove(Object searchBounds, Object item) { build(); if (itemBoundables.isEmpty()) { Assert.isTrue(root.getBounds() == null); } if (getIntersectsOp().intersects(root.getBounds(), searchBounds)) { return remove(searchBounds, root, item); } return false; }
/** * Returns the directed edge that starts at this directed edge's end point, or null * if there are zero or multiple directed edges starting there. * @return the directed edge */ public LineMergeDirectedEdge getNext() { if (getToNode().getDegree() != 2) { return null; } if (getToNode().getOutEdges().getEdges().get(0) == getSym()) { return (LineMergeDirectedEdge) getToNode().getOutEdges().getEdges().get(1); } Assert.isTrue(getToNode().getOutEdges().getEdges().get(1) == getSym()); return (LineMergeDirectedEdge) getToNode().getOutEdges().getEdges().get(0); } }
private boolean isInside(LinearRing innerRing, LinearRing searchRing) { Coordinate[] innerRingPts = innerRing.getCoordinates(); Coordinate[] searchRingPts = searchRing.getCoordinates(); if (! innerRing.getEnvelopeInternal().intersects(searchRing.getEnvelopeInternal())) return false; Coordinate innerRingPt = IsValidOp.findPtNotNode(innerRingPts, searchRing, graph); Assert.isTrue(innerRingPt != null, "Unable to find a ring point not a node of the search ring"); boolean isInside = CGAlgorithms.isPointInRing(innerRingPt, searchRingPts); if (isInside) { nestedPt = innerRingPt; return true; } return false; }