~sharpie/geos/3.3.2

« back to all changes in this revision

Viewing changes to tests/unit/algorithm/ConvexHullTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabio Tranchitella
  • Date: 2009-03-27 15:54:54 UTC
  • mfrom: (1.2.1 upstream) (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090327155454-o3u9j86rzrtcp5vl
Tags: 3.1.0-1
* New upstream release.
* This version includes also a missing header inclusion, which caused FTBFS
  on armel. (Closes: #520447)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: ConvexHullTest.cpp 1993 2007-06-10 11:53:49Z mloskot $
2
 
// 
3
 
// Test Suite for geos::algorithm::ConvexHull
4
 
// Ported from JTS junit/algorithm/ConvexHullTest.java
5
 
 
6
 
// tut
7
 
#include <tut.h>
8
 
#include <utility.h>
9
 
// geos
10
 
#include <geos/algorithm/ConvexHull.h>
11
 
#include <geos/geom/LineString.h>
12
 
#include <geos/geom/Coordinate.h>
13
 
#include <geos/geom/CoordinateArraySequence.h>
14
 
#include <geos/geom/Dimension.h>
15
 
#include <geos/geom/Geometry.h>
16
 
#include <geos/geom/GeometryFactory.h>
17
 
#include <geos/geom/PrecisionModel.h>
18
 
#include <geos/io/WKTReader.h>
19
 
// std
20
 
#include <sstream>
21
 
#include <memory>
22
 
 
23
 
namespace geos {
24
 
        namespace geom {
25
 
                class Geometry;
26
 
        }
27
 
}
28
 
 
29
 
using namespace geos::geom; // for Location
30
 
 
31
 
namespace tut
32
 
{
33
 
        //
34
 
        // Test Group
35
 
        //
36
 
 
37
 
        // dummy data, not used
38
 
        struct test_convexhull_data
39
 
    {
40
 
                // Typedefs used as short names by test cases
41
 
        typedef std::auto_ptr<geos::geom::Geometry> GeometryAPtr;
42
 
        typedef std::auto_ptr<geos::geom::LineString> LineStringAPtr;
43
 
 
44
 
        geos::geom::PrecisionModel pm_;
45
 
        geos::geom::GeometryFactory factory_;
46
 
        geos::io::WKTReader reader_;
47
 
 
48
 
        test_convexhull_data()
49
 
                        : pm_(1), factory_(&pm_, 0), reader_(&factory_)
50
 
        {}
51
 
    };
52
 
 
53
 
        typedef test_group<test_convexhull_data> group;
54
 
        typedef group::object object;
55
 
 
56
 
    group test_convexhull_group("geos::algorithm::ConvexHull");
57
 
 
58
 
        //
59
 
        // Test Cases
60
 
        //
61
 
 
62
 
        // 1 - Test convex hull of linestring
63
 
        template<>
64
 
    template<>
65
 
    void object::test<1>()
66
 
    {   
67
 
        using geos::geom::LineString;
68
 
        using utility::dynamic_cast_auto_ptr;
69
 
 
70
 
        GeometryAPtr lineGeom(reader_.read("LINESTRING (30 220, 240 220, 240 220)"));
71
 
        LineStringAPtr line(dynamic_cast_auto_ptr<LineString>(lineGeom));
72
 
        ensure(0 != line.get());
73
 
 
74
 
        GeometryAPtr hullGeom(reader_.read("LINESTRING (30 220, 240 220)"));
75
 
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
76
 
        ensure(0 != convexHull.get());
77
 
 
78
 
        ensure( convexHull->equalsExact(line->convexHull()) );
79
 
    }
80
 
 
81
 
        // 2 - Test convex hull of multipoint
82
 
        template<>
83
 
    template<>
84
 
    void object::test<2>()
85
 
    {   
86
 
        using geos::geom::LineString;
87
 
        using utility::dynamic_cast_auto_ptr;
88
 
 
89
 
        GeometryAPtr geom(reader_.read("MULTIPOINT (130 240, 130 240, 130 240, 570 240, 570 240, 570 240, 650 240)"));
90
 
        ensure(0 != geom.get());
91
 
 
92
 
        GeometryAPtr hullGeom(reader_.read("LINESTRING (130 240, 650 240)"));
93
 
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
94
 
        ensure(0 != convexHull.get());
95
 
 
96
 
        ensure( convexHull->equalsExact(geom->convexHull()) );
97
 
    }
98
 
 
99
 
        // 3 - Test convex hull of multipoint
100
 
        template<>
101
 
    template<>
102
 
    void object::test<3>()
103
 
    {   
104
 
        using geos::geom::LineString;
105
 
        using utility::dynamic_cast_auto_ptr;
106
 
 
107
 
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 10 0)"));
108
 
        ensure(0 != geom.get());
109
 
 
110
 
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
111
 
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
112
 
        ensure(0 != convexHull.get());
113
 
 
114
 
        ensure( convexHull->equalsExact(geom->convexHull()) );
115
 
    }
116
 
                      
117
 
        // 4 - Test convex hull of multipoint
118
 
        template<>
119
 
    template<>
120
 
    void object::test<4>()
121
 
    {   
122
 
        using geos::geom::LineString;
123
 
        using utility::dynamic_cast_auto_ptr;
124
 
 
125
 
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 10 0, 10 0)"));
126
 
        ensure(0 != geom.get());
127
 
 
128
 
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
129
 
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
130
 
        ensure(0 != convexHull.get());
131
 
 
132
 
        ensure( convexHull->equalsExact(geom->convexHull()) );
133
 
    }
134
 
 
135
 
        // 5 - Test convex hull of multipoint
136
 
        template<>
137
 
    template<>
138
 
    void object::test<5>()
139
 
    {   
140
 
        using geos::geom::LineString;
141
 
        using utility::dynamic_cast_auto_ptr;
142
 
 
143
 
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 0, 10 0)"));
144
 
        ensure(0 != geom.get());
145
 
 
146
 
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
147
 
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
148
 
        ensure(0 != convexHull.get());
149
 
 
150
 
        ensure( convexHull->equalsExact(geom->convexHull()) );
151
 
    }
