[geos-commits] r3316 - in trunk: . tests/perf/operation
tests/perf/operation/predicate
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Apr 28 10:16:56 EDT 2011
Author: strk
Date: 2011-04-28 07:16:56 -0700 (Thu, 28 Apr 2011)
New Revision: 3316
Added:
trunk/tests/perf/operation/predicate/
trunk/tests/perf/operation/predicate/Makefile.am
trunk/tests/perf/operation/predicate/RectangleIntersectsPerfTest.cpp
Modified:
trunk/configure.in
trunk/tests/perf/operation/Makefile.am
Log:
Port RectangleIntersects performance test from JTS-1.12
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2011-04-28 14:16:47 UTC (rev 3315)
+++ trunk/configure.in 2011-04-28 14:16:56 UTC (rev 3316)
@@ -508,6 +508,7 @@
tests/perf/Makefile
tests/perf/operation/Makefile
tests/perf/operation/buffer/Makefile
+ tests/perf/operation/predicate/Makefile
tests/xmltester/Makefile
tests/geostest/Makefile
tests/thread/Makefile
Modified: trunk/tests/perf/operation/Makefile.am
===================================================================
--- trunk/tests/perf/operation/Makefile.am 2011-04-28 14:16:47 UTC (rev 3315)
+++ trunk/tests/perf/operation/Makefile.am 2011-04-28 14:16:56 UTC (rev 3316)
@@ -3,5 +3,6 @@
# This file is part of project GEOS (http://trac.osgeo.org/geos/)
#
SUBDIRS = \
- buffer
+ buffer \
+ predicate
Added: trunk/tests/perf/operation/predicate/Makefile.am
===================================================================
--- trunk/tests/perf/operation/predicate/Makefile.am (rev 0)
+++ trunk/tests/perf/operation/predicate/Makefile.am 2011-04-28 14:16:56 UTC (rev 3316)
@@ -0,0 +1,16 @@
+#
+# This file is part of project GEOS (http://trac.osgeo.org/geos/)
+#
+prefix=@prefix@
+top_srcdir=@top_srcdir@
+top_builddir=@top_builddir@
+
+noinst_PROGRAMS = RectangleIntersectsPerfTest
+
+LIBS = $(top_builddir)/src/libgeos.la
+
+RectangleIntersectsPerfTest_SOURCES = RectangleIntersectsPerfTest.cpp
+RectangleIntersectsPerfTest_LDADD = $(LIBS)
+
+INCLUDES = -I$(top_srcdir)/include
+INCLUDES += -I$(top_srcdir)/src/io/markup
Added: trunk/tests/perf/operation/predicate/RectangleIntersectsPerfTest.cpp
===================================================================
--- trunk/tests/perf/operation/predicate/RectangleIntersectsPerfTest.cpp (rev 0)
+++ trunk/tests/perf/operation/predicate/RectangleIntersectsPerfTest.cpp 2011-04-28 14:16:56 UTC (rev 3316)
@@ -0,0 +1,160 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2011 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: perf/operation/predicate/RectangleIntersectsPerfTest.java r378 (JTS-1.12)
+ *
+ **********************************************************************/
+
+
+#include <geos/geom/PrecisionModel.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/util/GeometricShapeFactory.h>
+#include <geos/precision/SimpleGeometryPrecisionReducer.h>
+#include <geos/geom/util/SineStarFactory.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/profiler.h>
+#include <iostream>
+#include <vector>
+#include <cmath>
+#include <sstream>
+#include <memory>
+
+using namespace geos::geom;
+using namespace geos::io;
+using namespace std;
+
+class RectangleIntersectsPerfTest
+{
+public:
+ RectangleIntersectsPerfTest()
+ :
+ pm(),
+ fact(&pm, 0)
+ {}
+
+ void test(int nPts)
+ {
+ double size = 100;
+ Coordinate origin(0, 0);
+ auto_ptr<Geometry> sinePoly (
+ createSineStar(origin, size, nPts)->getBoundary()
+ );
+
+ /**
+ * Make the geometry "crinkly" by rounding off the points.
+ * This defeats the MonotoneChain optimization in the full relate
+ * algorithm, and provides a more realistic test.
+ */
+ using geos::precision::SimpleGeometryPrecisionReducer;
+ PrecisionModel pm(size/10);
+ SimpleGeometryPrecisionReducer reducer(&pm);
+ auto_ptr<Geometry> sinePolyCrinkly ( reducer.reduce(sinePoly.get()) );
+ sinePoly.reset();
+
+ Geometry& target = *sinePolyCrinkly;
+
+ testRectangles(target, 30, 5);
+ }
+
+
+private:
+
+ static const int MAX_ITER = 10;
+
+ static const int NUM_AOI_PTS = 2000;
+ static const int NUM_LINES = 5000;
+ static const int NUM_LINE_PTS = 1000;
+
+ PrecisionModel pm;
+ GeometryFactory fact;
+
+ void testRectangles(const Geometry& target, int nRect, double rectSize)
+ {
+ vector<const Geometry*> rects;
+ createRectangles(*target.getEnvelopeInternal(), nRect, rectSize, rects);
+ test(rects, target);
+ for (vector<const Geometry*>::iterator i=rects.begin(), n=rects.end();
+ i!=n; ++i) delete *i;
+ }
+
+ void test(vector<const Geometry*>& rect, const Geometry& g)
+ {
+ typedef vector<const Geometry*>::size_type size_type;
+
+ stringstream ss; ss << g.getNumPoints() << " pts";
+
+ geos::util::Profile sw(ss.str());
+ sw.start();
+
+ for (int i = 0; i < MAX_ITER; i++) {
+ for (size_type j = 0; j < rect.size(); j++) {
+ rect[j]->intersects(&g);
+ }
+ }
+
+ sw.stop();
+ cout << sw << endl;
+
+ }
+
+ // Push newly created geoms to rectLit
+ void createRectangles(const Envelope& env, int nRect, double rectSize,
+ vector<const Geometry*>& rectList)
+ {
+ int nSide = 1 + (int)sqrt((double) nRect);
+ double dx = env.getWidth() / nSide;
+ double dy = env.getHeight() / nSide;
+
+ for (int i = 0; i < nSide; i++) {
+ for (int j = 0; j < nSide; j++) {
+ double baseX = env.getMinX() + i * dx;
+ double baseY = env.getMinY() + j * dy;
+ Envelope envRect(
+ baseX, baseX + dx,
+ baseY, baseY + dy);
+ Geometry* rect = fact.toGeometry(&envRect);
+ rectList.push_back(rect);
+ }
+ }
+ }
+
+ auto_ptr<Polygon> createSineStar(const Coordinate& origin,
+ double size, int nPts)
+ {
+ using geos::geom::util::SineStarFactory;
+
+ SineStarFactory gsf(&fact);
+ gsf.setCentre(origin);
+ gsf.setSize(size);
+ gsf.setNumPoints(nPts);
+ gsf.setArmLengthRatio(2);
+ gsf.setNumArms(20);
+ auto_ptr<Polygon> poly = gsf.createSineStar();
+ return poly;
+ }
+
+
+};
+
+int
+main()
+{
+
+ RectangleIntersectsPerfTest tester;
+
+ tester.test(500);
+ tester.test(100000);
+}
+
More information about the geos-commits
mailing list