1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
//
// Test Suite for geos::algorithm::Length
// Ported from JTS junit/algorithm/LengthTest.java
#include <tut/tut.hpp>
#include <utility.h>
// geos
#include <geos/algorithm/PolygonNodeTopology.h>
// std
#include <string>
#include <memory>
using geos::algorithm::PolygonNodeTopology;
namespace tut {
//
// Test Group
//
// dummy data, not used
struct test_polygonnodetopology_data {
geos::io::WKTReader r_;
void
checkCrossing(const std::string& wktA, const std::string& wktB)
{
checkCrossing(wktA, wktB, true);
}
void
checkNonCrossing(const std::string& wktA, const std::string& wktB)
{
checkCrossing(wktA, wktB, false);
}
void
checkCrossing(const std::string& wktA, const std::string& wktB, bool isExpected)
{
std::unique_ptr<CoordinateSequence> a = readPts(wktA);
std::unique_ptr<CoordinateSequence> b = readPts(wktB);
// assert: a[1] = b[1]
bool isCrossing = PolygonNodeTopology::isCrossing(
&a->getAt(1), &a->getAt(0), &a->getAt(2), &b->getAt(0), &b->getAt(2));
ensure(isCrossing == isExpected);
}
void
checkInterior(const std::string& wktA, const std::string& wktB)
{
checkInteriorSegment(wktA, wktB, true);
}
void
checkExterior(const std::string& wktA, const std::string& wktB)
{
checkInteriorSegment(wktA, wktB, false);
}
void
checkInteriorSegment(const std::string& wktA, const std::string& wktB, bool isExpected)
{
std::unique_ptr<CoordinateSequence> a = readPts(wktA);
std::unique_ptr<CoordinateSequence> b = readPts(wktB);
// assert: a[1] = b[1]
bool isInterior = PolygonNodeTopology::isInteriorSegment(
&a->getAt(1), &a->getAt(0), &a->getAt(2), &b->getAt(1));
ensure(isInterior == isExpected);
}
std::unique_ptr<CoordinateSequence>
readPts(const std::string& wkt)
{
auto line = r_.read<LineString>(wkt);
if (line)
return line->getCoordinatesRO()->clone();
else
return nullptr;
}
};
typedef test_group<test_polygonnodetopology_data> group;
typedef group::object object;
group test_polygonnodetopology_data("geos::algorithm::PolygonNodeTopology");
//
// Test Cases
//
template<>
template<>
void object::test<1> ()
{
checkCrossing(
"LINESTRING (500 1000, 1000 1000, 1000 1500)",
"LINESTRING (1000 500, 1000 1000, 500 1500)");
}
//
// testNonCrossingQuadrant2
//
template<>
template<>
void object::test<2> ()
{
checkNonCrossing(
"LINESTRING (500 1000, 1000 1000, 1000 1500)",
"LINESTRING (300 1200, 1000 1000, 500 1500)");
}
//
// testNonCrossingQuadrant4
//
template<>
template<>
void object::test<3> ()
{
checkNonCrossing(
"LINESTRING (500 1000, 1000 1000, 1000 1500)",
"LINESTRING (1000 500, 1000 1000, 1500 1000)");
}
//
// testInteriorSegment
//
template<>
template<>
void object::test<4> ()
{
checkInterior(
"LINESTRING (5 9, 5 5, 9 5)",
"LINESTRING (5 5, 0 0)");
}
//
// testExteriorSegment
//
template<>
template<>
void object::test<5> ()
{
checkExterior(
"LINESTRING (5 9, 5 5, 9 5)",
"LINESTRING (5 5, 9 9)");
}
} // namespace tut
|