152
 
 
153
 
        // 6 - Test convex hull of multipoint exported to string form
154
 
        template<>
155
 
    template<>
156
 
    void object::test<6>()
157
 
    {   
158
 
        using geos::geom::LineString;
159
 
        using utility::dynamic_cast_auto_ptr;
160
 
 
161
 
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 1, 10 0)"));
162
 
        ensure(0 != geom.get());
163
 
 
164
 
        GeometryAPtr hullGeom(geom->convexHull());
165
 
        ensure(0 != hullGeom.get());
166
 
 
167
 
        GeometryAPtr expectedHull(reader_.read("POLYGON ((0 0, 5 1, 10 0, 0 0))"));
168
 
        ensure(0 != expectedHull.get());
169
 
 
170
 
        ensure_equals( hullGeom->toString(), expectedHull->toString() );
171
 
    }
172
 
 
173
 
        // 7 - Test convex hull of multipoint
174
 
        template<>
175
 
    template<>
176
 
    void object::test<7>()
177
 
    {   
178
 
        using geos::geom::LineString;
179
 
        using utility::dynamic_cast_auto_ptr;
180
 
 
181
 
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 5 0, 5 0, 10 0, 10 0)"));
182
 
        ensure(0 != geom.get());
183
 
 
184
 
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
185
 
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
186
 
        ensure(0 != convexHull.get());
187
 
 
188
 
        ensure( convexHull->equalsExact(geom->convexHull()) );
189
 
    }
190
 
 
191
 
} // namespace tut
 
1
// $Id: ConvexHullTest.cpp 2167 2008-08-19 00:18:04Z mloskot $
 
2
// 
 
3
// Test Suite for geos::algorithm::ConvexHull
 
4
// Ported from JTS junit/algorithm/ConvexHullTest.java
 
5
 
 
6
// geos
 
7
#include <geos/algorithm/ConvexHull.h>
 
8
#include <geos/geom/LineString.h>
 
9
#include <geos/geom/Coordinate.h>
 
10
#include <geos/geom/CoordinateArraySequence.h>
 
11
#include <geos/geom/Dimension.h>
 
12
#include <geos/geom/Geometry.h>
 
13
#include <geos/geom/GeometryFactory.h>
 
14
#include <geos/geom/PrecisionModel.h>
 
15
#include <geos/io/WKTReader.h>
 
16
// std
 
17
#include <sstream>
 
18
#include <memory>
 
19
#include <cassert>
 
20
// tut
 
21
#include <tut.h>
 
22
#include <utility.h>
 
23
 
 
24
namespace geos {
 
25
        namespace geom {
 
26
                class Geometry;
 
27
        }
 
28
}
 
29
 
 
30
using namespace geos::geom; // for Location
 
31
 
 
32
namespace tut
 
