File: GEOSMinimumRotatedRectangleTest.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (133 lines) | stat: -rw-r--r-- 2,839 bytes parent folder | download
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
//
// Test Suite for C-API GEOSMinimumRotatedRectangle

#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_minimumrotatedrectangle_data : public capitest::utility {
    test_minimumrotatedrectangle_data() {
        GEOSWKTWriter_setRoundingPrecision(wktw_, 8);
    }

    void checkMinRectangle(const char* wkt, const char* expected)
    {
        // input
        geom1_ = GEOSGeomFromWKT(wkt);
        ensure(nullptr != geom1_);
        GEOSSetSRID(geom1_, 1234);

        // result
        geom2_ = GEOSMinimumRotatedRectangle(geom1_);
        ensure(nullptr != geom2_);
        ensure("SRID equal", GEOSGetSRID(geom2_) == GEOSGetSRID(geom1_));

        // expected
        if (expected) {
            geom3_ = GEOSGeomFromWKT(expected);
            ensure(nullptr != geom3_);
            ensure_geometry_equals(geom2_, geom3_, 0.0001);
        }
    }
};

typedef test_group<test_minimumrotatedrectangle_data> group;
typedef group::object object;

group test_capigeosminimumrotatedrectangle_group("capi::GEOSMinimumRotatedRectangle");

//
// Test Cases
//

template<>
template<>
void object::test<1>
()
{
    checkMinRectangle(  "POLYGON ((1 6, 6 11, 11 6, 6 1, 1 6))",
                        "POLYGON ((1 6, 6 11, 11 6, 6 1, 1 6))");
}

// zero-length
template<>
template<>
void object::test<2>
()
{
    checkMinRectangle("LINESTRING (1 1, 1 1)", "POINT (1 1)");
}

// Horizontal
template<>
template<>
void object::test<3>
()
{
    checkMinRectangle("LINESTRING (1 1, 3 1, 5 1, 7 1)", "LINESTRING (1 1, 7 1)");
}

// Vertical
template<>
template<>
void object::test<4>
()
{
    checkMinRectangle("LINESTRING (1 1, 1 4, 1 7, 1 9)", "LINESTRING (1 1, 1 9)");
}

// Bent Line
template<>
template<>
void object::test<5>
()
{
    checkMinRectangle(
        "LINESTRING (1 2, 3 8, 9 6)",
        "POLYGON ((1 2, 3 8, 9 6, 7 0, 1 2))");
}

// Failure case from https://trac.osgeo.org/postgis/ticket/5163
template<>
template<>
void object::test<6>
()
{
    checkMinRectangle(
        "LINESTRING(-99.48710639268086 34.79029839231914,-99.48370699999998 34.78689899963806,-99.48152167568102 34.784713675318976)",
        "POLYGON ((-99.48710639 34.79029839, -99.48710639 34.79029839, -99.48152168 34.78471368, -99.48152168 34.78471368, -99.48710639 34.79029839))"
        );
}

// Collection Input
template<>
template<>
void object::test<7>
()
{
    checkMinRectangle(
        "MULTILINESTRING ((1 2, 3 8, 9 6))",
        "POLYGON ((1 2, 3 8, 9 6, 7 0, 1 2))");
}

template<>
template<>
void object::test<8>
()
{
    input_ = fromWKT("CIRCULARSTRING (0 0, 1 1, 2 0)");
    ensure(input_);

    result_ = GEOSMinimumRotatedRectangle(input_);
    ensure("curved geometry not supported", result_ == nullptr);
}

} // namespace tut