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
|
//
// Test Suite for geos::algorithm::Length
// Ported from JTS junit/algorithm/LengthTest.java
#include <tut/tut.hpp>
// geos
#include <geos/algorithm/Length.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Dimension.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/LineString.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/io/WKTReader.h>
// std
#include <string>
#include <memory>
using namespace geos;
using namespace geos::geom;
namespace tut {
//
// Test Group
//
// dummy data, not used
struct test_length_data {
geos::geom::Geometry* geom_;
geos::geom::PrecisionModel pm_;
geos::geom::GeometryFactory::Ptr factory_;
geos::io::WKTReader reader_;
test_length_data():
geom_(nullptr),
pm_(1),
factory_(GeometryFactory::create(&pm_, 0)), reader_(factory_.get())
{
assert(nullptr == geom_);
}
~test_length_data()
{
factory_->destroyGeometry(geom_);
geom_ = nullptr;
}
void
checkLengthOfLine(std::string wkt, double expectedLength)
{
auto line = reader_.read<LineString>(wkt);
ensure(nullptr != line.get());
const CoordinateSequence* lineSeq = line->getCoordinatesRO();
double actual = algorithm::Length::ofLine(lineSeq);
ensure_equals(actual, expectedLength);
}
};
// void checkLengthOfLine(String wkt, double expectedLen) {
// LineString ring = (LineString) read(wkt);
// CoordinateSequence pts = ring.getCoordinateSequence();
// double actual = Length.ofLine(pts);
// assertEquals(actual, expectedLen);
// }
typedef test_group<test_length_data> group;
typedef group::object object;
group test_length_group("geos::algorithm::Length");
//
// Test Cases
//
template<>
template<>
void object::test<1>
()
{
checkLengthOfLine("LINESTRING (100 200, 200 200, 200 100, 100 100, 100 200)", 400.0);
}
} // namespace tut
|