33
{
 
34
        //
 
35
        // Test Group
 
36
        //
 
37
 
 
38
        // dummy data, not used
 
39
        struct test_convexhull_data
 
40
    {
 
41
                // Typedefs used as short names by test cases
 
42
        typedef std::auto_ptr<geos::geom::Geometry> GeometryAPtr;
 
43
        typedef std::auto_ptr<geos::geom::LineString> LineStringAPtr;
 
44
 
 
45
        GeometryPtr geom_;
 
46
        geos::geom::PrecisionModel pm_;
 
47
        geos::geom::GeometryFactory factory_;
 
48
        geos::io::WKTReader reader_;
 
49
 
 
50
        test_convexhull_data()
 
51
                        : geom_(0), pm_(1), factory_(&pm_, 0), reader_(&factory_)
 
52
        {
 
53
            assert(0 == geom_);
 
54
        }
 
55
 
 
56
        ~test_convexhull_data()
 
57
        {
 
58
            factory_.destroyGeometry(geom_);
 
59
            geom_ = 0;
 
60
        }
 
61
    };
 
62
 
 
63
        typedef test_group<test_convexhull_data> group;
 
64
        typedef group::object object;
 
65
 
 
66
    group test_convexhull_group("geos::algorithm::ConvexHull");
 
67
 
 
68
        //
 
69
        // Test Cases
 
70
        //
 
71
 
 
72
        // 1 - Test convex hull of linestring
 
73
        template<>
 
74
    template<>
 
75
    void object::test<1>()
 
76
    {   
 
77
        using geos::geom::LineString;
 
78
 
 
79
        GeometryAPtr lineGeom(reader_.read("LINESTRING (30 220, 240 220, 240 220)"));
 
80
        LineStringAPtr line(dynamic_cast_auto_ptr<LineString>(lineGeom));
 
81
        ensure(0 != line.get());
 
82
 
 
83
        GeometryAPtr hullGeom(reader_.read("LINESTRING (30 220, 240 220)"));
 
84
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
 
85
        ensure(0 != convexHull.get());
 
86
 
 
87
        geom_ = line->convexHull();
 
88
        ensure( convexHull->equalsExact(geom_) );
 
89
    }
 
90
 
 
91
        // 2 - Test convex hull of multipoint
 
92
        template<>
 
93
    template<>
 
94
    void object::test<2>()
 
95
    {   
 
96
        using geos::geom::LineString;
 
97
 
 
98
        GeometryAPtr geom(reader_.read("MULTIPOINT (130 240, 130 240, 130 240, 570 240, 570 240, 570 240, 650 240)"));
 
99
        ensure(0 != geom.get());
 
100
 
 
101
        GeometryAPtr hullGeom(reader_.read("LINESTRING (130 240, 650 240)"));
 
102
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
 
103
        ensure(0 != convexHull.get());
 
104
 
 
105
        geom_ = geom->convexHull();
 
106
        ensure( convexHull->equalsExact(geom_) );
 
107
    }
 
108
 
 
109
        // 3 - Test convex hull of multipoint
 
110
        template<>
 
111
    template<>
 
112
    void object::test<3>()
 
113
    {   
 
114
        using geos::geom::LineString;
 
115
 
 
116
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 10 0)"));
 
117
        ensure(0 != geom.get());
 
118
 
 
119
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
 
120
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
 
121
        ensure(0 != convexHull.get());
 
122
 
 
123
        geom_ = geom->convexHull();
 
124
        ensure( convexHull->equalsExact(geom_) );
 
125
    }
 
126
                      
 
127
        // 4 - Test convex hull of multipoint
 
128
        template<>
 
129
    template<>
 
130
    void object::test<4>()
 
131
    {   
 
132
        using geos::geom::LineString;
 
133
 
 
134
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 10 0, 10 0)"));
 
135
        ensure(0 != geom.get());
 
136
 
 
137
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
 
138
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
 
139
        ensure(0 != convexHull.get());
 
140
 
 
141
        geom_ = geom->convexHull();
 
142
        ensure( convexHull->equalsExact(geom_) );
 
143
    }
 
144
 
 
145
        // 5 - Test convex hull of multipoint
 
146
        template<>
 
147
    template<>
 
148
    void object::test<5>()
 
149
    {   
 
150
        using geos::geom::LineString;
 
151
 
 
152
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 0, 10 0)"));
 
153
        ensure(0 != geom.get());
 
154
 
 
155
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
 
156
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
 
157
        ensure(0 != convexHull.get());
 
158
 
 
159
        geom_ = geom->convexHull();
 
160
        ensure( convexHull->equalsExact(geom_) );
 
161
    }
 
162
 
 
163
        // 6 - Test convex hull of multipoint exported to string form
 
164
        template<>
 
165
    template<>
 
166
    void object::test<6>()
 
167
    {   
 
168
        using geos::geom::LineString;
 
169
 
 
170
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 1, 10 0)"));
 
171
        ensure(0 != geom.get());
 
172
 
 
173
        GeometryAPtr hullGeom(geom->convexHull());
 
174
        ensure(0 != hullGeom.get());
 
175
 
 
176
        GeometryAPtr expectedHull(reader_.read("POLYGON ((0 0, 5 1, 10 0, 0 0))"));
 
177
        ensure(0 != expectedHull.get());
 
178
 
 
179
        ensure_equals( hullGeom->toString(), expectedHull->toString() );
 
180
    }
 
181
 
 
182
        // 7 - Test convex hull of multipoint
 
183
        template<>
 
184
    template<>
 
185
    void object::test<7>()
 
186
    {   
 
187
        using geos::geom::LineString;
 
188
 
 
189
        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 5 0, 5 0, 10 0, 10 0)"));
 
190
        ensure(0 != geom.get());
 
191
 
 
192
        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
 
193
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
 
194
        ensure(0 != convexHull.get());
 
195
 
 
196
        geom_ = geom->convexHull();
 
197
        ensure( convexHull->equalsExact(geom_) );
 
198
    }
 
199
 
 
200
} // namespace tut
 
201