[geos-commits] r2554 - in trunk: . build/msvc90/geos_lib capi source/algorithm source/geom source/headers/geos source/headers/geos/geom source/headers/geos/index/intervalrtree source/headers/geos/noding source/operation/buffer source/operation/distance source/util tests/unit/geom tests/unit/operation/distance

svn_geos at osgeo.org svn_geos at osgeo.org
Sat Jun 6 17:14:51 EDT 2009


Author: strk
Date: 2009-06-06 17:14:51 -0400 (Sat, 06 Jun 2009)
New Revision: 2554

Modified:
   trunk/build/msvc90/geos_lib/geos_lib.vcproj
   trunk/capi/geos_ts_c.cpp
   trunk/configure.in
   trunk/source/algorithm/InteriorPointLine.cpp
   trunk/source/algorithm/InteriorPointPoint.cpp
   trunk/source/algorithm/MinimumDiameter.cpp
   trunk/source/geom/Geometry.cpp
   trunk/source/geom/GeometryFactory.cpp
   trunk/source/geom/LineSegment.cpp
   trunk/source/headers/geos/geom/Coordinate.h
   trunk/source/headers/geos/geom/Coordinate.inl
   trunk/source/headers/geos/index/intervalrtree/IntervalRTreeNode.h
   trunk/source/headers/geos/noding/SingleInteriorIntersectionFinder.h
   trunk/source/headers/geos/platform.h.in
   trunk/source/headers/geos/platform.h.vc
   trunk/source/operation/buffer/RightmostEdgeFinder.cpp
   trunk/source/operation/distance/DistanceOp.cpp
   trunk/source/util/GeometricShapeFactory.cpp
   trunk/tests/unit/geom/CoordinateTest.cpp
   trunk/tests/unit/geom/TriangleTest.cpp
   trunk/tests/unit/operation/distance/DistanceOpTest.cpp
Log:
Use real NaNs rather than fake them. Applies patch in ticket #259. Adds autoconf checks for finite() and isfinite() and makes use of them for unix systems (platform.h)


Modified: trunk/build/msvc90/geos_lib/geos_lib.vcproj
===================================================================
--- trunk/build/msvc90/geos_lib/geos_lib.vcproj	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/build/msvc90/geos_lib/geos_lib.vcproj	2009-06-06 21:14:51 UTC (rev 2554)
@@ -21,7 +21,7 @@
 			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
 			IntermediateDirectory="$(ConfigurationName)\$(ProjectName)\"
 			ConfigurationType="4"
-			CharacterSet="2"
+			CharacterSet="1"
 			>
 			<Tool
 				Name="VCPreBuildEventTool"

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/capi/geos_ts_c.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -45,6 +45,7 @@
 #include <geos/operation/union/CascadedPolygonUnion.h>
 #include <geos/geom/BinaryOp.h>
 #include <geos/version.h> 
+#include <geos/platform.h>  // for FINITE
 
 // This should go away
 #include <cstddef>

Modified: trunk/configure.in
===================================================================
--- trunk/configure.in	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/configure.in	2009-06-06 21:14:51 UTC (rev 2554)
@@ -140,6 +140,35 @@
 CFLAGS="${CFLAGS} ${DEFAULTFLAGS}"
 
 dnl --------------------------------------------------------------------
