[geos-commits] r3483 - trunk/tests/unit/linearref
svn_geos at osgeo.org
svn_geos at osgeo.org
Fri Sep 23 08:14:39 EDT 2011
Author: strk
Date: 2011-09-23 05:14:39 -0700 (Fri, 23 Sep 2011)
New Revision: 3483
Modified:
trunk/tests/unit/linearref/LengthIndexedLineTest.cpp
Log:
Port updates to the LenghtIndexedLineTest testcase (see #323)
Note that the test fails if the library isn't also fixed
Modified: trunk/tests/unit/linearref/LengthIndexedLineTest.cpp
===================================================================
--- trunk/tests/unit/linearref/LengthIndexedLineTest.cpp 2011-09-23 01:03:54 UTC (rev 3482)
+++ trunk/tests/unit/linearref/LengthIndexedLineTest.cpp 2011-09-23 12:14:39 UTC (rev 3483)
@@ -1,12 +1,13 @@
//
-// Ported from JTS junit/linearref/AbstractIndexedLineTest.java rev. 1.10
-// and junit/linearref/LengthIndexedLineTest.java rev. 1.10
+// Ported from JTS junit/linearref/AbstractIndexedLineTestCase.java r466
+// and junit/linearref/LengthIndexedLineTestCase.java r466
#include <tut.hpp>
#include <utility.h>
// geos
#include <geos/platform.h>
#include <geos/io/WKTReader.h>
+#include <geos/io/WKTWriter.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Geometry.h> // required for use in auto_ptr
@@ -35,22 +36,26 @@
struct test_lengthindexedline_data
{
test_lengthindexedline_data()
- : pm(), gf(&pm), reader(&gf)
- {}
+ : pm(), gf(&pm), reader(&gf), writer()
+ {
+ writer.setTrim(true);
+ }
PrecisionModel pm;
GeometryFactory gf;
geos::io::WKTReader reader;
+ geos::io::WKTWriter writer;
void checkExpected(Geometry* result, string const& expected)
{
GeomPtr subLine(reader.read(expected));
- ensure_equals_geometry(subLine.get(), result);
+ checkExpected(result, subLine.get());
}
void checkExpected(Geometry* result, const Geometry* expected)
{
- ensure_equals_geometry(expected, result);
+ bool isEqual = result->equalsExact(expected, 1.0e-5);
+ ensure_equals("Expect: "+writer.write(expected)+" Obtained: "+writer.write(result), isEqual, true);
}
void runIndicesOfThenExtract(string const& inputStr, string const& subLineStr)
@@ -138,7 +143,7 @@
group test_lengthindexedline_group("geos::linearref::LocationIndexedLine");
-//1 - testML
+// testML
template<>
template<>
void object::test<1>()
@@ -147,19 +152,19 @@
"MULTILINESTRING ((1 1, 10 10), (20 20, 25 25))");
}
-//2 - testPartOfSegmentNoVertex
+// testPartOfSegmentNoVertex
template<>
template<>
-void object::test<2>()
+void object::test<2>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 20 20)",
"LINESTRING (1 1, 9 9)");
}
-//3 - testPartOfSegmentContainingVertex()
+// testPartOfSegmentContainingVertex()
template<>
template<>
-void object::test<3>()
+void object::test<3>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 20 20)",
"LINESTRING (5 5, 10 10, 15 15)");
@@ -170,10 +175,10 @@
*
* @throws Exception
*/
-// 4 - testPartOfSegmentContainingDuplicateCoords
+// testPartOfSegmentContainingDuplicateCoords
template<>
template<>
-void object::test<4>()
+void object::test<4>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 10 10, 20 20)",
"LINESTRING (5 5, 10 10, 10 10, 15 15)");
@@ -184,76 +189,76 @@
* This requires that the correct vertex for (0,0) is selected.
*/
-//5 - testLoopWithStartSubLine
+// testLoopWithStartSubLine
template<>
template<>
-void object::test<5>()
+void object::test<5>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
"LINESTRING (0 0, 0 10, 10 10)");
}
-//6 - testLoopWithEndingSubLine()
+// testLoopWithEndingSubLine()
template<>
template<>
-void object::test<6>()
+void object::test<6>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
"LINESTRING (10 10, 10 0, 0 0)");
}
// test a subline equal to the parent loop
-//7 - testLoopWithIdenticalSubLine()
+// testLoopWithIdenticalSubLine()
template<>
template<>
-void object::test<7>()
+void object::test<7>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
"LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)");
}
// test a zero-length subline equal to the start point
-//8 - testZeroLenSubLineAtStart()
+// testZeroLenSubLineAtStart()
template<>
template<>
-void object::test<8>()
+void object::test<8>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
"LINESTRING (0 0, 0 0)");
}
// test a zero-length subline equal to a mid point
-//9 - testZeroLenSubLineAtMidVertex()
+// testZeroLenSubLineAtMidVertex()
template<>
template<>
-void object::test<9>()
+void object::test<9>()
{
runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
"LINESTRING (10 10, 10 10)");
}
-//10 - testIndexOfAfterSquare()
+// testIndexOfAfterSquare()
template<>
template<>
-void object::test<10>()
+void object::test<10>()
{
runIndexOfAfterTest("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
"POINT (0 0)");
}
-//11 - testIndexOfAfterRibbon()
+// testIndexOfAfterRibbon()
template<>
template<>
-void object::test<11>()
+void object::test<11>()
{
runIndexOfAfterTest("LINESTRING (0 0, 0 60, 50 60, 50 20, -20 20)",
"POINT (0 20)");
}
-//12 - testOffsetStartPoint()
+// testOffsetStartPoint()
template<>
template<>
-void object::test<12>()
+void object::test<12>()
{
runOffsetTest("LINESTRING (0 0, 10 10, 10 10, 20 20)", "POINT(0 0)", 1.0, "POINT (-0.7071067811865475 0.7071067811865475)");
runOffsetTest("LINESTRING (0 0, 10 10, 10 10, 20 20)", "POINT(0 0)", -1.0, "POINT (0.7071067811865475 -0.7071067811865475)");
@@ -261,79 +266,89 @@
runOffsetTest("LINESTRING (0 0, 10 10, 10 10, 20 20)", "POINT(10 10)", -5.0, "POINT (13.535533905932738 6.464466094067262)");
}
-
-//13 - testExtractLineBeyondRange()
+// testExtractLineBothIndicesAtEndpointXXX()
template<>
template<>
-void object::test<13>()
+void object::test<13>()
{
+ checkExtractLine(
+ "MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
+ -10, 10, "LINESTRING (10 0, 10 0)"
+ );
+}
+
+
+// testExtractLineBeyondRange()
+template<> template<>
+void object::test<14>()
+{
checkExtractLine("LINESTRING (0 0, 10 10)", -100, 100, "LINESTRING (0 0, 10 10)");
}
-//14 - testExtractLineReverse()
+// testExtractLineReverse()
template<>
template<>
-void object::test<14>()
+void object::test<15>()
{
checkExtractLine("LINESTRING (0 0, 10 0)", 9, 1, "LINESTRING (9 0, 1 0)");
}
-//15 - testExtractLineReverseMulti()
+// testExtractLineReverseMulti()
template<>
template<>
-void object::test<15>()
+void object::test<16>()
{
checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
19, 1, "MULTILINESTRING ((29 0, 25 0, 20 0), (10 0, 1 0))");
}
-//16 - testExtractLineNegative()
+// testExtractLineNegative()
template<>
template<>
-void object::test<16>()
+void object::test<17>()
{
checkExtractLine("LINESTRING (0 0, 10 0)", -9, -1, "LINESTRING (1 0, 9 0)");
}
-//17 - testExtractLineNegativeReverse()
+// testExtractLineNegativeReverse()
template<>
template<>
-void object::test<17>()
+void object::test<18>()
{
checkExtractLine("LINESTRING (0 0, 10 0)", -1, -9, "LINESTRING (9 0, 1 0)");
}
-//18 - testExtractLineIndexAtEndpoint()
+// testExtractLineIndexAtEndpoint()
template<>
template<>
-void object::test<18>()
+void object::test<19>()
{
checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
10, -1, "LINESTRING (20 0, 25 0, 29 0)");
}
-//19 - testExtractLineBothIndicesAtEndpoint()
+// testExtractLineBothIndicesAtEndpoint()
template<>
template<>
-void object::test<19>()
+void object::test<20>()
{
checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
- 10, 10, "LINESTRING (20 0, 20 0)");
+ 10, 10, "LINESTRING (10 0, 10 0)");
}
-//20 - testExtractLineBothIndicesAtEndpointNegative()
+// testExtractLineBothIndicesAtEndpointNegative()
template<>
template<>
-void object::test<20>()
+void object::test<21>()
{
checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
- -10, 10, "LINESTRING (20 0, 20 0)");
+ -10, 10, "LINESTRING (10 0, 10 0)");
}
-//21 - testExtractPointBeyondRange()
+// testExtractPointBeyondRange()
template<>
template<>
-void object::test<21>()
+void object::test<22>()
{
GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 10)"));
LengthIndexedLine indexedLine(linearGeom.get());
@@ -344,10 +359,10 @@
ensure(pt2 == Coordinate(0, 0));
}
-//22 - testProjectPointWithDuplicateCoords()
+// testProjectPointWithDuplicateCoords()
template<>
template<>
-void object::test<22>()
+void object::test<23>()
{
GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 0, 10 0, 20 0)"));
LengthIndexedLine indexedLine(linearGeom.get());
@@ -359,10 +374,10 @@
* Tests that z values are interpolated
*
*/
-//23 - testComputeZ()
+// testComputeZ()
template<>
template<>
-void object::test<23>()
+void object::test<24>()
{
GeomPtr linearGeom(reader.read("LINESTRING (0 0 0, 10 10 10)"));
LengthIndexedLine indexedLine(linearGeom.get());
@@ -376,10 +391,10 @@
* Tests that if the input does not have Z ordinates, neither does the output.
*
*/
-//24 - testComputeZNaN()
+// testComputeZNaN()
template<>
template<>
-void object::test<24>()
+void object::test<25>()
{
GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 10 10)"));
@@ -388,6 +403,74 @@
Coordinate projPt = indexedLine.extractPoint(projIndex);
ensure(0 != ISNAN(projPt.z));
}
+
+/**
+ * From GEOS Ticket #323
+ */
+// testProjectExtractPoint()
+template<>
+template<>
+void object::test<26>()
+{
+ GeomPtr linearGeom(reader.read("MULTILINESTRING ((0 2, 0 0), (-1 1, 1 1))"));
+ LengthIndexedLine indexedLine(linearGeom.get());
+ double index = indexedLine.project(Coordinate(1, 0));
+ Coordinate pt = indexedLine.extractPoint(index);
+ ensure_equals(pt, Coordinate(0, 0));
+}
+
+/**
+ * Tests that leading and trailing zero-length sublines are trimmed in
+ * the computed result, and that zero-length extracts return the lowest
+ * extracted zero-length line
+ */
+// testExtractLineIndexAtEndpointWithZeroLenComponents()
+template<> template<>
+void object::test<27>()
+{
+ checkExtractLine(
+ "MULTILINESTRING ((0 0, 10 0), (10 0, 10 0), (20 0, 25 0, 30 0))",
+ 10, -1, "LINESTRING (20 0, 25 0, 29 0)");
+
+ checkExtractLine(
+ "MULTILINESTRING ((0 0, 10 0), (10 0, 10 0), (20 0, 25 0, 30 0))",
+ 5, 10, "LINESTRING (5 0, 10 0)");
+
+ checkExtractLine(
+ "MULTILINESTRING ((0 0,10 0),(10 0,10 0),(10 0,10 0),(20 0,25 0,30 0))",
+ 10, 10, "LINESTRING (10 0, 10 0)");
+
+ checkExtractLine(
+ "MULTILINESTRING((0 0,10 0),(10 0,10 0),(10 0,10 0),(10 0,10 0),(20 0,25 0,30 0))",
+ 10, -10, "LINESTRING (10 0, 10 0)");
+}
+
+
+
+
+
+#if 0
+template<>
+template<>
+void object::test<28>()
+{
+
+ GeomPtr linearGeom(reader.read(
+"MULTILINESTRING ((0 -2, 0 2),(-2 0, 2 0))"
+));
+ LengthIndexedLine indexedLine(linearGeom.get());
+
+ double projIndex = indexedLine.project(Coordinate(2, 1.9));
+ ensure_equals(projIndex, 8);
+ Coordinate projPt = indexedLine.extractPoint(projIndex);
+ ensure_equals(projPt, Coordinate(2, 0));
+
+ projIndex = indexedLine.project(Coordinate(2, 2.1));
+ ensure_equals(projIndex, 4);
+ projPt = indexedLine.extractPoint(projIndex);
+ ensure_equals(projPt, Coordinate(0, 2));
+}
+#endif
} // namespace tut
More information about the geos-commits
mailing list