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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
//
// Test Suite for C-API GEOSintersection
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include "capi_test_utils.h"
namespace tut {
//
// Test Group
//
// Common data used in test cases.
struct test_capigeosintersectionprec_data : public capitest::utility {
test_capigeosintersectionprec_data() {
}
static int
same(GEOSGeometry* g1, GEOSGeometry* g2, double tolerance)
{
GEOSNormalize(g1);
GEOSNormalize(g2);
return GEOSEqualsExact(g1, g2, tolerance);
}
};
typedef test_group<test_capigeosintersectionprec_data> group;
typedef group::object object;
group test_capigeosintersectionprec_group("capi::GEOSIntersectionPrec");
//
// Test Cases
//
template<>
template<>
void object::test<1>
()
{
geom1_ = GEOSGeomFromWKT("POLYGON EMPTY");
geom2_ = GEOSGeomFromWKT("POLYGON EMPTY");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 0);
ensure(nullptr != geom3_);
ensure_equals(toWKT(geom3_), std::string("POLYGON EMPTY"));
}
template<>
template<>
void object::test<2>
()
{
geom1_ = GEOSGeomFromWKT("POLYGON((1 1,1 5,5 5,5 1,1 1))");
geom2_ = GEOSGeomFromWKT("POINT(2 2)");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 0);
ensure(nullptr != geom3_);
ensure_equals(toWKT(geom3_), std::string("POINT (2 2)"));
}
template<>
template<>
void object::test<3>
()
{
geom1_ = GEOSGeomFromWKT("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)))");
geom2_ = GEOSGeomFromWKT("POLYGON((-1 1,-1 2,2 2,2 1,-1 1))");
expected_ = GEOSGeomFromWKT("POLYGON ((0 1, 0 2, 2 2, 2 1, 0 1))");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 0);
ensure(nullptr != geom3_);
ensure(same(geom3_, expected_, 0.1));
}
/* See http://trac.osgeo.org/geos/ticket/719 */
template<>
template<>
void object::test<4>
()
{
geom1_ = GEOSGeomFromWKT("MULTIPOLYGON(((0 0,5 10,10 0,0 0),(1 1,1 2,2 2,2 1,1 1),(100 100,100 102,102 102,102 100,100 100)))");
geom2_ = GEOSGeomFromWKT("POLYGON((0 1,0 2,10 2,10 1,0 1))");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 0);
GEOSNormalize(geom3_);
ensure(nullptr != geom3_);
expected_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION (LINESTRING (1 2, 2 2), LINESTRING (2 1, 1 1), POLYGON ((0.5 1, 1 2, 1 1, 0.5 1)), POLYGON ((9 2, 9.5 1, 2 1, 2 2, 9 2)))");
GEOSNormalize(expected_);
ensure(GEOSEqualsExact(expected_, geom3_, 0.00001));
}
template<>
template<>
void object::test<5>
()
{
geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0)");
geom2_ = GEOSGeomFromWKT("LINESTRING(0 1, 10 1)");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 0);
ensure(nullptr != geom3_);
ensure_equals(toWKT(geom3_), std::string("LINESTRING EMPTY"));
}
template<>
template<>
void object::test<6>
()
{
geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0)");
geom2_ = GEOSGeomFromWKT("LINESTRING(0 1, 10 1)");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 10);
ensure(nullptr != geom3_);
ensure_equals(toWKT(geom3_), std::string("LINESTRING (0 0, 10 0)"));
}
template<>
template<>
void object::test<7>
()
{
geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0)");
geom2_ = GEOSGeomFromWKT("LINESTRING(0 1, 10 0)");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 0);
ensure(nullptr != geom3_);
ensure_equals(toWKT(geom3_), std::string("POINT (10 0)"));
}
template<>
template<>
void object::test<8>
()
{
geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 10 0)");
geom2_ = GEOSGeomFromWKT("LINESTRING(9 0, 12 0, 12 20, 4 0, 2 0, 2 10, 0 10, 0 -10)");
ensure(nullptr != geom1_);
ensure(nullptr != geom2_);
geom3_ = GEOSIntersectionPrec(geom1_, geom2_, 2);
ensure(nullptr != geom3_);
ensure_geometry_equals(geom3_, "GEOMETRYCOLLECTION (LINESTRING (2 0, 4 0), POINT (0 0), POINT (10 0))");
}
} // namespace tut
|