package dk.daoas.adressevedligehold.afstandandenrute; import dk.daoas.adressevedligehold.beans.Address; public class BoundingBox implements Cloneable{ public static class BoundingBoxException extends Exception{ public BoundingBoxException(String reason) { super(reason); } private static final long serialVersionUID = 1L; } public double latitudeMax; public double latitudeMin = Double.MAX_VALUE; public double longitudeMax; public double longitudeMin = Double.MAX_VALUE; @Override public String toString() { return "bbox: Latitude=" + latitudeMin +"/" + latitudeMax + " longitude=" + longitudeMin + "/" + longitudeMax; } public void validateBbox() throws BoundingBoxException { double latDiff = Math.abs(latitudeMax - latitudeMin); if ( latDiff > 1.1) { throw new BoundingBoxException("For stor latitude forskel / " + latDiff); } double lngDiff = Math.abs(longitudeMax - longitudeMin); if ( lngDiff > 1.1) { throw new BoundingBoxException("For stor longitude forskel / " + lngDiff); } Address min = new Address(latitudeMin, longitudeMin); Address max = new Address(latitudeMax, longitudeMax); double afstand = GeoPointHelper.beregnAfstand(min, max); if (afstand >= 125.0) { //hvis cross afstand er over X km - så er postnummeret for stort throw new BoundingBoxException("For stor cross afstand " + afstand); } } @Override public BoundingBox clone() { BoundingBox bb = new BoundingBox(); bb.latitudeMax = this.latitudeMax; bb.longitudeMax = this.longitudeMax; bb.latitudeMin = this.latitudeMin; bb.longitudeMin = this.longitudeMin; return bb; } }