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
|
//
// Test Suite for Area::ofRingSigned() function
// tut
#include <tut/tut.hpp>
// geos
#include <geos/algorithm/Area.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/Coordinate.h>
#include <geos/io/WKTReader.h>
#include <geos/io/WKBReader.h>
// std
#include <string>
#include <memory>
#include <cassert>
using namespace geos::algorithm;
namespace tut {
//
// Test Group
//
struct test_signedarea_data {
typedef std::unique_ptr<geos::geom::Geometry> GeometryPtr;
std::unique_ptr<geos::geom::CoordinateSequence> cs_;
geos::io::WKTReader reader_;
geos::io::WKBReader breader_;
test_signedarea_data()
: cs_(nullptr)
{
assert(nullptr == cs_);
}
~test_signedarea_data()
{
}
};
typedef test_group<test_signedarea_data> group;
typedef group::object object;
group test_signedarea_group("geos::algorithm::CGAlgorithms::signedArea");
//
// Test Cases
//
// 1 - clockwise oriented
template<>
template<>
void object::test<1>
()
{
const std::string wkt("POLYGON ((60 180, 140 240, 140 240, 140 240, 200 180, 120 120, 60 180))");
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
double area = Area::ofRingSigned(cs_.get());
ensure_equals(area, 8400);
}
// 2 - counter-clockwise oriented
template<>
template<>
void object::test<2>
()
{
const std::string wkt("POLYGON ((60 180, 140 120, 100 180, 140 240, 60 180))");
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
double area = Area::ofRingSigned(cs_.get());
ensure_equals(area, -2400);
}
// 3 - Test the same polygon as in test No 2 but with duplicated top point
template<>
template<>
void object::test<3>
()
{
const std::string wkt("POLYGON ((60 180, 140 120, 100 180, 140 240, 140 240, 60 180))");
GeometryPtr geom(reader_.read(wkt));
cs_ = geom->getCoordinates();
double area = Area::ofRingSigned(cs_.get());
ensure_equals(area, -2400);
}
} // namespace tut
|