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
|
//
// Test Suite for geos::algorithm::PointLocation
// Ported from JTS junit/algorithm/PointLocationTest.java
#include <tut/tut.hpp>
#include <utility.h>
// geos
#include <geos/geom/Coordinate.h>
#include <geos/algorithm/PointLocation.h>
// std
#include <string>
#include <memory>
using geos::algorithm::PointLocation;
using geos::geom::CoordinateXY;
namespace tut {
//
// Test Group
//
// dummy data, not used
struct test_PointLocation_data {
geos::io::WKTReader r_;
void
checkOnLine(double x, double y, const std::string& wktLine, bool isExpected)
{
CoordinateXY p(x, y);
std::unique_ptr<CoordinateSequence> line = readPts(wktLine);
bool isOnLine = PointLocation::isOnLine(p, line.get());
ensure(isOnLine == isExpected);
}
void
checkOnSegment(double x, double y, const std::string& wktLine, bool isExpected)
{
CoordinateXY p(x, y);
std::unique_ptr<CoordinateSequence> line = readPts(wktLine);
bool isOnSeg = PointLocation::isOnSegment(p, line->getAt(0), line->getAt(1));
ensure(isOnSeg == 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_PointLocation_data> group;
typedef group::object object;
group test_PointLocation_data("geos::algorithm::PointLocation");
//
// Test Cases
//
// testOnLineOnVertex
template<>
template<>
void object::test<1> ()
{
checkOnLine(20, 20, "LINESTRING (0 00, 20 20, 30 30)", true);
}
// testOnLineInSegment
template<>
template<>
void object::test<2> ()
{
checkOnLine(10, 10, "LINESTRING (0 0, 20 20, 0 40)", true);
checkOnLine(10, 30, "LINESTRING (0 0, 20 20, 0 40)", true);
}
// testNotOnLine
template<>
template<>
void object::test<3> ()
{
checkOnLine(0, 100, "LINESTRING (10 10, 20 10, 30 10)", false);
}
// testOnSegment
template<>
template<>
void object::test<4> ()
{
checkOnSegment(5, 5, "LINESTRING(0 0, 9 9)", true);
checkOnSegment(0, 0, "LINESTRING(0 0, 9 9)", true);
checkOnSegment(9, 9, "LINESTRING(0 0, 9 9)", true);
}
// testNotOnSegment
template<>
template<>
void object::test<5> ()
{
checkOnSegment(5, 6, "LINESTRING(0 0, 9 9)", false);
checkOnSegment(10, 10, "LINESTRING(0 0, 9 9)", false);
checkOnSegment(9, 9.00001, "LINESTRING(0 0, 9 9)", false);
}
// testOnZeroLengthSegment
template<>
template<>
void object::test<6> ()
{
checkOnSegment(1, 1, "LINESTRING(1 1, 1 1)", true);
checkOnSegment(1, 2, "LINESTRING(1 1, 1 1)", false);
}
} // namespace tut
|