[Schmitzm-commits] r679 - branches/2.0-RC1/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Feb 5 16:25:28 CET 2010


Author: alfonx
Date: 2010-02-05 16:25:25 +0100 (Fri, 05 Feb 2010)
New Revision: 679

Modified:
   branches/2.0-RC1/src/skrueger/geotools/XMapPane.java
Log:
backported a bug that could leed to an infinite loop when finding the best map extend due to double precision problems


Modified: branches/2.0-RC1/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/2.0-RC1/src/skrueger/geotools/XMapPane.java	2010-02-05 15:21:33 UTC (rev 678)
+++ branches/2.0-RC1/src/skrueger/geotools/XMapPane.java	2010-02-05 15:25:25 UTC (rev 679)
@@ -805,16 +805,23 @@
 
 		final Envelope maxAllowedExtend = getMaxExtend();
 
+		// This variable is used to break the loop if it runs forever...
+		Envelope lastCalculatedArea = null;
+		/*
+		 * If a maxAllowedExtend is set, we have to honour that...
+		 */
 		while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea)
 				&& newArea != null && !newArea.isNull()
 				&& !Double.isNaN(newArea.getMinX())
 				&& !Double.isNaN(newArea.getMaxX())
 				&& !Double.isNaN(newArea.getMinY())
 				&& !Double.isNaN(newArea.getMaxY())) {
-			/*
-			 * If a maxExtend is set, we have to honour that...
-			 */
-
+			
+			if (newArea.equals(lastCalculatedArea))
+				break;
+			// Check that we are not iterating for ever due to double precision rounding errors
+			lastCalculatedArea = newArea;
+			
 			// Exceeds top? Move down and maybe cut
 			if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) {
 				final double divY = newArea.getMaxY()



More information about the Schmitzm-commits mailing list