1
// $Id: ConvexHullTest.cpp 1993 2007-06-10 11:53:49Z mloskot $
3
// Test Suite for geos::algorithm::ConvexHull
4
// Ported from JTS junit/algorithm/ConvexHullTest.java
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>
29
using namespace geos::geom; // for Location
37
// dummy data, not used
38
struct test_convexhull_data
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;
44
geos::geom::PrecisionModel pm_;
45
geos::geom::GeometryFactory factory_;
46
geos::io::WKTReader reader_;
48
test_convexhull_data()
49
: pm_(1), factory_(&pm_, 0), reader_(&factory_)
53
typedef test_group<test_convexhull_data> group;
54
typedef group::object object;
56
group test_convexhull_group("geos::algorithm::ConvexHull");
62
// 1 - Test convex hull of linestring
65
void object::test<1>()
67
using geos::geom::LineString;
68
using utility::dynamic_cast_auto_ptr;
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());
74
GeometryAPtr hullGeom(reader_.read("LINESTRING (30 220, 240 220)"));
75
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
76
ensure(0 != convexHull.get());
78
ensure( convexHull->equalsExact(line->convexHull()) );
81
// 2 - Test convex hull of multipoint
84
void object::test<2>()
86
using geos::geom::LineString;
87
using utility::dynamic_cast_auto_ptr;
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());
92
GeometryAPtr hullGeom(reader_.read("LINESTRING (130 240, 650 240)"));
93
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
94
ensure(0 != convexHull.get());
96
ensure( convexHull->equalsExact(geom->convexHull()) );
99
// 3 - Test convex hull of multipoint
102
void object::test<3>()
104
using geos::geom::LineString;
105
using utility::dynamic_cast_auto_ptr;
107
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 10 0)"));
108
ensure(0 != geom.get());
110
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
111
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
112
ensure(0 != convexHull.get());
114
ensure( convexHull->equalsExact(geom->convexHull()) );
117
// 4 - Test convex hull of multipoint
120
void object::test<4>()
122
using geos::geom::LineString;
123
using utility::dynamic_cast_auto_ptr;
125
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 10 0, 10 0)"));
126
ensure(0 != geom.get());
128
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
129
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
130
ensure(0 != convexHull.get());
132
ensure( convexHull->equalsExact(geom->convexHull()) );
135
// 5 - Test convex hull of multipoint
138
void object::test<5>()
140
using geos::geom::LineString;
141
using utility::dynamic_cast_auto_ptr;
143
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 0, 10 0)"));
144
ensure(0 != geom.get());
146
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
147
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
148
ensure(0 != convexHull.get());
150
ensure( convexHull->equalsExact(geom->convexHull()) );
153
// 6 - Test convex hull of multipoint exported to string form
156
void object::test<6>()
158
using geos::geom::LineString;
159
using utility::dynamic_cast_auto_ptr;
161
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 1, 10 0)"));
162
ensure(0 != geom.get());
164
GeometryAPtr hullGeom(geom->convexHull());
165
ensure(0 != hullGeom.get());
167
GeometryAPtr expectedHull(reader_.read("POLYGON ((0 0, 5 1, 10 0, 0 0))"));
168
ensure(0 != expectedHull.get());
170
ensure_equals( hullGeom->toString(), expectedHull->toString() );
173
// 7 - Test convex hull of multipoint
176
void object::test<7>()
178
using geos::geom::LineString;
179
using utility::dynamic_cast_auto_ptr;
181
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 5 0, 5 0, 10 0, 10 0)"));
182
ensure(0 != geom.get());
184
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
185
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
186
ensure(0 != convexHull.get());
188
ensure( convexHull->equalsExact(geom->convexHull()) );
1
// $Id: ConvexHullTest.cpp 2167 2008-08-19 00:18:04Z mloskot $
3
// Test Suite for geos::algorithm::ConvexHull
4
// Ported from JTS junit/algorithm/ConvexHullTest.java
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>
30
using namespace geos::geom; // for Location
38
// dummy data, not used
39
struct test_convexhull_data
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;
46
geos::geom::PrecisionModel pm_;
47
geos::geom::GeometryFactory factory_;
48
geos::io::WKTReader reader_;
50
test_convexhull_data()
51
: geom_(0), pm_(1), factory_(&pm_, 0), reader_(&factory_)
56
~test_convexhull_data()
58
factory_.destroyGeometry(geom_);
63
typedef test_group<test_convexhull_data> group;
64
typedef group::object object;
66
group test_convexhull_group("geos::algorithm::ConvexHull");
72
// 1 - Test convex hull of linestring
75
void object::test<1>()
77
using geos::geom::LineString;
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());
83
GeometryAPtr hullGeom(reader_.read("LINESTRING (30 220, 240 220)"));
84
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
85
ensure(0 != convexHull.get());
87
geom_ = line->convexHull();
88
ensure( convexHull->equalsExact(geom_) );
91
// 2 - Test convex hull of multipoint
94
void object::test<2>()
96
using geos::geom::LineString;
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());
101
GeometryAPtr hullGeom(reader_.read("LINESTRING (130 240, 650 240)"));
102
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
103
ensure(0 != convexHull.get());
105
geom_ = geom->convexHull();
106
ensure( convexHull->equalsExact(geom_) );
109
// 3 - Test convex hull of multipoint
112
void object::test<3>()
114
using geos::geom::LineString;
116
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 10 0)"));
117
ensure(0 != geom.get());
119
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
120
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
121
ensure(0 != convexHull.get());
123
geom_ = geom->convexHull();
124
ensure( convexHull->equalsExact(geom_) );
127
// 4 - Test convex hull of multipoint
130
void object::test<4>()
132
using geos::geom::LineString;
134
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 10 0, 10 0)"));
135
ensure(0 != geom.get());
137
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
138
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
139
ensure(0 != convexHull.get());
141
geom_ = geom->convexHull();
142
ensure( convexHull->equalsExact(geom_) );
145
// 5 - Test convex hull of multipoint
148
void object::test<5>()
150
using geos::geom::LineString;
152
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 0, 10 0)"));
153
ensure(0 != geom.get());
155
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
156
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
157
ensure(0 != convexHull.get());
159
geom_ = geom->convexHull();
160
ensure( convexHull->equalsExact(geom_) );
163
// 6 - Test convex hull of multipoint exported to string form
166
void object::test<6>()
168
using geos::geom::LineString;
170
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 1, 10 0)"));
171
ensure(0 != geom.get());
173
GeometryAPtr hullGeom(geom->convexHull());
174
ensure(0 != hullGeom.get());
176
GeometryAPtr expectedHull(reader_.read("POLYGON ((0 0, 5 1, 10 0, 0 0))"));
177
ensure(0 != expectedHull.get());
179
ensure_equals( hullGeom->toString(), expectedHull->toString() );
182
// 7 - Test convex hull of multipoint
185
void object::test<7>()
187
using geos::geom::LineString;
189
GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 5 0, 5 0, 10 0, 10 0)"));
190
ensure(0 != geom.get());
192
GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
193
LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
194
ensure(0 != convexHull.get());
196
geom_ = geom->convexHull();
197
ensure( convexHull->equalsExact(geom_) );