+dnl - Look for finite and/or isfinite macros/functions
+dnl --------------------------------------------------------------------
+
+dnl These two tests need the math library or they won't link
+dnl on OpenBSD, even if the functions exist.
+save_LIBS=$LIBS
+LIBS="$LIBS -lm"
+AC_CACHE_CHECK([for finite], ac_cv_finite,
+ [AC_TRY_LINK([#include <math.h>],
+ [double x; int y; y = finite(x);],
+ ac_cv_finite=yes,
+ ac_cv_finite=no
+)])
+if test x"$ac_cv_finite" = x"yes"; then
+  AC_DEFINE(HAVE_FINITE, [1], [Has finite])
+fi
+
+AC_CACHE_CHECK([for isfinite], ac_cv_isfinite,
+ [AC_TRY_LINK([#include <math.h>],
+ [double x; int y; y = isfinite(x);],
+ ac_cv_isfinite=yes,
+ ac_cv_isfinite=no
+)])
+if test x"$ac_cv_isfinite" = x"yes"; then
+  AC_DEFINE(HAVE_ISFINITE, [1], [Has isfinite])
+fi
+LIBS=$save_LIBS
+
+dnl --------------------------------------------------------------------
 dnl - Look for a 64bit integer (do after CFLAGS is set)
 dnl --------------------------------------------------------------------
 

Modified: trunk/source/algorithm/InteriorPointLine.cpp
===================================================================
--- trunk/source/algorithm/InteriorPointLine.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/algorithm/InteriorPointLine.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -38,7 +38,7 @@
 
 InteriorPointLine::InteriorPointLine(const Geometry *g)
 {
-	minDistance=DoubleInfinity;
+	minDistance=DoubleMax;
 	hasInterior=false;
 	if ( g->getCentroid(centroid) )
 	{

Modified: trunk/source/algorithm/InteriorPointPoint.cpp
===================================================================
--- trunk/source/algorithm/InteriorPointPoint.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/algorithm/InteriorPointPoint.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -14,6 +14,7 @@
  *
  **********************************************************************/
 
+#include <geos/platform.h>
 #include <geos/algorithm/InteriorPointPoint.h>
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/Geometry.h>
@@ -33,7 +34,7 @@
 /*public*/
 InteriorPointPoint::InteriorPointPoint(const Geometry *g)
 {
-	minDistance=DoubleInfinity;
+	minDistance=DoubleMax;
 	if ( ! g->getCentroid(centroid) ) {
 		hasInterior=false;
 	} else {

Modified: trunk/source/algorithm/MinimumDiameter.cpp
===================================================================
--- trunk/source/algorithm/MinimumDiameter.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/algorithm/MinimumDiameter.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -220,7 +220,7 @@
 void
 MinimumDiameter::computeConvexRingMinDiameter(const CoordinateSequence* pts)
 {
-	minWidth=DoubleInfinity;
+	minWidth=DoubleMax;
 	unsigned int currMaxIndex=1;
 	LineSegment seg;
 

Modified: trunk/source/geom/Geometry.cpp
===================================================================
--- trunk/source/geom/Geometry.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/geom/Geometry.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -149,7 +149,7 @@
 {
 	size_t npts=list->getSize();
 	for (size_t i=0; i<npts; ++i) {
-		if (list->getAt(i)==Coordinate::getNull()) {
+		if (list->getAt(i).isNull()) {
 			return true;
 		}
 	}

Modified: trunk/source/geom/GeometryFactory.cpp
===================================================================
--- trunk/source/geom/GeometryFactory.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/geom/GeometryFactory.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -232,7 +232,7 @@
 Point*
 GeometryFactory::createPoint(const Coordinate& coordinate) const
 {
-	if (coordinate==Coordinate::getNull()) {
+	if (coordinate.isNull()) {
 		return createPoint();
 	} else {
 		CoordinateSequence *cl=coordinateListFactory->create(new vector<Coordinate>(1, coordinate));

Modified: trunk/source/geom/LineSegment.cpp
===================================================================
--- trunk/source/geom/LineSegment.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/geom/LineSegment.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -194,7 +194,7 @@
 	CoordinateSequence *closestPt=new CoordinateArraySequence(2);
 	//vector<Coordinate> *cv = new vector<Coordinate>(2);
 
-	double minDistance=DoubleInfinity;
+	double minDistance=DoubleMax;
 	double dist;
 
 	Coordinate close00;

Modified: trunk/source/headers/geos/geom/Coordinate.h
===================================================================
--- trunk/source/headers/geos/geom/Coordinate.h	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/headers/geos/geom/Coordinate.h	2009-06-06 21:14:51 UTC (rev 2554)
@@ -23,6 +23,7 @@
 #include <stack>
 #include <vector> // for typedefs
 #include <string>
+#include <limits>
 
 namespace geos {
 namespace geom { // geos.geom
@@ -84,6 +85,8 @@
 
 	static Coordinate& getNull();
 
+	bool isNull() const;
+
 	~Coordinate();
 
 	Coordinate(double xNew=0.0, double yNew=0.0, double zNew=DoubleNotANumber);

Modified: trunk/source/headers/geos/geom/Coordinate.inl
===================================================================
--- trunk/source/headers/geos/geom/Coordinate.inl	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/headers/geos/geom/Coordinate.inl	2009-06-06 21:14:51 UTC (rev 2554)
@@ -40,6 +40,12 @@
 	return nullCoord;
 }
 
+INLINE bool
+Coordinate::isNull() const
+{
+	return (ISNAN(x) && ISNAN(y) && ISNAN(z));
+}
+
 INLINE
 Coordinate::~Coordinate()
 {

Modified: trunk/source/headers/geos/index/intervalrtree/IntervalRTreeNode.h
===================================================================
--- trunk/source/headers/geos/index/intervalrtree/IntervalRTreeNode.h	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/headers/geos/index/intervalrtree/IntervalRTreeNode.h	2009-06-06 21:14:51 UTC (rev 2554)
@@ -17,6 +17,7 @@
 #ifndef GEOS_INDEX_INTERVALRTREE_INTERVALRTREENODE_H
 #define GEOS_INDEX_INTERVALRTREE_INTERVALRTREENODE_H
 
+#include <geos/platform.h>
 #include <vector>
 #include <limits>
 
@@ -51,8 +52,8 @@
 	typedef std::vector<const IntervalRTreeNode *> ConstVect;
 
 	IntervalRTreeNode()
-	:	min( std::numeric_limits<double>::min() ),
-		max( std::numeric_limits<double>::max() )
+	:	min( DoubleInfinity ),
+		max( DoubleNegInfinity )
 	{ }
 
 	IntervalRTreeNode( double min, double max)

Modified: trunk/source/headers/geos/noding/SingleInteriorIntersectionFinder.h
===================================================================
--- trunk/source/headers/geos/noding/SingleInteriorIntersectionFinder.h	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/headers/geos/noding/SingleInteriorIntersectionFinder.h	2009-06-06 21:14:51 UTC (rev 2554)
@@ -71,7 +71,7 @@
 	 */
 	bool hasIntersection() const
 	{ 
-		return interiorIntersection != geom::Coordinate::getNull(); 
+		return !interiorIntersection.isNull(); 
 	}
   
 	/** \brief
@@ -110,8 +110,7 @@
   
 	bool isDone() const
 	{ 
-		// TODO: add Coordinate::isNull()
-		return interiorIntersection != geom::Coordinate::getNull();
+		return !interiorIntersection.isNull();
 	}
 };
 

Modified: trunk/source/headers/geos/platform.h.in
===================================================================
--- trunk/source/headers/geos/platform.h.in	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/headers/geos/platform.h.in	2009-06-06 21:14:51 UTC (rev 2554)
@@ -13,6 +13,12 @@
 /* Set to 1 if you have ieeefp.h */
 #undef HAVE_IEEEFP_H
 
+/* Has finite */
+#undef HAVE_FINITE
+
+/* Has isfinite */
+#undef HAVE_ISFINITE
+
 #ifdef HAVE_IEEEFP_H
 extern "C"
 {
@@ -36,16 +42,36 @@
 #include <float.h>
 #endif
 
+#include <cmath> // for finite()/isfinite() and isnan()
+#include <limits> // for std::numeric_limits
 
+
+
 //Defines NaN for intel platforms
+#define DoubleNotANumber std::numeric_limits<double>::quiet_NaN()
+
 //Don't forget to define infinities
-#define DoubleNotANumber 1.7e-308
-#define DoubleInfinity 1.7e+308
-#define DoubleNegInfinity -1.7e+308
+#define DoubleInfinity std::numeric_limits<double>::infinity()
+#define DoubleNegInfinity -std::numeric_limits<double>::infinity()
 
-#define FINITE(x) ( (x) != DoubleNotANumber && (x) != DoubleInfinity && (x) != DoubleNegInfinity )
-#define ISNAN(x) ( (x) == DoubleNotANumber )
+#define DoubleMax std::numeric_limits<double>::max()
 
+inline bool
+isFinite(double d)
+{
+#if defined(HAVE_FINITE) && !defined(HAVE_ISFINITE)
+    return (finite(d));
+#else
+    // Put using namespace std; here if you have to
+    // put it anywhere.
+    using namespace std;
+    return (isfinite(d));
+#endif
+}
+#define FINITE(x) ( isFinite(x) ) 
+
+#define ISNAN(x) ( isnan(x) )
+
 #ifdef HAVE_INT64_T_64
   typedef int64_t int64;
 #else

Modified: trunk/source/headers/geos/platform.h.vc
===================================================================
--- trunk/source/headers/geos/platform.h.vc	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/headers/geos/platform.h.vc	2009-06-06 21:14:51 UTC (rev 2554)
@@ -39,14 +39,16 @@
 #endif
 
 //Defines NaN for intel platforms
-#define DoubleNotANumber 1.7e-308
+#define DoubleNotANumber std::numeric_limits<double>::quiet_NaN()
 
 #define ISNAN(x)  _isnan(x)
 
 //Don't forget to define infinities
-#define DoubleInfinity 1.7e+308
-#define DoubleNegInfinity -1.7e+308
+#define DoubleInfinity std::numeric_limits<double>::infinity()
+#define DoubleNegInfinity -std::numeric_limits<double>::infinity()
 
+#define DoubleMax std::numeric_limits<double>::max()
+
 #define FINITE(x) _finite(x)
 #define finite(x) _finite(x)
 

Modified: trunk/source/operation/buffer/RightmostEdgeFinder.cpp
===================================================================
--- trunk/source/operation/buffer/RightmostEdgeFinder.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/operation/buffer/RightmostEdgeFinder.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -202,7 +202,7 @@
      // of a non-horizontal segment
      // <FIX> MD 19 Sep 03 - NO!  we can test all vertices,
      // since the rightmost must have a non-horiz segment adjacent to it
-		if (minCoord==Coordinate::getNull() ||
+		if (minCoord.isNull() || 
 			coord->getAt(i).x > minCoord.x )
 		{
 			minDe = de;

Modified: trunk/source/operation/distance/DistanceOp.cpp
===================================================================
--- trunk/source/operation/distance/DistanceOp.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/operation/distance/DistanceOp.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -83,7 +83,7 @@
 	geom(2),
 	terminateDistance(0.0),
 	minDistanceLocation(0),
-	minDistance(DoubleInfinity)
+	minDistance(DoubleMax)
 {
 	geom[0] = g0;
 	geom[1] = g1;
@@ -93,7 +93,7 @@
 	geom(2),
 	terminateDistance(0.0),
 	minDistanceLocation(0),
-	minDistance(DoubleInfinity)
+	minDistance(DoubleMax)
 {
 	geom[0] = &g0;
 	geom[1] = &g1;
@@ -104,7 +104,7 @@
 	geom(2),
 	terminateDistance(tdist),
 	minDistanceLocation(0),
-	minDistance(DoubleInfinity)
+	minDistance(DoubleMax)
 {
 	geom[0] = &g0;
 	geom[1] = &g1;

Modified: trunk/source/util/GeometricShapeFactory.cpp
===================================================================
--- trunk/source/util/GeometricShapeFactory.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/source/util/GeometricShapeFactory.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -257,10 +257,10 @@
 Envelope*
 GeometricShapeFactory::Dimensions::getEnvelope()
 {
-	if (base!=Coordinate::getNull()) {
+	if (!base.isNull()) {
 		return new Envelope(base.x, base.x + width, base.y, base.y + height);
 	}
-	if (centre!=Coordinate::getNull()) {
+	if (!centre.isNull()) {
 		return new Envelope(centre.x - width/2, centre.x + width/2,centre.y - height/2, centre.y + height/2);
 	}
 	return new Envelope(0, width, 0, height);

Modified: trunk/tests/unit/geom/CoordinateTest.cpp
===================================================================
--- trunk/tests/unit/geom/CoordinateTest.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/tests/unit/geom/CoordinateTest.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -50,7 +50,7 @@
         geos::geom::Coordinate coord;
         ensure_equals( coord.x, 0.0 );
         ensure_equals( coord.y, 0.0 );
-        ensure_equals( coord.z, DoubleNotANumber );
+        ensure( ISNAN( coord.z ) );
     }
 
     // Test of copy constructor and assignment operator
@@ -172,16 +172,16 @@
 
         // Make it null and check
         not_null_coord.setNull();
-        ensure_equals( not_null_coord.x, DoubleNotANumber );
-        ensure_equals( not_null_coord.y, DoubleNotANumber );
-        ensure_equals( not_null_coord.z, DoubleNotANumber );
+        ensure( ISNAN( not_null_coord.x ) );
+        ensure( ISNAN( not_null_coord.y ) );
+        ensure( ISNAN( not_null_coord.z ) );
 
         // Build in static null instance
         geos::geom::Coordinate null_coord;
         null_coord = geos::geom::Coordinate::getNull();
-        ensure_equals( null_coord.x, DoubleNotANumber );
-        ensure_equals( null_coord.y, DoubleNotANumber );
-        ensure_equals( null_coord.z, DoubleNotANumber );
+        ensure( ISNAN( null_coord.x ) );
+        ensure( ISNAN( null_coord.y ) );
+        ensure( ISNAN( null_coord.z ) );
     }
 
 } // namespace tut

Modified: trunk/tests/unit/geom/TriangleTest.cpp
===================================================================
--- trunk/tests/unit/geom/TriangleTest.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/tests/unit/geom/TriangleTest.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -113,6 +113,6 @@
 		ensure( fabs(center.x - 6.0) < 1e-15 );
 		ensure( center.y > 4.2 );
 		ensure( center.y < 4.3 );
-		ensure_equals( center.z, DoubleNotANumber );
+		ensure( ISNAN( center.z ) );
     }
 } // namespace tut

Modified: trunk/tests/unit/operation/distance/DistanceOpTest.cpp
===================================================================
--- trunk/tests/unit/operation/distance/DistanceOpTest.cpp	2009-06-06 00:55:55 UTC (rev 2553)
+++ trunk/tests/unit/operation/distance/DistanceOpTest.cpp	2009-06-06 21:14:51 UTC (rev 2554)
@@ -218,7 +218,7 @@
 
 		DistanceOp dist(g0.get(), g1.get());
 
-		ensure_equals(dist.distance(), DoubleInfinity);
+		ensure_equals(dist.distance(), DoubleMax);
 
 		ensure_equals(dist.closestPoints(), (void*)0);
 	}
@@ -396,7 +396,7 @@
 
 		DistanceOp dist(g0.get(), g1.get());
 
-		ensure_equals(dist.distance(), DoubleInfinity);
+		ensure_equals(dist.distance(), DoubleMax);
 
         	ensure_equals(dist.closestPoints(), (void*)0);
 



More information about the geos-commits mailing list