File: ConvexHullTest.cpp

package info (click to toggle)
geos 3.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 10,060 kB
  • ctags: 8,674
  • sloc: cpp: 64,513; xml: 23,384; sh: 8,965; ruby: 1,295; makefile: 1,124; python: 824; ansic: 289
file content (191 lines) | stat: -rw-r--r-- 5,697 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
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
182
183
184
185
186
187
188
189
190
191
// $Id: ConvexHullTest.cpp 1993 2007-06-10 11:53:49Z mloskot $
// 
// Test Suite for geos::algorithm::ConvexHull
// Ported from JTS junit/algorithm/ConvexHullTest.java

// tut
#include <tut.h>
#include <utility.h>
// geos
#include <geos/algorithm/ConvexHull.h>
#include <geos/geom/LineString.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateArraySequence.h>
#include <geos/geom/Dimension.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/PrecisionModel.h>
#include <geos/io/WKTReader.h>
// std
#include <sstream>
#include <memory>

namespace geos {
	namespace geom {
		class Geometry;
	}
}

using namespace geos::geom; // for Location

namespace tut
{
	//
	// Test Group
	//

	// dummy data, not used
	struct test_convexhull_data
    {
		// Typedefs used as short names by test cases
        typedef std::auto_ptr<geos::geom::Geometry> GeometryAPtr;
        typedef std::auto_ptr<geos::geom::LineString> LineStringAPtr;

        geos::geom::PrecisionModel pm_;
        geos::geom::GeometryFactory factory_;
        geos::io::WKTReader reader_;

        test_convexhull_data()
			: pm_(1), factory_(&pm_, 0), reader_(&factory_)
        {}
    };

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

    group test_convexhull_group("geos::algorithm::ConvexHull");

	//
	// Test Cases
	//

	// 1 - Test convex hull of linestring
	template<>
    template<>
    void object::test<1>()
    {   
        using geos::geom::LineString;
        using utility::dynamic_cast_auto_ptr;

        GeometryAPtr lineGeom(reader_.read("LINESTRING (30 220, 240 220, 240 220)"));
        LineStringAPtr line(dynamic_cast_auto_ptr<LineString>(lineGeom));
        ensure(0 != line.get());

        GeometryAPtr hullGeom(reader_.read("LINESTRING (30 220, 240 220)"));
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
        ensure(0 != convexHull.get());

        ensure( convexHull->equalsExact(line->convexHull()) );
    }

	// 2 - Test convex hull of multipoint
	template<>
    template<>
    void object::test<2>()
    {   
        using geos::geom::LineString;
        using utility::dynamic_cast_auto_ptr;

        GeometryAPtr geom(reader_.read("MULTIPOINT (130 240, 130 240, 130 240, 570 240, 570 240, 570 240, 650 240)"));
        ensure(0 != geom.get());

        GeometryAPtr hullGeom(reader_.read("LINESTRING (130 240, 650 240)"));
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
        ensure(0 != convexHull.get());

        ensure( convexHull->equalsExact(geom->convexHull()) );
    }

	// 3 - Test convex hull of multipoint
	template<>
    template<>
    void object::test<3>()
    {   
        using geos::geom::LineString;
        using utility::dynamic_cast_auto_ptr;

        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 10 0)"));
        ensure(0 != geom.get());

        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
        ensure(0 != convexHull.get());

        ensure( convexHull->equalsExact(geom->convexHull()) );
    }
		      
	// 4 - Test convex hull of multipoint
	template<>
    template<>
    void object::test<4>()
    {   
        using geos::geom::LineString;
        using utility::dynamic_cast_auto_ptr;

        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 10 0, 10 0)"));
        ensure(0 != geom.get());

        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
        ensure(0 != convexHull.get());

        ensure( convexHull->equalsExact(geom->convexHull()) );
    }

	// 5 - Test convex hull of multipoint
	template<>
    template<>
    void object::test<5>()
    {   
        using geos::geom::LineString;
        using utility::dynamic_cast_auto_ptr;

        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 0, 10 0)"));
        ensure(0 != geom.get());

        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
        ensure(0 != convexHull.get());

        ensure( convexHull->equalsExact(geom->convexHull()) );
    }

	// 6 - Test convex hull of multipoint exported to string form
	template<>
    template<>
    void object::test<6>()
    {   
        using geos::geom::LineString;
        using utility::dynamic_cast_auto_ptr;

        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 5 1, 10 0)"));
        ensure(0 != geom.get());

        GeometryAPtr hullGeom(geom->convexHull());
        ensure(0 != hullGeom.get());

        GeometryAPtr expectedHull(reader_.read("POLYGON ((0 0, 5 1, 10 0, 0 0))"));
        ensure(0 != expectedHull.get());

        ensure_equals( hullGeom->toString(), expectedHull->toString() );
    }

	// 7 - Test convex hull of multipoint
	template<>
    template<>
    void object::test<7>()
    {   
        using geos::geom::LineString;
        using utility::dynamic_cast_auto_ptr;

        GeometryAPtr geom(reader_.read("MULTIPOINT (0 0, 0 0, 5 0, 5 0, 10 0, 10 0)"));
        ensure(0 != geom.get());

        GeometryAPtr hullGeom(reader_.read("LINESTRING (0 0, 10 0)"));
        LineStringAPtr convexHull(dynamic_cast_auto_ptr<LineString>(hullGeom));
        ensure(0 != convexHull.get());

        ensure( convexHull->equalsExact(geom->convexHull()) );
    }

} // namespace tut