/** * Return true if the two bounding box are in overlaps relation. * i.e. the two box intersect but are not contained in each other. * * @param boundingBox1 An envelope. * @param boundingBox2 An envelope. * * @return True if the two envelope are overlaping. */ public static boolean overlaps(final GeneralEnvelope boundingBox1, final GeneralEnvelope boundingBox2) { if ((boundingBox1.contains(boundingBox2, true) || boundingBox2.contains(boundingBox1, true))) return false; if (boundingBox1.intersects(boundingBox2, true)) return true; return false; }
/** * Return the shortest distance between two bounding box. * if the two Bounding box intersect it return 0. * * @param boundingBox1 The first bounding box. * @param boundingBox2 The second bounding box. * @param units The units in which the distance will be expressed. * * @return The shortest distance between the bounding box and the line. */ public static double bboxToBBoxDistance(final GeneralEnvelope boundingBox1, final GeneralEnvelope boundingBox2, final String units) { if (boundingBox1.intersects(boundingBox2, false)) return 0; List<Line2D> border = getBorder(boundingBox1); double distance = Double.MAX_VALUE; for (Line2D l: border) { double tempDistance = lineToBBoxDistance(l, boundingBox2, units); if (tempDistance < distance) distance = tempDistance; } return distance; }
final Envelope penv1 = Envelopes.transform(env1, crs); final Envelope penv2 = Envelopes.transform(env2, crs); return GeneralEnvelope.castOrCopy(penv1).intersects(penv2); } catch(Exception ex) {/*do nothing*/} final Envelope penv2 = Envelopes.transform(env2, crs1); if (GeneralEnvelope.castOrCopy(penv2).isEmpty()) break cas1; return GeneralEnvelope.castOrCopy(env1).intersects(penv2); } catch(Exception ex) {/*do nothing*/} final Envelope penv1 = Envelopes.transform(env1, crs2); if (GeneralEnvelope.castOrCopy(penv1).isEmpty()) break cas2; return GeneralEnvelope.castOrCopy(penv1).intersects(env2); } catch(Exception ex) {/*do nothing*/}