[geos-commits] r2890 - trunk/tests/unit/linearref
svn_geos at osgeo.org
svn_geos at osgeo.org
Wed Jan 27 17:25:49 EST 2010
Author: mloskot
Date: 2010-01-27 17:25:48 -0500 (Wed, 27 Jan 2010)
New Revision: 2890
Modified:
trunk/tests/unit/linearref/LengthIndexedLineTest.cpp
Log:
Tidy up messy code in tests/unit/linearref
Modified: trunk/tests/unit/linearref/LengthIndexedLineTest.cpp
===================================================================
--- trunk/tests/unit/linearref/LengthIndexedLineTest.cpp 2010-01-27 22:09:45 UTC (rev 2889)
+++ trunk/tests/unit/linearref/LengthIndexedLineTest.cpp 2010-01-27 22:25:48 UTC (rev 2890)
@@ -28,144 +28,142 @@
/**
* Tests the {@link LocationIndexedLine} class
*/
-
namespace tut {
- typedef auto_ptr<Geometry> GeomPtr;
- static const double TOLERANCE_DIST = 0.001;
+typedef auto_ptr<Geometry> GeomPtr;
+static const double TOLERANCE_DIST = 0.001;
- struct test_lengthindexedline_data
+struct test_lengthindexedline_data
+{
+ test_lengthindexedline_data()
+ : pm(), gf(&pm), reader(&gf)
+ {}
+
+ PrecisionModel pm;
+ GeometryFactory gf;
+ geos::io::WKTReader reader;
+
+ void checkExpected(Geometry* result, string const& expected)
{
- test_lengthindexedline_data()
- : pm(), gf(&pm), reader(&gf)
- {}
+ GeomPtr subLine(reader.read(expected));
+ ensure_equals_geometry(subLine.get(), result);
+ }
+
+ void checkExpected(Geometry* result, const Geometry* expected)
+ {
+ ensure_equals_geometry(expected, result);
+ }
+
+ void runIndicesOfThenExtract(string const& inputStr, string const& subLineStr)
+ {
+ GeomPtr input(reader.read(inputStr));
+ GeomPtr subLine(reader.read(subLineStr));
+ GeomPtr result(indicesOfThenExtract(input.get(), subLine.get()));
+
+ checkExpected(result.get(), subLine.get());
+ }
+
+ bool indexOfAfterCheck(Geometry* linearGeom, Coordinate testPt)
+ {
+ LengthIndexedLine indexedLine(linearGeom);
+
+ // check locations are consecutive
+ double loc1 = indexedLine.indexOf(testPt);
+ double loc2 = indexedLine.indexOfAfter(testPt, loc1);
+ if (loc2 <= loc1) return false;
+
+ // check extracted points are the same as the input
+ Coordinate pt1 = indexedLine.extractPoint(loc1);
+ Coordinate pt2 = indexedLine.extractPoint(loc2);
+ if (! pt1.equals2D(testPt)) return false;
+ if (! pt2.equals2D(testPt)) return false;
- PrecisionModel pm;
- GeometryFactory gf;
- geos::io::WKTReader reader;
+ return true;
+ }
- void checkExpected(Geometry* result, string const& expected)
- {
- GeomPtr subLine(reader.read(expected));
- ensure_equals_geometry(subLine.get(), result);
- }
-
- void checkExpected(Geometry* result, const Geometry* expected)
- {
- ensure_equals_geometry(expected, result);
- }
-
- void runIndicesOfThenExtract(string const& inputStr, string const& subLineStr)
- {
- GeomPtr input(reader.read(inputStr));
- GeomPtr subLine(reader.read(subLineStr));
- GeomPtr result(indicesOfThenExtract(input.get(), subLine.get()));
-
- checkExpected(result.get(), subLine.get());
- }
+ void runIndexOfAfterTest(string const& inputStr, string const& testPtWKT)
+ {
+ GeomPtr input(reader.read(inputStr));
+ GeomPtr testPoint(reader.read(testPtWKT));
+ const Coordinate* testPt = testPoint->getCoordinate();
+ bool resultOK = indexOfAfterCheck(input.get(), *testPt);
+ ensure(resultOK);
+ }
- bool indexOfAfterCheck(Geometry* linearGeom, Coordinate testPt)
- {
- LengthIndexedLine indexedLine(linearGeom);
-
- // check locations are consecutive
- double loc1 = indexedLine.indexOf(testPt);
- double loc2 = indexedLine.indexOfAfter(testPt, loc1);
- if (loc2 <= loc1) return false;
-
- // check extracted points are the same as the input
- Coordinate pt1 = indexedLine.extractPoint(loc1);
- Coordinate pt2 = indexedLine.extractPoint(loc2);
- if (! pt1.equals2D(testPt)) return false;
- if (! pt2.equals2D(testPt)) return false;
-
- return true;
- }
+ void runOffsetTest(string const& inputWKT, string const& testPtWKT,
+ double offsetDistance, string const& expectedPtWKT)
+ {
+ GeomPtr input(reader.read(inputWKT));
+ GeomPtr testPoint(reader.read(testPtWKT));
+ GeomPtr expectedPoint(reader.read(expectedPtWKT));
+ const Coordinate* testPt = testPoint->getCoordinate();
+ const Coordinate* expectedPt = expectedPoint->getCoordinate();
+ Coordinate offsetPt = extractOffsetAt(input.get(), *testPt, offsetDistance);
- void runIndexOfAfterTest(string const& inputStr, string const& testPtWKT)
- {
- GeomPtr input(reader.read(inputStr));
- GeomPtr testPoint(reader.read(testPtWKT));
- const Coordinate* testPt = testPoint->getCoordinate();
- bool resultOK = indexOfAfterCheck(input.get(), *testPt);
- ensure(resultOK);
- }
+ bool isOk = offsetPt.distance(*expectedPt) < TOLERANCE_DIST;
+ if (! isOk)
+ cout << "Expected = " << *expectedPoint << " Actual = " << offsetPt << endl;
+ ensure(isOk);
+ }
- void runOffsetTest(string const& inputWKT, string const& testPtWKT,
- double offsetDistance, string const& expectedPtWKT)
- {
- GeomPtr input(reader.read(inputWKT));
- GeomPtr testPoint(reader.read(testPtWKT));
- GeomPtr expectedPoint(reader.read(expectedPtWKT));
- const Coordinate* testPt = testPoint->getCoordinate();
- const Coordinate* expectedPt = expectedPoint->getCoordinate();
- Coordinate offsetPt = extractOffsetAt(input.get(), *testPt, offsetDistance);
-
- bool isOk = offsetPt.distance(*expectedPt) < TOLERANCE_DIST;
- if (! isOk)
- cout << "Expected = " << *expectedPoint << " Actual = " << offsetPt << endl;
- ensure(isOk);
- }
+ Coordinate extractOffsetAt(Geometry* linearGeom, Coordinate testPt, double offsetDistance)
+ {
+ LengthIndexedLine indexedLine(linearGeom);
+ double index = indexedLine.indexOf(testPt);
+ return indexedLine.extractPoint(index, offsetDistance);
+ }
- Coordinate extractOffsetAt(Geometry* linearGeom, Coordinate testPt, double offsetDistance)
- {
- LengthIndexedLine indexedLine(linearGeom);
- double index = indexedLine.indexOf(testPt);
- return indexedLine.extractPoint(index, offsetDistance);
- }
-
- void checkExtractLine(const char* wkt, double start, double end, const char* expected)
- {
- string wktstr(wkt);
- GeomPtr linearGeom(reader.read(wktstr));
- LengthIndexedLine indexedLine(linearGeom.get());
- GeomPtr result(indexedLine.extractLine(start, end));
- checkExpected(result.get(), expected);
- }
-
-
- Geometry* indicesOfThenExtract(Geometry* linearGeom, Geometry* subLine)
- {
- LengthIndexedLine indexedLine(linearGeom);
- double* loc = indexedLine.indicesOf(subLine);
- Geometry* result = indexedLine.extractLine(loc[0], loc[1]);
- delete [] loc;
- return result;
- }
-
- }; // struct test_lengthindexedline_data
+ void checkExtractLine(const char* wkt, double start, double end, const char* expected)
+ {
+ string wktstr(wkt);
+ GeomPtr linearGeom(reader.read(wktstr));
+ LengthIndexedLine indexedLine(linearGeom.get());
+ GeomPtr result(indexedLine.extractLine(start, end));
+ checkExpected(result.get(), expected);
+ }
- typedef test_group<test_lengthindexedline_data> group;
- typedef group::object object;
-
- group test_lengthindexedline_group("geos::linearref::LocationIndexedLine");
-
- //1 - testML
- template<>
- template<>
- void object::test<1>()
- {
- runIndicesOfThenExtract("MULTILINESTRING ((0 0, 10 10), (20 20, 30 30))",
- "MULTILINESTRING ((1 1, 10 10), (20 20, 25 25))");
- }
+ Geometry* indicesOfThenExtract(Geometry* linearGeom, Geometry* subLine)
+ {
+ LengthIndexedLine indexedLine(linearGeom);
+ double* loc = indexedLine.indicesOf(subLine);
+ Geometry* result = indexedLine.extractLine(loc[0], loc[1]);
+ delete [] loc;
+ return result;
+ }
- //2 - testPartOfSegmentNoVertex
- template<>
- template<>
- void object::test<2>()
- {
- runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 20 20)",
- "LINESTRING (1 1, 9 9)");
+}; // struct test_lengthindexedline_data
+
+typedef test_group<test_lengthindexedline_data> group;
+typedef group::object object;
+
+group test_lengthindexedline_group("geos::linearref::LocationIndexedLine");
+
+//1 - testML
+template<>
+template<>
+void object::test<1>()
+{
+ runIndicesOfThenExtract("MULTILINESTRING ((0 0, 10 10), (20 20, 30 30))",
+ "MULTILINESTRING ((1 1, 10 10), (20 20, 25 25))");
}
+//2 - testPartOfSegmentNoVertex
+template<>
+template<>
+void object::test<2>()
+{
+ runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 20 20)",
+ "LINESTRING (1 1, 9 9)");
+}
+
//3 - testPartOfSegmentContainingVertex()
- template<>
- template<>
- void object::test<3>()
+template<>
+template<>
+void object::test<3>()
{
- runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 20 20)",
- "LINESTRING (5 5, 10 10, 15 15)");
+ runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 20 20)",
+ "LINESTRING (5 5, 10 10, 15 15)");
}
/**
@@ -174,12 +172,12 @@
* @throws Exception
*/
// 4 - testPartOfSegmentContainingDuplicateCoords
- template<>
- template<>
- void object::test<4>()
+template<>
+template<>
+void object::test<4>()
{
- runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 10 10, 20 20)",
- "LINESTRING (5 5, 10 10, 10 10, 15 15)");
+ runIndicesOfThenExtract("LINESTRING (0 0, 10 10, 10 10, 20 20)",
+ "LINESTRING (5 5, 10 10, 10 10, 15 15)");
}
/**
@@ -188,174 +186,174 @@
*/
//5 - testLoopWithStartSubLine
- template<>
- template<>
- void object::test<5>()
+template<>
+template<>
+void object::test<5>()
{
- runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
- "LINESTRING (0 0, 0 10, 10 10)");
+ runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
+ "LINESTRING (0 0, 0 10, 10 10)");
}
//6 - testLoopWithEndingSubLine()
- template<>
- template<>
- void object::test<6>()
+template<>
+template<>
+void object::test<6>()
{
- runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
- "LINESTRING (10 10, 10 0, 0 0)");
+ 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()
- template<>
- template<>
- void object::test<7>()
+template<>
+template<>
+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)");
+ 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()
- template<>
- template<>
- void object::test<8>()
+template<>
+template<>
+void object::test<8>()
{
- runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
- "LINESTRING (0 0, 0 0)");
+ 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()
- template<>
- template<>
- void object::test<9>()
+template<>
+template<>
+void object::test<9>()
{
- runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
- "LINESTRING (10 10, 10 10)");
+ runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
+ "LINESTRING (10 10, 10 10)");
}
//10 - testIndexOfAfterSquare()
- template<>
- template<>
- void object::test<10>()
+template<>
+template<>
+void object::test<10>()
{
- runIndexOfAfterTest("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
- "POINT (0 0)");
+ runIndexOfAfterTest("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)",
+ "POINT (0 0)");
}
//11 - testIndexOfAfterRibbon()
- template<>
- template<>
- void object::test<11>()
+template<>
+template<>
+void object::test<11>()
{
- runIndexOfAfterTest("LINESTRING (0 0, 0 60, 50 60, 50 20, -20 20)",
- "POINT (0 20)");
+ runIndexOfAfterTest("LINESTRING (0 0, 0 60, 50 60, 50 20, -20 20)",
+ "POINT (0 20)");
}
//12 - testOffsetStartPoint()
- template<>
- template<>
- void object::test<12>()
+template<>
+template<>
+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)");
- runOffsetTest("LINESTRING (0 0, 10 10, 10 10, 20 20)", "POINT(10 10)", 5.0, "POINT (6.464466094067262 13.535533905932738)");
- runOffsetTest("LINESTRING (0 0, 10 10, 10 10, 20 20)", "POINT(10 10)", -5.0, "POINT (13.535533905932738 6.464466094067262)");
+ 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)");
+ runOffsetTest("LINESTRING (0 0, 10 10, 10 10, 20 20)", "POINT(10 10)", 5.0, "POINT (6.464466094067262 13.535533905932738)");
+ runOffsetTest("LINESTRING (0 0, 10 10, 10 10, 20 20)", "POINT(10 10)", -5.0, "POINT (13.535533905932738 6.464466094067262)");
}
//13 - testExtractLineBeyondRange()
- template<>
- template<>
- void object::test<13>()
+template<>
+template<>
+void object::test<13>()
{
- checkExtractLine("LINESTRING (0 0, 10 10)", -100, 100, "LINESTRING (0 0, 10 10)");
+ checkExtractLine("LINESTRING (0 0, 10 10)", -100, 100, "LINESTRING (0 0, 10 10)");
}
//14 - testExtractLineReverse()
- template<>
- template<>
- void object::test<14>()
+template<>
+template<>
+void object::test<14>()
{
- checkExtractLine("LINESTRING (0 0, 10 0)", 9, 1, "LINESTRING (9 0, 1 0)");
+ checkExtractLine("LINESTRING (0 0, 10 0)", 9, 1, "LINESTRING (9 0, 1 0)");
}
//15 - testExtractLineReverseMulti()
- template<>
- template<>
- void object::test<15>()
+template<>
+template<>
+void object::test<15>()
{
- 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))");
+ 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()
- template<>
- template<>
- void object::test<16>()
+template<>
+template<>
+void object::test<16>()
{
- checkExtractLine("LINESTRING (0 0, 10 0)", -9, -1, "LINESTRING (1 0, 9 0)");
+ checkExtractLine("LINESTRING (0 0, 10 0)", -9, -1, "LINESTRING (1 0, 9 0)");
}
//17 - testExtractLineNegativeReverse()
- template<>
- template<>
- void object::test<17>()
+template<>
+template<>
+void object::test<17>()
{
- checkExtractLine("LINESTRING (0 0, 10 0)", -1, -9, "LINESTRING (9 0, 1 0)");
+ checkExtractLine("LINESTRING (0 0, 10 0)", -1, -9, "LINESTRING (9 0, 1 0)");
}
//18 - testExtractLineIndexAtEndpoint()
- template<>
- template<>
- void object::test<18>()
+template<>
+template<>
+void object::test<18>()
{
- checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
- 10, -1, "LINESTRING (20 0, 25 0, 29 0)");
+ checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
+ 10, -1, "LINESTRING (20 0, 25 0, 29 0)");
}
//19 - testExtractLineBothIndicesAtEndpoint()
- template<>
- template<>
- void object::test<19>()
+template<>
+template<>
+void object::test<19>()
{
- checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
- 10, 10, "LINESTRING (20 0, 20 0)");
+ checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
+ 10, 10, "LINESTRING (20 0, 20 0)");
}
//20 - testExtractLineBothIndicesAtEndpointNegative()
- template<>
- template<>
- void object::test<20>()
+template<>
+template<>
+void object::test<20>()
{
- checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
- -10, 10, "LINESTRING (20 0, 20 0)");
+ checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))",
+ -10, 10, "LINESTRING (20 0, 20 0)");
}
//21 - testExtractPointBeyondRange()
- template<>
- template<>
- void object::test<21>()
+template<>
+template<>
+void object::test<21>()
{
- GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 10)"));
- LengthIndexedLine indexedLine(linearGeom.get());
- Coordinate pt = indexedLine.extractPoint(100);
- ensure(pt == Coordinate(10, 10));
+ GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 10)"));
+ LengthIndexedLine indexedLine(linearGeom.get());
+ Coordinate pt = indexedLine.extractPoint(100);
+ ensure(pt == Coordinate(10, 10));
- Coordinate pt2 = indexedLine.extractPoint(0);
- ensure(pt2 == Coordinate(0, 0));
+ Coordinate pt2 = indexedLine.extractPoint(0);
+ ensure(pt2 == Coordinate(0, 0));
}
//22 - testProjectPointWithDuplicateCoords()
- template<>
- template<>
- void object::test<22>()
+template<>
+template<>
+void object::test<22>()
{
- GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 0, 10 0, 20 0)"));
- LengthIndexedLine indexedLine(linearGeom.get());
- double projIndex = indexedLine.project(Coordinate(10, 1));
- ensure(projIndex == 10.0);
+ GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 0, 10 0, 20 0)"));
+ LengthIndexedLine indexedLine(linearGeom.get());
+ double projIndex = indexedLine.project(Coordinate(10, 1));
+ ensure(projIndex == 10.0);
}
/**
@@ -363,16 +361,16 @@
*
*/
//23 - testComputeZ()
- template<>
- template<>
- void object::test<23>()
+template<>
+template<>
+void object::test<23>()
{
- GeomPtr linearGeom(reader.read("LINESTRING (0 0 0, 10 10 10)"));
- LengthIndexedLine indexedLine(linearGeom.get());
- double projIndex = indexedLine.project(Coordinate(5, 5));
- Coordinate projPt = indexedLine.extractPoint(projIndex);
-// System.out.println(projPt);
- ensure(projPt.equals3D(Coordinate(5, 5, 5)));
+ GeomPtr linearGeom(reader.read("LINESTRING (0 0 0, 10 10 10)"));
+ LengthIndexedLine indexedLine(linearGeom.get());
+ double projIndex = indexedLine.project(Coordinate(5, 5));
+ Coordinate projPt = indexedLine.extractPoint(projIndex);
+ // System.out.println(projPt);
+ ensure(projPt.equals3D(Coordinate(5, 5, 5)));
}
/**
@@ -380,16 +378,17 @@
*
*/
//24 - testComputeZNaN()
- template<>
- template<>
- void object::test<24>()
+template<>
+template<>
+void object::test<24>()
{
- GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 10 10)"));
- LengthIndexedLine indexedLine(linearGeom.get());
- double projIndex = indexedLine.project(Coordinate(5, 5));
- Coordinate projPt = indexedLine.extractPoint(projIndex);
- ensure(0 != ISNAN(projPt.z));
+ GeomPtr linearGeom(reader.read("LINESTRING (0 0, 10 10 10)"));
+ LengthIndexedLine indexedLine(linearGeom.get());
+ double projIndex = indexedLine.project(Coordinate(5, 5));
+ Coordinate projPt = indexedLine.extractPoint(projIndex);
+ ensure(0 != ISNAN(projPt.z));
}
+
+} // namespace tut
-}
More information about the geos-commits
mailing list