[geos-commits] r2832 - in trunk/source: geom headers/geos/geom

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Dec 15 09:44:44 EST 2009


Author: mloskot
Date: 2009-12-15 09:44:43 -0500 (Tue, 15 Dec 2009)
New Revision: 2832

Modified:
   trunk/source/geom/PrecisionModel.cpp
   trunk/source/headers/geos/geom/PrecisionModel.h
   trunk/source/headers/geos/geom/PrecisionModel.inl
Log:
* Assert precision model scale must never be negative
* Replaced use of operator== against float-point number with operator<=
* Typos

Modified: trunk/source/geom/PrecisionModel.cpp
===================================================================
--- trunk/source/geom/PrecisionModel.cpp	2009-12-15 14:38:37 UTC (rev 2831)
+++ trunk/source/geom/PrecisionModel.cpp	2009-12-15 14:44:43 UTC (rev 2832)
@@ -48,20 +48,20 @@
 PrecisionModel::makePrecise(double val) const
 {
 #if GEOS_DEBUG
-	cerr<<"PrecisionModel["<<this<<"]::makePrecise called"<<endl;
+    cerr<<"PrecisionModel["<<this<<"]::makePrecise called"<<endl;
 #endif
 
-	if (modelType==FLOATING_SINGLE) {
-		float floatSingleVal = (float) val;
-		return (double) floatSingleVal;
-	}
-	if (modelType == FIXED) {
-		// Use whatever happens to be the default rounding method
-		double ret = util::round(val*scale)/scale;
-		return ret;
-	}
-	// modelType == FLOATING - no rounding necessary
-	return val;
+    if (modelType==FLOATING_SINGLE) {
+        float floatSingleVal = static_cast<float>(val);
+        return static_cast<double>(floatSingleVal);
+    }
+    if (modelType == FIXED) {
+        // Use whatever happens to be the default rounding method
+        const double ret = util::round(val*scale)/scale;
+        return ret;
+    }
+    // modelType == FLOATING - no rounding necessary
+    return val;
 }
 
 /*public*/
@@ -161,7 +161,8 @@
 	} else if (modelType == FLOATING_SINGLE) {
 		maxSigDigits = 6;
 	} else if (modelType == FIXED) {
-		maxSigDigits = 1 + (int)ceil((double)log(getScale())/(double)log(10.0));
+        const int dgts = static_cast<int>(std::ceil(std::log(getScale()) / std::log(double(10.0))));
+        maxSigDigits = 1 + dgts;
 	}
 	return maxSigDigits;
 }
@@ -172,9 +173,9 @@
 PrecisionModel::setScale(double newScale)
 		// throw IllegalArgumentException
 {
-	if ( newScale == 0 )
+	if ( newScale <= 0 )
 		throw util::IllegalArgumentException("PrecisionModel scale cannot be 0"); 
-	scale=fabs(newScale);
+    scale = std::fabs(newScale);
 }
 
 /*public*/

Modified: trunk/source/headers/geos/geom/PrecisionModel.h
===================================================================
--- trunk/source/headers/geos/geom/PrecisionModel.h	2009-12-15 14:38:37 UTC (rev 2831)
+++ trunk/source/headers/geos/geom/PrecisionModel.h	2009-12-15 14:44:43 UTC (rev 2832)
@@ -70,8 +70,8 @@
  *   The scale factor specifies the grid which numbers are rounded to.
  *   Input coordinates are mapped to fixed coordinates according to the
  *   following equations:
- *   - jtsPt.x = round( (inputPt.x * scale ) / scale
- *   - jtsPt.y = round( (inputPt.y * scale ) / scale
+ *   - jtsPt.x = round( inputPt.x * scale ) / scale
+ *   - jtsPt.y = round( inputPt.y * scale ) / scale
  *
  * Coordinates are represented internally as Java double-precision values.
  * Since Java uses the IEEE-394 floating point standard, this

Modified: trunk/source/headers/geos/geom/PrecisionModel.inl
===================================================================
--- trunk/source/headers/geos/geom/PrecisionModel.inl	2009-12-15 14:38:37 UTC (rev 2831)
+++ trunk/source/headers/geos/geom/PrecisionModel.inl	2009-12-15 14:44:43 UTC (rev 2832)
@@ -52,7 +52,8 @@
 INLINE double
 PrecisionModel::getScale() const
 {
-	return scale;
+    assert(!(scale < 0));
+    return scale;
 }
 
 



More information about the geos-commits mailing list