@Override public boolean evaluate(Shape indexedShape, Shape queryShape) { return ! indexedShape.relate(queryShape).intersects(); } };
@Override public boolean evaluate(Shape indexedShape, Shape queryShape) { return indexedShape.relate(queryShape).intersects(); } };
/** * Computes whether the shapes are mutually disjoint. This is a utility method * offered for use by a subclass implementing {@link #relateContainsShortCircuits()}. * <b>Beware: this is an O(N^2) algorithm.</b>. Consequently, consider safely * assuming non-disjoint if shapes.size() > 10 or something. And if all shapes * are a Point then the result of this method doesn't ultimately matter. */ protected static boolean computeMutualDisjoint(List<? extends Shape> shapes) { //WARNING: this is an O(n^2) algorithm. //loop through each shape and see if it intersects any shape before it for (int i = 1; i < shapes.size(); i++) { Shape shapeI = shapes.get(i); for (int j = 0; j < i; j++) { Shape shapeJ = shapes.get(j); if (shapeJ.relate(shapeI).intersects()) return false; } } return true; }
@Override public boolean evaluate(Shape indexedShape, Shape queryShape) { return indexedShape.getBoundingBox().relate(queryShape).intersects(); } };
public SpatialRelation relate(Point pt) { if (!getBoundingBox().relate(pt).intersects()) return SpatialRelation.DISJOINT; Geometry ptGeom; if (pt instanceof JtsPoint) ptGeom = ((JtsPoint)pt).getGeom(); else ptGeom = ctx.getGeometryFactory().createPoint(new Coordinate(pt.getX(), pt.getY())); return relate(ptGeom);//is point-optimized }
if (cornersIntersect == 4) {//all double backX = frontX <= 0 ? frontX + 180 : frontX - 180; if (r.relateXRange(backX, backX).intersects()) return SpatialRelation.INTERSECTS; else return SpatialRelation.CONTAINS; } else if (cornersIntersect == 0) {//none if (r.relateXRange(frontX, frontX).intersects()) return SpatialRelation.INTERSECTS; else
if ( r.relateYRange(getYAxis(), getYAxis()).intersects() // at y vertical && r.relateXRange(enclosingBox.getMinX(), enclosingBox.getMaxX()).intersects() ) return SpatialRelation.INTERSECTS; if (r.relateXRange(getXAxis(), getXAxis()).intersects()) { // at x horizontal double yTop = getCenter().getY()+ radiusDEG; assert yTop <= 90; double yBot = getCenter().getY()- radiusDEG; assert yBot >= -90; if (r.relateYRange(yBot, yTop).intersects())//back bottom return SpatialRelation.INTERSECTS;
@Override public boolean evaluate(Shape indexedShape, Shape queryShape) { return indexedShape.relate(queryShape).intersects(); } };
@Override public boolean evaluate(Shape indexedShape, Shape queryShape) { return ! indexedShape.relate(queryShape).intersects(); } };
@Override public boolean evaluate(Shape indexedShape, Shape queryShape) { return indexedShape.getBoundingBox().relate(queryShape).intersects(); } };
@Override public boolean hasNext() { thisCell = null; if (nextCell != null)//calling hasNext twice in a row return true; while (baseIter.hasNext()) { nextCell = baseIter.next(); if (shapeFilter == null) { return true; } else { SpatialRelation rel = nextCell.getShape().relate(shapeFilter); if (rel.intersects()) { nextCell.setShapeRel(rel); if (rel == SpatialRelation.WITHIN) nextCell.setLeaf(); return true; } } } return false; }
@Override protected boolean visitPrefix(Cell cell) throws IOException { //cell.relate is based on the bufferedQueryShape; we need to examine what // the relation is against the queryShape SpatialRelation visitRelation = cell.getShape().relate(queryShape); if (cell.getLevel() == detailLevel) { collectDocs(visitRelation.intersects() ? inside : outside); return false; } else if (visitRelation == SpatialRelation.WITHIN) { collectDocs(inside); return false; } else if (visitRelation == SpatialRelation.DISJOINT) { collectDocs(outside); return false; } return true; }
/** * The cell is either indexed as a leaf or is the last level of detail. It * might not even intersect the query shape, so be sure to check for that. * The default implementation will check that and if passes then call * {@link #visitLeaf(org.apache.lucene.spatial.prefix.tree.Cell)} or * {@link #visitPrefix(org.apache.lucene.spatial.prefix.tree.Cell)}. */ protected void visitScanned(Cell cell) throws IOException { final SpatialRelation relate = cell.getShape().relate(queryShape); if (relate.intersects()) { cell.setShapeRel(relate);//just being pedantic if (cell.isLeaf()) { visitLeaf(cell); } else { visitPrefix(cell); } } }
/** Returns true if the provided cell, and all its sub-cells down to * detailLevel all intersect the queryShape. */ private boolean allCellsIntersectQuery(Cell cell) { SpatialRelation relate = cell.getShape().relate(queryShape); if (cell.getLevel() == detailLevel) return relate.intersects(); if (relate == SpatialRelation.WITHIN) return true; if (relate == SpatialRelation.DISJOINT) return false; // Note: Generating all these cells just to determine intersection is not ideal. // The real solution is LUCENE-4869. CellIterator subCells = cell.getNextLevelCells(null); while (subCells.hasNext()) { Cell subCell = subCells.next(); if (!allCellsIntersectQuery(subCell))//recursion return false; } return true; }
queryRatio = width / queryExtent.getWidth(); } else { queryRatio = queryExtent.relate(target).intersects() ? 1 : 0;//could be optimized targetRatio = width / target.getWidth(); } else { targetRatio = target.relate(queryExtent).intersects() ? 1 : 0;//could be optimized