[geos-commits] r2629 - in trunk/tests/xmltester: . tests

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Sep 28 03:02:03 EDT 2009


Author: strk
Date: 2009-09-28 03:02:02 -0400 (Mon, 28 Sep 2009)
New Revision: 2629

Added:
   trunk/tests/xmltester/SingleSidedBufferResultMatcher.cpp
   trunk/tests/xmltester/SingleSidedBufferResultMatcher.h
   trunk/tests/xmltester/tests/singlesidedbuffer.xml
Modified:
   trunk/tests/xmltester/Makefile.am
   trunk/tests/xmltester/XMLTester.cpp
Log:
Add an hausdorff distance based result matcher for single-sided buffer tests. Enable the single sided buffer test provided by swong in ticket #215 with minor tweak (expect multilinestring).


Modified: trunk/tests/xmltester/Makefile.am
===================================================================
--- trunk/tests/xmltester/Makefile.am	2009-09-27 20:43:03 UTC (rev 2628)
+++ trunk/tests/xmltester/Makefile.am	2009-09-28 07:02:02 UTC (rev 2629)
@@ -15,6 +15,7 @@
 	$(srcdir)/tests/linemerge.xml \
 	$(srcdir)/tests/TestIsValid.xml \
 	$(srcdir)/tests/robustness.xml \
+	$(srcdir)/tests/singlesidedbuffer.xml \
 	$(srcdir)/tests/bug176.xml \
 	$(srcdir)/tests/bug188.xml \
 	$(srcdir)/tests/bug244.xml \
@@ -79,7 +80,11 @@
 SimpleWKTTester_SOURCES = SimpleWKTTester.cpp
 SimpleWKTTester_LDADD = $(LIBS)
 
-XMLTester_SOURCES = XMLTester.cpp markup/MarkupSTL.cpp markup/MarkupSTL.h XMLTester.h BufferResultMatcher.h BufferResultMatcher.cpp
+XMLTester_SOURCES = XMLTester.cpp XMLTester.h \
+	markup/MarkupSTL.cpp markup/MarkupSTL.h \
+	BufferResultMatcher.h BufferResultMatcher.cpp \
+	SingleSidedBufferResultMatcher.h SingleSidedBufferResultMatcher.cpp
+
 XMLTester_LDADD = $(LIBS)
 
 INCLUDES = -I$(top_srcdir)/source/headers

Added: trunk/tests/xmltester/SingleSidedBufferResultMatcher.cpp
===================================================================
--- trunk/tests/xmltester/SingleSidedBufferResultMatcher.cpp	                        (rev 0)
+++ trunk/tests/xmltester/SingleSidedBufferResultMatcher.cpp	2009-09-28 07:02:02 UTC (rev 2629)
@@ -0,0 +1,86 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009  Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: original work
+ *
+ **********************************************************************/
+
+#include "SingleSidedBufferResultMatcher.h"
+
+#include <geos/geom/Geometry.h>
+#include <geos/geom/BinaryOp.h>
+#include <geos/operation/overlay/OverlayOp.h>
+#include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
+
+#include <cmath>
+
+namespace geos {
+namespace xmltester {
+
+double SingleSidedBufferResultMatcher::MIN_DISTANCE_TOLERANCE = 1.0e-8;
+double SingleSidedBufferResultMatcher::MAX_HAUSDORFF_DISTANCE_FACTOR = 100;
+
+bool
+SingleSidedBufferResultMatcher::isBufferResultMatch(const geom::Geometry& actualBuffer,
+	                         const geom::Geometry& expectedBuffer,
+	                         double distance)
+{
+	if (actualBuffer.isEmpty() && expectedBuffer.isEmpty())
+		return true;
+
+	if (! isBoundaryHausdorffDistanceInTolerance(actualBuffer,
+	           expectedBuffer, distance))
+	{
+std::cerr << "isBoundaryHasudorffDistanceInTolerance failed" << std::endl;
+		return false;
+	}
+
+	return true;
+}
+
+bool
+SingleSidedBufferResultMatcher::isBoundaryHausdorffDistanceInTolerance(
+	const geom::Geometry& actualBuffer,
+	const geom::Geometry& expectedBuffer, double distance)
+{
+	typedef std::auto_ptr<geom::Geometry> GeomPtr;
+
+	using geos::algorithm::distance::DiscreteHausdorffDistance;
+
+	GeomPtr actualBdy ( actualBuffer.clone() );
+	GeomPtr expectedBdy ( expectedBuffer.clone() );
+
+	DiscreteHausdorffDistance haus(*actualBdy, *expectedBdy);
+	haus.setDensifyFraction(0.25);
+
+	double maxDistanceFound = haus.orientedDistance();
+
+	double expectedDistanceTol = fabs(distance) / MAX_HAUSDORFF_DISTANCE_FACTOR;
+	if (expectedDistanceTol < MIN_DISTANCE_TOLERANCE)
+	{
+		expectedDistanceTol = MIN_DISTANCE_TOLERANCE;
+	}
+
+	if (maxDistanceFound > expectedDistanceTol)
+	{
+std::cerr << "maxDistanceFound: " << maxDistanceFound << " tolerated " << expectedDistanceTol << std::endl;
+		return false;
+	}
+
+	return true;
+}
+
+} // namespace geos::xmltester
+} // namespace geos

