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
|
// $Id$
//
// Test Suite for C-API GEOSGetCentroid
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
// std
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "capi_test_utils.h"
namespace tut {
//
// Test Group
//
// Common data used in test cases.
struct test_capiminimumboundingcircle_data : public capitest::utility {
test_capiminimumboundingcircle_data()
{
GEOSWKTWriter_setRoundingPrecision(wktw_, 8);
}
};
typedef test_group<test_capiminimumboundingcircle_data> group;
typedef group::object object;
group test_capiminimumboundingcircle_group("capi::GEOSMinimumBoundingCircle");
//
// Test Cases
//
// Single point
template<>
template<>
void object::test<1>
()
{
geom1_ = GEOSGeomFromWKT("POINT(10 10)");
ensure(nullptr != geom1_);
geom2_ = GEOSMinimumBoundingCircle(geom1_, NULL, NULL);
ensure(nullptr != geom2_);
wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
ensure_equals(std::string(wkt_), std::string("POINT (10 10)"));
}
template<>
template<>
void object::test<2>
()
{
geom1_ = GEOSGeomFromWKT("LINESTRING(0 10, 0 20)");
ensure(nullptr != geom1_);
geom2_ = GEOSMinimumBoundingCircle(geom1_, NULL, NULL);
ensure(nullptr != geom2_);
geom3_ = GEOSGeomFromWKT("POLYGON ((5 15, 4.9039264 14.024548, 4.6193977 13.086583, 4.1573481 12.222149, 3.5355339 11.464466, 2.7778512 10.842652, 1.9134172 10.380602, 0.97545161 10.096074, 8.0777229e-15 10, -0.97545161 10.096074, -1.9134172 10.380602, -2.7778512 10.842652, -3.5355339 11.464466, -4.1573481 12.222149, -4.6193977 13.086583, -4.9039264 14.024548, -5 15, -4.9039264 15.975452, -4.6193977 16.913417, -4.1573481 17.777851, -3.5355339 18.535534, -2.7778512 19.157348, -1.9134172 19.619398, -0.97545161 19.903926, -1.8682053e-14 20, 0.97545161 19.903926, 1.9134172 19.619398, 2.7778512 19.157348, 3.5355339 18.535534, 4.1573481 17.777851, 4.6193977 16.913417, 4.9039264 15.975452, 5 15))");
ensure(nullptr != geom3_);
// wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
bool eq = GEOSEqualsExact(geom2_, geom3_, 0.0001) != 0;
ensure(eq);
}
template<>
template<>
void object::test<3>
()
{
geom1_ = GEOSGeomFromWKT("LINESTRING EMPTY");
ensure(nullptr != geom1_);
result_ = GEOSMinimumBoundingCircle(geom1_, NULL, NULL);
ensure(nullptr != result_);
expected_ = GEOSGeomFromWKT("POLYGON EMPTY");
ensure(nullptr != expected_);
bool eq = GEOSEqualsExact(result_, expected_, 0.0001) != 0;
ensure(eq);
}
template<>
template<>
void object::test<4>
()
{
GEOSGeometry* center;
GEOSGeometry* center_expected;
double radius;
geom1_ = GEOSGeomFromWKT("LINESTRING(0 10, 0 20)");
ensure(nullptr != geom1_);
geom2_ = GEOSMinimumBoundingCircle(geom1_, &radius, ¢er);
ensure(nullptr != geom2_);
geom3_ = GEOSGeomFromWKT("POLYGON ((5 15, 4.9039264 14.024548, 4.6193977 13.086583, 4.1573481 12.222149, 3.5355339 11.464466, 2.7778512 10.842652, 1.9134172 10.380602, 0.97545161 10.096074, 8.0777229e-15 10, -0.97545161 10.096074, -1.9134172 10.380602, -2.7778512 10.842652, -3.5355339 11.464466, -4.1573481 12.222149, -4.6193977 13.086583, -4.9039264 14.024548, -5 15, -4.9039264 15.975452, -4.6193977 16.913417, -4.1573481 17.777851, -3.5355339 18.535534, -2.7778512 19.157348, -1.9134172 19.619398, -0.97545161 19.903926, -1.8682053e-14 20, 0.97545161 19.903926, 1.9134172 19.619398, 2.7778512 19.157348, 3.5355339 18.535534, 4.1573481 17.777851, 4.6193977 16.913417, 4.9039264 15.975452, 5 15))");
ensure(nullptr != geom3_);
center_expected = GEOSGeomFromWKT("POINT(0 15)");
// wkt_ = GEOSWKTWriter_write(wktw_, geom2_);
// std::cout << wkt_ << std::endl;
bool eq;
eq = GEOSEqualsExact(geom2_, geom3_, 0.0001) != 0;
ensure(eq);
eq = GEOSEqualsExact(center, center_expected, 0.0001) != 0;
ensure(eq);
GEOSGeom_destroy(center);
GEOSGeom_destroy(center_expected);
ensure(fabs(radius) - 5.0 < 0.001);
}
template<>
template<>
void object::test<5>
()
{
input_ = fromWKT("CIRCULARSTRING (0 0, 1 1, 2 0)");
ensure(input_);
GEOSGeometry* center;
double radius;
result_ = GEOSMinimumBoundingCircle(input_, &radius, ¢er);
ensure("curved geometry not supported", result_ == nullptr);
}
} // namespace tut
|