--- dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/BoundingBox.java 2014/09/19 09:37:37 2221 +++ dao/FuldDaekningWorker/src/dk/daoas/fulddaekning/BoundingBox.java 2015/02/20 08:52:52 2330 @@ -15,10 +15,10 @@ //public static final double LONGUTUDE_MARGIN = 0.046875; public double latitudeMax; - public double latitudeMin; + public double latitudeMin = Double.MAX_VALUE; public double longitudeMax; - public double longitudeMin; + public double longitudeMin = Double.MAX_VALUE; @Override @@ -27,30 +27,47 @@ } public void validateBbox() throws BoundingBoxException { - - if ( Math.abs(latitudeMax-latitudeMin)> 1.0) - throw new BoundingBoxException("For stor latitude forskel"); + + double latDiff = Math.abs(latitudeMax - latitudeMin); + if ( latDiff > 1.1) { + throw new BoundingBoxException("For stor latitude forskel / " + latDiff); + } - if ( Math.abs(longitudeMax-longitudeMin)> 1.0) - throw new BoundingBoxException("For stor longitude forskel"); + double lngDiff = Math.abs(longitudeMax - longitudeMin); + if ( lngDiff > 1.1) { + throw new BoundingBoxException("For stor longitude forskel / " + lngDiff); + } GeoPoint min = new GeoPoint(latitudeMin, longitudeMin); GeoPoint max = new GeoPoint(latitudeMax, longitudeMax); double afstand = GeoPoint.beregnAfstand(min, max); - if (afstand >= 80.0) { //hvis cross afstand er over 80 km - så er postnummeret for stort + if (afstand >= 125.0) { //hvis cross afstand er over 80 km - så er postnummeret for stort throw new BoundingBoxException("For stor cross afstand " + afstand); } } - public void adjustToMargin() { - Constants consts = Constants.getInstance(); + public void adjustToMargin(double kmMargin) { + double latMargin = GeoPoint.kmToLatitude(kmMargin); + double lngMargin = GeoPoint.kmToLongitude(kmMargin); + + latitudeMax += latMargin; + latitudeMin -= latMargin; + + longitudeMax += lngMargin; + longitudeMin -= lngMargin; + } + + @Override + public BoundingBox clone() { + BoundingBox bb = new BoundingBox(); + bb.latitudeMax = this.latitudeMax; + bb.longitudeMax = this.longitudeMax; - latitudeMax += consts.getLatitudeMargin(); - latitudeMin -= consts.getLatitudeMargin(); + bb.latitudeMin = this.latitudeMin; + bb.longitudeMin = this.longitudeMin; - longitudeMax += consts.getLongitudeMargin(); - longitudeMin -= consts.getLongitudeMargin(); + return bb; }