Added: trunk/tests/xmltester/SingleSidedBufferResultMatcher.h
===================================================================
--- trunk/tests/xmltester/SingleSidedBufferResultMatcher.h	                        (rev 0)
+++ trunk/tests/xmltester/SingleSidedBufferResultMatcher.h	2009-09-28 07:02:02 UTC (rev 2629)
@@ -0,0 +1,60 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009  Sandro Santilli <strk at keybit.net>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: original work
+ *
+ **********************************************************************/
+
+#ifndef XMLTESTER_SINGLESIDEDBUFFERRESULTMATCHER_H
+#define XMLTESTER_SINGLESIDEDBUFFERRESULTMATCHER_H
+
+// Forward declarations
+namespace geos {
+	namespace geom {
+		class Geometry;
+	}
+}
+
+namespace geos {
+namespace xmltester {
+
+class SingleSidedBufferResultMatcher
+{
+public:
+	bool isBufferResultMatch(const geom::Geometry& actualBuffer,
+	                         const geom::Geometry& expectedBuffer,
+	                         double distance);
+
+private:
+
+	static double MAX_HAUSDORFF_DISTANCE_FACTOR;
+
+	/*
+	 * The minimum distance tolerance which will be used.
+	 * This is required because densified vertices do no lie
+	 * precisely on their parent segment.
+	 */
+	static double MIN_DISTANCE_TOLERANCE;
+
+	bool isBoundaryHausdorffDistanceInTolerance(
+                        const geom::Geometry& actualBuffer,
+	                const geom::Geometry& expectedBuffer,
+	                double distance);
+};
+
+} // namespace geos::xmltester
+} // namespace geos
+
+#endif // XMLTESTER_SINGLESIDEDBUFFERRESULTMATCHER_H

Modified: trunk/tests/xmltester/XMLTester.cpp
===================================================================
--- trunk/tests/xmltester/XMLTester.cpp	2009-09-27 20:43:03 UTC (rev 2628)
+++ trunk/tests/xmltester/XMLTester.cpp	2009-09-28 07:02:02 UTC (rev 2629)
@@ -48,6 +48,7 @@
 #include <geos/opValid.h>
 #include "XMLTester.h"
 #include "BufferResultMatcher.h"
+#include "SingleSidedBufferResultMatcher.h"
 
 #include <cassert>
 #include <cctype>
@@ -148,6 +149,41 @@
 	return success;
 }
 
+static int
+checkSingleSidedBufferSuccess(geom::Geometry& gRes,
+		geom::Geometry& gRealRes, double dist)
+{
+	int success = 1;
+	do
+	{
+
+		if ( gRes.getGeometryTypeId() != gRealRes.getGeometryTypeId() )
+		{
+			std::cerr << "Expected result is of type "
+				<< gRes.getGeometryType()
+				<< "; obtained result is of type "
+				<< gRealRes.getGeometryType()
+				<< std::endl;
+			success=0;
+			break;
+		}
+
+		geos::xmltester::SingleSidedBufferResultMatcher matcher;
+		if ( ! matcher.isBufferResultMatch(gRealRes,
+						   gRes,
+						   dist) )
+		{
+std::cerr << "SingleSidedBufferResultMatcher FAILED" << std::endl;
+			success=0;
+			break;
+		}
+
+	}
+	while (0);
+
+	return success;
+}
+
 XMLTester::XMLTester()
 	:
 	gA(0),
@@ -886,33 +922,10 @@
 			profile.stop();
 			gRealRes->normalize();
 
-			// Assume a success and check for obvious failures
-			success=1;
-			do
-			{
+			// Validate the single sided buffer operation
+			success = checkSingleSidedBufferSuccess(*gRes,
+					*gRealRes, dist);
 
-				if ( gRes->getGeometryTypeId() !=
-				     gRealRes->getGeometryTypeId() )
-				{
-					std::cerr << "Expected result is of type "
-					        << gRes->getGeometryType()
-						<< "; obtained result is of type "
-						<< gRealRes->getGeometryType()
-						<< std::endl;
-					success=0;
-					break;
-				}
-				
-				if ( ! gRes->equals( gRealRes.get() ) )
-				{
-std::cerr << "Matching single sided buffer results FAILED" << std::endl;
-					success=0;
-					break;
-				}
-
-			}
-			while (0);
-
 			if ( testValidOutput ) testValid(gRes.get(), "result");
 
 			actual_result=printGeom(gRealRes.get());

Added: trunk/tests/xmltester/tests/singlesidedbuffer.xml
===================================================================
--- trunk/tests/xmltester/tests/singlesidedbuffer.xml	                        (rev 0)
+++ trunk/tests/xmltester/tests/singlesidedbuffer.xml	2009-09-28 07:02:02 UTC (rev 2629)
@@ -0,0 +1,19 @@
+<run>
+  <!--precisionModel scale="1.0" offsetx="0.0" offsety="0.0"/-->
+  <precisionModel type="FLOATING" />
+<case><desc>Single-sided buffers</desc>
+<a>
+LINESTRING (5 5,1 1,1.5 3)
+</a>
+<test>
+<op name="buffersinglesided" arg1="a" arg2="1.6" arg3="4" arg4="right">
+MULTILINESTRING ((0.889806640162438 3.15254833995939,3.86862915010152 6.13137084989848))
+</op>
+</test>
+<test>
+<op name="buffersinglesided" arg1="a" arg2="1.6" arg3="4" arg4="left">
+MULTILINESTRING ((6.13137084989848 3.86862915010152,2.13137084989848 -0.131370849898476,1.64334932914975 -0.464957897238882,1.06750928729122 -0.598575145599803,0.482454087349093 -0.513983562756987,-0.0319550194114402 -0.222730075655103,-0.405500120335007 0.235428609129087,-0.58719153245376 0.797952878498393,-0.552228000232531 1.38805700005813,-0.052228000232531 3.38805700005813))
+</op>
+</test>
+</case>
+</run>



More information about the geos-commits mailing list