[geos-commits] r3528 - in trunk: include/geos/noding/snapround src/noding/snapround tests/unit tests/unit/noding tests/unit/noding/snapround

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Dec 6 12:26:47 EST 2011


Author: strk
Date: 2011-12-06 09:26:46 -0800 (Tue, 06 Dec 2011)
New Revision: 3528

Added:
   trunk/tests/unit/noding/snapround/
   trunk/tests/unit/noding/snapround/HotPixelTest.cpp
Modified:
   trunk/include/geos/noding/snapround/HotPixel.h
   trunk/src/noding/snapround/HotPixel.cpp
   trunk/tests/unit/Makefile.am
Log:
HotPixel: do not invalidate reference to original point. Fixes #498.

Modified: trunk/include/geos/noding/snapround/HotPixel.h
===================================================================
--- trunk/include/geos/noding/snapround/HotPixel.h	2011-12-06 17:26:09 UTC (rev 3527)
+++ trunk/include/geos/noding/snapround/HotPixel.h	2011-12-06 17:26:46 UTC (rev 3528)
@@ -152,7 +152,8 @@
 	/**
 	 * Creates a new hot pixel.
 	 *
-	 * @param pt the coordinate at the centre of the pixel
+	 * @param pt the coordinate at the centre of the pixel.
+	 *           Will be kept by reference, so make sure to keep it alive.
 	 * @param scaleFact the scaleFactor determining the pixel size
 	 * @param li the intersector to use for testing intersection with
 	 *        line segments

Modified: trunk/src/noding/snapround/HotPixel.cpp
===================================================================
--- trunk/src/noding/snapround/HotPixel.cpp	2011-12-06 17:26:09 UTC (rev 3527)
+++ trunk/src/noding/snapround/HotPixel.cpp	2011-12-06 17:26:46 UTC (rev 3528)
@@ -42,7 +42,7 @@
 	:
 	li(newLi),
 	pt(newPt),
-	originalPt(pt),
+	originalPt(newPt),
 	scaleFactor(newScaleFactor)
 {
 	if (scaleFactor != 1.0) {

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2011-12-06 17:26:09 UTC (rev 3527)
+++ trunk/tests/unit/Makefile.am	2011-12-06 17:26:46 UTC (rev 3528)
@@ -61,7 +61,7 @@
 	geom/MultiPolygonTest.cpp \
 	geom/PointTest.cpp \
 	geom/PolygonTest.cpp \
-  geom/PrecisionModelTest.cpp \
+	geom/PrecisionModelTest.cpp \
 	geom/prep/PreparedGeometryFactoryTest.cpp \
 	geom/TriangleTest.cpp \
 	geom/util/GeometryExtracterTest.cpp \
@@ -76,6 +76,7 @@
 	noding/NodedSegmentStringTest.cpp \
 	noding/SegmentNodeTest.cpp \
 	noding/SegmentPointComparatorTest.cpp \
+	noding/snapround/HotPixelTest.cpp \
 	operation/buffer/BufferOpTest.cpp \
 	operation/buffer/BufferParametersTest.cpp \
 	operation/distance/DistanceOpTest.cpp \

Added: trunk/tests/unit/noding/snapround/HotPixelTest.cpp
===================================================================
--- trunk/tests/unit/noding/snapround/HotPixelTest.cpp	                        (rev 0)
+++ trunk/tests/unit/noding/snapround/HotPixelTest.cpp	2011-12-06 17:26:46 UTC (rev 3528)
@@ -0,0 +1,95 @@
+// 
+// Test Suite for geos::noding::snapround::HotPixel class.
+
+#include <tut.hpp>
+// geos
+#include <geos/algorithm/LineIntersector.h>
+#include <geos/noding/snapround/HotPixel.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/Envelope.h>
+// std
+#include <memory>
+
+namespace tut
+{
+  //
+  // Test Group
+  //
+
+  // Common data used by all tests
+  struct test_hotpixel_data
+  {
+
+    typedef geos::geom::Coordinate Coordinate;
+    typedef geos::geom::Envelope Envelope;
+    typedef geos::algorithm::LineIntersector LineIntersector;
+    typedef geos::noding::snapround::HotPixel HotPixel;
+
+    test_hotpixel_data() {}
+  };
+
+  typedef test_group<test_hotpixel_data> group;
+  typedef group::object object;
+
+  group test_hotpixel_group("geos::noding::snapround::HotPixel");
+
+  //
+  // Test Cases
+  //
+
+  // Test with scaleFactor=1
+  template<>
+  template<>
+  void object::test<1>()
+  {
+
+    LineIntersector li;
+    Coordinate pt(10, 10);
+    HotPixel hp(pt, 1, li);
+
+    ensure_equals(hp.getCoordinate(), pt);
+
+    const Envelope& env = hp.getSafeEnvelope();
+    ensure_equals(env.toString(), "Env[9.25:10.75,9.25:10.75]");
+
+    Coordinate p0(0, 10);
+    Coordinate p1(20, 10);
+    ensure( "hp.intersects 0 10, 20 10", hp.intersects(p0, p1) );
+
+    p1.y = 11; // intersection point within 0.75 distance
+    ensure( "hp.intersects(0 10, 20 11)", hp.intersects(p0, p1));
+
+    p1.y = 20;
+    ensure_not( "!hp.intersects(0 10, 20 20)", hp.intersects(p0, p1));
+
+  }
+
+  // Test with scaleFactor=10
+  // See http://trac.osgeo.org/geos/ticket/498
+  template<>
+  template<>
+  void object::test<2>()
+  {
+
+    LineIntersector li;
+    Coordinate pt(10, 10);
+    HotPixel hp(pt, 10, li);
+
+    ensure_equals(hp.getCoordinate(), pt);
+
+    const Envelope& env = hp.getSafeEnvelope();
+    ensure_equals(env.toString(), "Env[9.925:10.075,9.925:10.075]");
+
+    Coordinate p0(0, 10);
+    Coordinate p1(20, 10);
+    ensure( "hp.intersects 0 10, 20 10", hp.intersects(p0, p1) );
+
+    p1.y = 11; // intersection point not within 0.075 distance
+    ensure_not( "hp.intersects(0 10, 20 11)", hp.intersects(p0, p1));
+
+  }
+
+  // TODO: test addSnappedNode !
+
+
+} // namespace tut



More information about the geos-commits mailing list