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 178 179 180 181
|
//
// Test Suite for geos::algorithm::MinimumAreaRectangle
#include <tut/tut.hpp>
// geos
#include <geos/algorithm/MinimumAreaRectangle.h>
#include <geos/io/WKTReader.h>
#include <geos/geom/Geometry.h>
#include <utility.h>
// std
#include <string>
#include <memory>
using geos::algorithm::MinimumAreaRectangle;
using geos::io::WKTReader;
using geos::geom::Geometry;
namespace tut {
//
// Test Group
//
// dummy data, not used
struct test_minimumarearectangle_data {
const double TOL = 1e-10;
WKTReader reader_;
test_minimumarearectangle_data() {};
void
checkMinRectangle(const std::string& wkt, const std::string& wktExpected)
{
std::unique_ptr<Geometry> geom = reader_.read(wkt);
std::unique_ptr<Geometry> actual = MinimumAreaRectangle::getMinimumRectangle(geom.get());
std::unique_ptr<Geometry> expected = reader_.read(wktExpected);
ensure_equals_geometry(expected.get(), actual.get(), TOL);
}
};
typedef test_group<test_minimumarearectangle_data> group;
typedef group::object object;
group test_minimumarearectangle_group("geos::algorithm::MinimumAreaRectangle");
//
// Test Cases
//
// testEmpty
template<>
template<>
void object::test<1>()
{
checkMinRectangle(
"POLYGON EMPTY",
"POLYGON EMPTY");
}
// testLineLengthZero
template<>
template<>
void object::test<2>()
{
checkMinRectangle(
"LINESTRING (1 1, 1 1)",
"POINT (1 1)");
}
// testLineHorizontal
template<>
template<>
void object::test<3>()
{
checkMinRectangle(
"LINESTRING (1 1, 3 1, 5 1, 7 1)", "LINESTRING (1 1, 7 1)");
}
// testLineVertical
template<>
template<>
void object::test<4>()
{
checkMinRectangle(
"LINESTRING (1 1, 1 4, 1 7, 1 9)",
"LINESTRING (1 1, 1 9)");
}
// testLineObtuseAngle
template<>
template<>
void object::test<5>()
{
checkMinRectangle(
"LINESTRING (1 2, 3 8, 9 8)",
"POLYGON ((9 8, 1 2, -1.16 4.88, 6.84 10.88, 9 8))");
}
// testLineAcuteAngle
template<>
template<>
void object::test<6>()
{
checkMinRectangle(
"LINESTRING (5 2, 3 8, 9 8)",
"POLYGON ((5 2, 3 8, 8.4 9.8, 10.4 3.8, 5 2))");
}
// testNotMinDiameter
template<>
template<>
void object::test<7>()
{
checkMinRectangle(
"POLYGON ((150 300, 200 300, 300 300, 300 250, 280 120, 210 100, 100 100, 100 240, 150 300))",
"POLYGON ((100 100, 100 300, 300 300, 300 100, 100 100))");
}
// testTriangle
template<>
template<>
void object::test<8>()
{
checkMinRectangle(
"POLYGON ((100 100, 200 200, 160 240, 100 100))",
"POLYGON ((100 100, 160 240, 208.2758620689651 219.31034482758352, 148.2758620689666 79.31034482758756, 100 100))");
}
// testConvex
template<>
template<>
void object::test<9>()
{
checkMinRectangle("POLYGON ((3 8, 6 8, 9 5, 7 3, 3 1, 2 4, 3 8))",
"POLYGON ((0.2 6.6, 6.6 9.8, 9.4 4.2, 3 1, 0.2 6.6))");
}
/**
* Failure case from https://trac.osgeo.org/postgis/ticket/5163
* @throws Exception
*/
// testFlatDiagonal
template<>
template<>
void object::test<10>()
{
// bool error = false;
// try {
checkMinRectangle(
"LINESTRING(-99.48710639268086 34.79029839231914,-99.48370699999998 34.78689899963806,-99.48152167568102 34.784713675318976)",
"POLYGON ((-99.48710639268066 34.790298392318675, -99.48710639268066 34.790298392318675, -99.48152167568082 34.78471367531866, -99.48152167568082 34.78471367531866, -99.48710639268066 34.790298392318675))");
// } catch (std::exception& e) {
// error = true;
// // errorMessage = e.what();
// }
// ensure("caught exception", error == true);
}
// testBadRectl
template<>
template<>
void object::test<11>()
{
// bool error = false;
// try {
checkMinRectangle(
"POLYGON ((-5.21175 49.944633, -5.77435 50.021367, -5.7997 50.0306, -5.81815 50.0513, -5.82625 50.073567, -5.83085 50.1173, -6.2741 56.758767, -5.93245 57.909, -5.1158 58.644533, -5.07915 58.661733, -3.42575 58.686633, -3.1392 58.6685, -3.12495 58.666233, -1.88745 57.6444, 1.68845 52.715133, 1.7057 52.6829, 1.70915 52.6522, 1.7034 52.585433, 1.3867 51.214033, 1.36595 51.190267, 1.30485 51.121967, 0.96365 50.928567, 0.93025 50.912433, 0.1925 50.7436, -5.21175 49.944633))",
"POLYGON ((1.8583607388069103 50.41649058582797, -5.816631979932251 49.904263313964535, -6.395241388167441 58.57389735949991, 1.2797513305717105 59.08612463136336, 1.8583607388069103 50.41649058582797))");
// } catch (std::exception& e) {
// error = true;
// // errorMessage = e.what();
// }
// ensure("caught exception", error == true);
}
} // namespace tut
|