[geos-commits] r2384 - trunk/tests/xmltester
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Apr 17 11:47:07 EDT 2009
Author: strk
Date: 2009-04-17 11:47:07 -0400 (Fri, 17 Apr 2009)
New Revision: 2384
Added:
trunk/tests/xmltester/BufferResultMatcher.cpp
trunk/tests/xmltester/BufferResultMatcher.h
Modified:
trunk/tests/xmltester/XMLTester.cpp
Log:
Port BufferResultMatcher. Gives 31 new failures !!
Added: trunk/tests/xmltester/BufferResultMatcher.cpp
===================================================================
--- trunk/tests/xmltester/BufferResultMatcher.cpp (rev 0)
+++ trunk/tests/xmltester/BufferResultMatcher.cpp 2009-04-17 15:47:07 UTC (rev 2384)
@@ -0,0 +1,125 @@
+/**********************************************************************
+ * $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: jtstest/testrunner/BufferResultMatcher.java rev rev 1.5 (JTS-1.10)
+ *
+ **********************************************************************/
+
+#include "BufferResultMatcher.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 BufferResultMatcher::MAX_RELATIVE_AREA_DIFFERENCE = 1.0E-3;
+double BufferResultMatcher::MAX_HAUSDORFF_DISTANCE_FACTOR = 100;
+
+bool
+BufferResultMatcher::isBufferResultMatch(const geom::Geometry& actualBuffer,
+ const geom::Geometry& expectedBuffer,
+ double distance)
+{
+ if (actualBuffer.isEmpty() && expectedBuffer.isEmpty())
+ return true;
+
+ /**
+ * MD - need some more checks here - symDiffArea won't catch
+ * very small holes ("tears")
+ * near the edge of computed buffers (which can happen
+ * in current version of JTS (1.8)).
+ * This can probably be handled by testing
+ * that every point of the actual buffer is at least a certain
+ * distance away from the geometry boundary.
+ */
+ if (! isSymDiffAreaInTolerance(actualBuffer, expectedBuffer))
+ {
+std::cerr << "isSymDiffAreaInTolerance failed" << std::endl;
+ return false;
+ }
+
+ if (! isBoundaryHausdorffDistanceInTolerance(actualBuffer,
+ expectedBuffer, distance))
+ {
+std::cerr << "isBoundaryHasudorffDistanceInTolerance failed" << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+bool
+BufferResultMatcher::isSymDiffAreaInTolerance(
+ const geom::Geometry& actualBuffer,
+ const geom::Geometry& expectedBuffer)
+{
+ typedef std::auto_ptr<geom::Geometry> GeomPtr;
+
+ using namespace operation::overlay;
+ using geos::geom::BinaryOp;
+
+ double area = expectedBuffer.getArea();
+ GeomPtr diff = BinaryOp(&actualBuffer, &expectedBuffer,
+ overlayOp(OverlayOp::opSYMDIFFERENCE));
+
+ double areaDiff = diff->getArea();
+
+ // can't get closer than difference area = 0 !
+ // This also handles case when symDiff is empty
+ if (areaDiff <= 0.0) return true;
+
+ if (area <= 0) return false;
+ double frac = areaDiff / area;
+
+ bool ret = frac < MAX_RELATIVE_AREA_DIFFERENCE;
+ if ( ! ret )
+ {
+std::cerr << "symDiffArea frac: " << frac << " tolerated " << MAX_RELATIVE_AREA_DIFFERENCE << std::endl;
+ }
+ return ret;
+}
+
+bool
+BufferResultMatcher::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.getBoundary() );
+ GeomPtr expectedBdy ( expectedBuffer.getBoundary() );
+
+ DiscreteHausdorffDistance haus(*actualBdy, *expectedBdy);
+ haus.setDensifyFraction(0.25);
+ double maxDistanceFound = haus.orientedDistance();
+ double expectedDistanceTol = fabs(distance) / MAX_HAUSDORFF_DISTANCE_FACTOR;
+ if (maxDistanceFound > expectedDistanceTol)
+ {
+std::cerr << "maxDistanceFound: " << maxDistanceFound << " tolerated " << expectedDistanceTol << std::endl;
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace geos::xmltester
+} // namespace geos
Added: trunk/tests/xmltester/BufferResultMatcher.h
===================================================================
--- trunk/tests/xmltester/BufferResultMatcher.h (rev 0)
+++ trunk/tests/xmltester/BufferResultMatcher.h 2009-04-17 15:47:07 UTC (rev 2384)
@@ -0,0 +1,58 @@
+/**********************************************************************
+ * $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: jtstest/testrunner/BufferResultMatcher.java rev rev 1.5 (JTS-1.10)
+ *
+ **********************************************************************/
+
+#ifndef XMLTESTER_BUFFERRESULTMATCHER_H
+#define XMLTESTER_BUFFERRESULTMATCHER_H
+
+// Forward declarations
+namespace geos {
+ namespace geom {
+ class Geometry;
+ }
+}
+
+namespace geos {
+namespace xmltester {
+
+class BufferResultMatcher
+{
+public:
+ bool isBufferResultMatch(const geom::Geometry& actualBuffer,
+ const geom::Geometry& expectedBuffer,
+ double distance);
+
+private:
+
+ static double MAX_RELATIVE_AREA_DIFFERENCE;
+
+ static double MAX_HAUSDORFF_DISTANCE_FACTOR;
+
+ bool isSymDiffAreaInTolerance(const geom::Geometry& actualBuffer,
+ const geom::Geometry& expectedBuffer);
+
+ bool isBoundaryHausdorffDistanceInTolerance(
+ const geom::Geometry& actualBuffer,
+ const geom::Geometry& expectedBuffer,
+ double distance);
+};
+
+} // namespace geos::xmltester
+} // namespace geos
+
+#endif // XMLTESTER_BUFFERRESULTMATCHER_H
Modified: trunk/tests/xmltester/XMLTester.cpp
===================================================================
--- trunk/tests/xmltester/XMLTester.cpp 2009-04-17 15:37:32 UTC (rev 2383)
+++ trunk/tests/xmltester/XMLTester.cpp 2009-04-17 15:47:07 UTC (rev 2384)
@@ -46,6 +46,7 @@
#include <geos/unload.h>
#include <geos/opValid.h>
#include "XMLTester.h"
+#include "BufferResultMatcher.h"
#include <cassert>
#include <cctype>
@@ -724,6 +725,17 @@
success=1;
do
{
+#if USE_BUFFER_RESULT_MATCHER
+ geos::xmltester::BufferResultMatcher matcher;
+ if ( ! matcher.isBufferResultMatch(*gRealRes,
+ *gRes,
+ dist) )
+ {
+ success=0;
+ break;
+ }
+#endif
+
// TODO: Is a buffer always an area ?
// we might check geometry type..
More information about the geos-commits
mailing list