rgeo 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/History.rdoc +13 -0
  2. data/README.rdoc +6 -0
  3. data/Version +1 -1
  4. data/ext/geos_c_impl/factory.c +2 -2
  5. data/lib/rgeo/features/factory.rb +2 -2
  6. data/lib/rgeo/features/geometry.rb +26 -4
  7. data/lib/rgeo/features/geometry_collection.rb +12 -2
  8. data/lib/rgeo/geography/common/geometry_collection_methods.rb +12 -1
  9. data/lib/rgeo/geography/common/helper.rb +4 -4
  10. data/lib/rgeo/geography/common/line_string_methods.rb +1 -1
  11. data/lib/rgeo/geography/common/point_methods.rb +1 -1
  12. data/lib/rgeo/geography/common/polygon_methods.rb +1 -1
  13. data/lib/rgeo/geography/factories.rb +19 -6
  14. data/lib/rgeo/geography/factory.rb +31 -10
  15. data/lib/rgeo/geography/simple_mercator/feature_classes.rb +26 -26
  16. data/lib/rgeo/geography/simple_mercator/feature_methods.rb +14 -14
  17. data/lib/rgeo/geography/simple_mercator/projector.rb +1 -1
  18. data/lib/rgeo/geography/simple_spherical/calculations.rb +61 -0
  19. data/lib/rgeo/geography/simple_spherical/point_impl.rb +5 -0
  20. data/lib/rgeo/geos/factory.rb +12 -11
  21. data/tests/common/geometry_collection_tests.rb +220 -0
  22. data/tests/common/line_string_tests.rb +300 -0
  23. data/tests/common/multi_line_string_tests.rb +206 -0
  24. data/tests/common/multi_point_tests.rb +198 -0
  25. data/tests/common/multi_polygon_tests.rb +206 -0
  26. data/tests/common/point_tests.rb +281 -0
  27. data/tests/common/polygon_tests.rb +232 -0
  28. data/tests/geos/tc_geometry_collection.rb +5 -169
  29. data/tests/geos/tc_line_string.rb +4 -252
  30. data/tests/geos/tc_multi_line_string.rb +5 -154
  31. data/tests/geos/tc_multi_point.rb +5 -145
  32. data/tests/geos/tc_multi_polygon.rb +4 -151
  33. data/tests/geos/tc_point.rb +11 -213
  34. data/tests/geos/tc_polygon.rb +4 -182
  35. data/tests/simple_mercator/tc_geometry_collection.rb +62 -0
  36. data/tests/simple_mercator/tc_line_string.rb +62 -0
  37. data/tests/simple_mercator/tc_multi_line_string.rb +62 -0
  38. data/tests/simple_mercator/tc_multi_point.rb +62 -0
  39. data/tests/simple_mercator/tc_multi_polygon.rb +63 -0
  40. data/tests/simple_mercator/tc_point.rb +7 -220
  41. data/tests/simple_mercator/tc_polygon.rb +62 -0
  42. data/tests/simple_spherical/tc_point.rb +165 -0
  43. metadata +48 -9
@@ -0,0 +1,281 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for point implementations
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'rgeo'
38
+
39
+
40
+ module RGeo
41
+ module Tests # :nodoc:
42
+ module Common # :nodoc:
43
+
44
+ module PointTests # :nodoc:
45
+
46
+
47
+ def assert_close_enough(p1_, p2_)
48
+ assert((p1_.x - p2_.x).abs < 0.00000001 && (p1_.y - p2_.y).abs < 0.00000001)
49
+ end
50
+
51
+
52
+ def assert_contains_approx(p_, mp_)
53
+ assert(mp_.any?{ |q_| (p_.x - q_.x).abs < 0.00000001 && (p_.y - q_.y).abs < 0.00000001 })
54
+ end
55
+
56
+
57
+ def test_creation
58
+ point_ = @factory.point(21, -22)
59
+ assert_equal(21, point_.x)
60
+ assert_equal(-22, point_.y)
61
+ end
62
+
63
+
64
+ def test_wkt_creation
65
+ point1_ = @factory.parse_wkt('POINT(21 -22)')
66
+ assert_equal(21, point1_.x)
67
+ assert_equal(-22, point1_.y)
68
+ end
69
+
70
+
71
+ def test_clone
72
+ point1_ = @factory.point(11, 12)
73
+ point2_ = point1_.clone
74
+ assert_equal(point1_, point2_)
75
+ point3_ = @factory.point(13, 12)
76
+ point4_ = point3_.dup
77
+ assert_equal(point3_, point4_)
78
+ assert_not_equal(point2_, point4_)
79
+ end
80
+
81
+
82
+ def test_type_check
83
+ point_ = @factory.point(21, 22)
84
+ assert(::RGeo::Features::Geometry.check_type(point_))
85
+ assert(::RGeo::Features::Point.check_type(point_))
86
+ assert(!::RGeo::Features::GeometryCollection.check_type(point_))
87
+ assert(!::RGeo::Features::Curve.check_type(point_))
88
+ end
89
+
90
+
91
+ def test_geometry_type
92
+ point_ = @factory.point(11, 12)
93
+ assert_equal(::RGeo::Features::Point, point_.geometry_type)
94
+ end
95
+
96
+
97
+ def test_dimension
98
+ point_ = @factory.point(11, 12)
99
+ assert_equal(0, point_.dimension)
100
+ end
101
+
102
+
103
+ def test_envelope
104
+ point_ = @factory.point(11, 12)
105
+ assert_close_enough(point_, point_.envelope)
106
+ end
107
+
108
+
109
+ def test_as_text_wkt_round_trip
110
+ point1_ = @factory.point(11, 12)
111
+ text_ = point1_.as_text
112
+ point2_ = @factory.parse_wkt(text_)
113
+ assert_equal(point2_, point1_)
114
+ end
115
+
116
+
117
+ def test_as_binary_wkb_round_trip
118
+ point1_ = @factory.point(211, 12)
119
+ binary_ = point1_.as_binary
120
+ point2_ = @factory.parse_wkb(binary_)
121
+ assert_equal(point2_, point1_)
122
+ end
123
+
124
+
125
+ def test_is_empty
126
+ point1_ = @factory.point(0, 0)
127
+ assert(!point1_.is_empty?)
128
+ end
129
+
130
+
131
+ def test_is_simple
132
+ point1_ = @factory.point(0, 0)
133
+ assert(point1_.is_simple?)
134
+ end
135
+
136
+
137
+ def test_boundary
138
+ point_ = @factory.point(11, 12)
139
+ boundary_ = point_.boundary
140
+ assert(boundary_.is_empty?)
141
+ end
142
+
143
+
144
+ def test_equals
145
+ point1_ = @factory.point(11, 12)
146
+ point2_ = @factory.point(11, 12)
147
+ point3_ = @factory.point(13, 12)
148
+ assert(point1_.equals?(point2_))
149
+ assert(point1_ == point2_)
150
+ assert(point1_.eql?(point2_))
151
+ assert(!point1_.equals?(point3_))
152
+ assert(point1_ != point3_)
153
+ assert(!point1_.eql?(point3_))
154
+ end
155
+
156
+
157
+ def test_disjoint
158
+ point1_ = @factory.point(11, 12)
159
+ point2_ = @factory.point(11, 12)
160
+ point3_ = @factory.point(12, 12)
161
+ assert(!point1_.disjoint?(point2_))
162
+ assert(point1_.disjoint?(point3_))
163
+ end
164
+
165
+
166
+ def test_intersects
167
+ point1_ = @factory.point(11, 12)
168
+ point2_ = @factory.point(11, 12)
169
+ point3_ = @factory.point(12, 12)
170
+ assert(point1_.intersects?(point2_))
171
+ assert(!point1_.intersects?(point3_))
172
+ end
173
+
174
+
175
+ def test_touches
176
+ point1_ = @factory.point(11, 12)
177
+ point2_ = @factory.point(11, 12)
178
+ point3_ = @factory.point(12, 12)
179
+ assert(!point1_.touches?(point2_))
180
+ assert(!point1_.touches?(point3_))
181
+ end
182
+
183
+
184
+ def test_crosses
185
+ point1_ = @factory.point(11, 12)
186
+ point2_ = @factory.point(11, 12)
187
+ point3_ = @factory.point(12, 12)
188
+ assert(!point1_.crosses?(point2_))
189
+ assert(!point1_.crosses?(point3_))
190
+ end
191
+
192
+
193
+ def test_within
194
+ point1_ = @factory.point(11, 12)
195
+ point2_ = @factory.point(11, 12)
196
+ point3_ = @factory.point(12, 12)
197
+ assert(point1_.within?(point2_))
198
+ assert(!point1_.within?(point3_))
199
+ end
200
+
201
+
202
+ def test_contains
203
+ point1_ = @factory.point(11, 12)
204
+ point2_ = @factory.point(11, 12)
205
+ point3_ = @factory.point(12, 12)
206
+ assert(point1_.contains?(point2_))
207
+ assert(!point1_.contains?(point3_))
208
+ end
209
+
210
+
211
+ def test_overlaps
212
+ point1_ = @factory.point(11, 12)
213
+ point2_ = @factory.point(11, 12)
214
+ point3_ = @factory.point(12, 12)
215
+ assert(!point1_.overlaps?(point2_))
216
+ assert(!point1_.overlaps?(point3_))
217
+ end
218
+
219
+
220
+ def test_convex_hull
221
+ point_ = @factory.point(11, 12)
222
+ hull_ = point_.convex_hull
223
+ assert_close_enough(point_, hull_)
224
+ end
225
+
226
+
227
+ def test_intersection
228
+ point1_ = @factory.point(11, 12)
229
+ point2_ = @factory.point(11, 12)
230
+ point3_ = @factory.point(12, 12)
231
+ assert_close_enough(point1_, point1_.intersection(point2_))
232
+ int13_ = point1_.intersection(point3_)
233
+ assert_equal(::RGeo::Features::GeometryCollection, int13_.geometry_type)
234
+ assert(int13_.is_empty?)
235
+ end
236
+
237
+
238
+ def test_union
239
+ point1_ = @factory.point(11, 12)
240
+ point2_ = @factory.point(11, 12)
241
+ point3_ = @factory.point(12, 12)
242
+ union12_ = point1_.union(point2_)
243
+ union13_ = point1_.union(point3_)
244
+ assert_close_enough(point1_, union12_)
245
+ assert_equal(::RGeo::Features::MultiPoint, union13_.geometry_type)
246
+ assert_contains_approx(point1_, union13_)
247
+ assert_contains_approx(point3_, union13_)
248
+ end
249
+
250
+
251
+ def test_difference
252
+ point1_ = @factory.point(11, 12)
253
+ point2_ = @factory.point(11, 12)
254
+ point3_ = @factory.point(12, 12)
255
+ diff12_ = point1_.difference(point2_)
256
+ diff13_ = point1_.difference(point3_)
257
+ assert_equal(::RGeo::Features::GeometryCollection, diff12_.geometry_type)
258
+ assert(diff12_.is_empty?)
259
+ assert_close_enough(point1_, diff13_)
260
+ end
261
+
262
+
263
+ def test_sym_difference
264
+ point1_ = @factory.point(11, 12)
265
+ point2_ = @factory.point(11, 12)
266
+ point3_ = @factory.point(12, 12)
267
+ diff12_ = point1_.sym_difference(point2_)
268
+ diff13_ = point1_.sym_difference(point3_)
269
+ assert_equal(::RGeo::Features::GeometryCollection, diff12_.geometry_type)
270
+ assert(diff12_.is_empty?)
271
+ assert_equal(::RGeo::Features::MultiPoint, diff13_.geometry_type)
272
+ assert_contains_approx(point1_, diff13_)
273
+ assert_contains_approx(point3_, diff13_)
274
+ end
275
+
276
+
277
+ end
278
+
279
+ end
280
+ end
281
+ end
@@ -0,0 +1,232 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for polygon implementations
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2010 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'rgeo'
38
+
39
+
40
+ module RGeo
41
+ module Tests # :nodoc:
42
+ module Common # :nodoc:
43
+
44
+ module PolygonTests # :nodoc:
45
+
46
+
47
+ def test_creation_simple
48
+ point1_ = @factory.point(0, 0)
49
+ point2_ = @factory.point(0, 1)
50
+ point3_ = @factory.point(1, 0)
51
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
52
+ polygon_ = @factory.polygon(exterior_)
53
+ assert_not_nil(polygon_)
54
+ assert(::RGeo::Features::Polygon === polygon_)
55
+ assert_equal(::RGeo::Features::Polygon, polygon_.geometry_type)
56
+ assert_equal(exterior_, polygon_.exterior_ring)
57
+ assert_equal(0, polygon_.num_interior_rings)
58
+ end
59
+
60
+
61
+ def test_creation_one_hole
62
+ point1_ = @factory.point(0, 0)
63
+ point2_ = @factory.point(0, 10)
64
+ point3_ = @factory.point(10, 10)
65
+ point4_ = @factory.point(10, 0)
66
+ point5_ = @factory.point(4, 4)
67
+ point6_ = @factory.point(5, 6)
68
+ point7_ = @factory.point(6, 4)
69
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
70
+ interior_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
71
+ polygon_ = @factory.polygon(exterior_, [interior_])
72
+ assert_not_nil(polygon_)
73
+ assert(::RGeo::Features::Polygon === polygon_)
74
+ assert_equal(::RGeo::Features::Polygon, polygon_.geometry_type)
75
+ assert_equal(exterior_, polygon_.exterior_ring)
76
+ assert_equal(1, polygon_.num_interior_rings)
77
+ assert_equal([interior_], polygon_.interior_rings)
78
+ end
79
+
80
+
81
+ def test_fully_equal
82
+ point1_ = @factory.point(0, 0)
83
+ point2_ = @factory.point(0, 1)
84
+ point3_ = @factory.point(1, 0)
85
+ exterior1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
86
+ poly1_ = @factory.polygon(exterior1_)
87
+ point4_ = @factory.point(0, 0)
88
+ point5_ = @factory.point(0, 1)
89
+ point6_ = @factory.point(1, 0)
90
+ exterior2_ = @factory.linear_ring([point4_, point5_, point6_, point4_])
91
+ poly2_ = @factory.polygon(exterior2_)
92
+ assert(poly1_.eql?(poly2_))
93
+ assert(poly1_.equals?(poly2_))
94
+ end
95
+
96
+
97
+ def test_geometrically_equal_but_ordered_different
98
+ point1_ = @factory.point(0, 0)
99
+ point2_ = @factory.point(0, 1)
100
+ point3_ = @factory.point(1, 0)
101
+ exterior1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
102
+ poly1_ = @factory.polygon(exterior1_)
103
+ exterior2_ = @factory.linear_ring([point2_, point3_, point1_, point2_])
104
+ poly2_ = @factory.polygon(exterior2_)
105
+ assert(!poly1_.eql?(poly2_))
106
+ assert(poly1_.equals?(poly2_))
107
+ end
108
+
109
+
110
+ def test_geometrically_equal_but_different_directions
111
+ point1_ = @factory.point(0, 0)
112
+ point2_ = @factory.point(0, 1)
113
+ point3_ = @factory.point(1, 0)
114
+ exterior1_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
115
+ poly1_ = @factory.polygon(exterior1_)
116
+ exterior2_ = @factory.linear_ring([point1_, point3_, point2_, point1_])
117
+ poly2_ = @factory.polygon(exterior2_)
118
+ assert(!poly1_.eql?(poly2_))
119
+ assert(poly1_.equals?(poly2_))
120
+ end
121
+
122
+
123
+ def test_wkt_creation_simple
124
+ parsed_poly_ = @factory.parse_wkt('POLYGON((0 0, 0 1, 1 0, 0 0))')
125
+ point1_ = @factory.point(0, 0)
126
+ point2_ = @factory.point(0, 1)
127
+ point3_ = @factory.point(1, 0)
128
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
129
+ built_poly_ = @factory.polygon(exterior_)
130
+ assert_equal(built_poly_, parsed_poly_)
131
+ end
132
+
133
+
134
+ def test_wkt_creation_one_hole
135
+ parsed_poly_ = @factory.parse_wkt('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0), (4 4, 5 6, 6 4, 4 4))')
136
+ point1_ = @factory.point(0, 0)
137
+ point2_ = @factory.point(0, 10)
138
+ point3_ = @factory.point(10, 10)
139
+ point4_ = @factory.point(10, 0)
140
+ point5_ = @factory.point(4, 4)
141
+ point6_ = @factory.point(5, 6)
142
+ point7_ = @factory.point(6, 4)
143
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
144
+ interior_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
145
+ built_poly_ = @factory.polygon(exterior_, [interior_])
146
+ assert_equal(built_poly_, parsed_poly_)
147
+ end
148
+
149
+
150
+ def test_clone
151
+ point1_ = @factory.point(0, 0)
152
+ point2_ = @factory.point(0, 1)
153
+ point3_ = @factory.point(1, 0)
154
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
155
+ poly1_ = @factory.polygon(exterior_)
156
+ poly2_ = poly1_.clone
157
+ assert_equal(poly1_, poly2_)
158
+ assert_equal(exterior_, poly2_.exterior_ring)
159
+ assert_equal(0, poly2_.num_interior_rings)
160
+ end
161
+
162
+
163
+ def test_type_check
164
+ point1_ = @factory.point(0, 0)
165
+ point2_ = @factory.point(0, 1)
166
+ point3_ = @factory.point(1, 0)
167
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
168
+ poly_ = @factory.polygon(exterior_)
169
+ assert(::RGeo::Features::Geometry.check_type(poly_))
170
+ assert(!::RGeo::Features::Point.check_type(poly_))
171
+ assert(!::RGeo::Features::GeometryCollection.check_type(poly_))
172
+ assert(::RGeo::Features::Surface.check_type(poly_))
173
+ assert(::RGeo::Features::Polygon.check_type(poly_))
174
+ end
175
+
176
+
177
+ def test_as_text_wkt_round_trip
178
+ point1_ = @factory.point(0, 0)
179
+ point2_ = @factory.point(0, 1)
180
+ point3_ = @factory.point(1, 0)
181
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
182
+ poly1_ = @factory.polygon(exterior_)
183
+ text_ = poly1_.as_text
184
+ poly2_ = @factory.parse_wkt(text_)
185
+ assert_equal(poly1_, poly2_)
186
+ end
187
+
188
+
189
+ def test_as_binary_wkb_round_trip
190
+ point1_ = @factory.point(0, 0)
191
+ point2_ = @factory.point(0, 1)
192
+ point3_ = @factory.point(1, 0)
193
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
194
+ poly1_ = @factory.polygon(exterior_)
195
+ binary_ = poly1_.as_binary
196
+ poly2_ = @factory.parse_wkb(binary_)
197
+ assert_equal(poly1_, poly2_)
198
+ end
199
+
200
+
201
+ def test_dimension
202
+ point1_ = @factory.point(0, 0)
203
+ point2_ = @factory.point(0, 10)
204
+ point3_ = @factory.point(10, 10)
205
+ point4_ = @factory.point(10, 0)
206
+ point5_ = @factory.point(4, 4)
207
+ point6_ = @factory.point(5, 6)
208
+ point7_ = @factory.point(6, 4)
209
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
210
+ interior_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
211
+ poly_ = @factory.polygon(exterior_, [interior_])
212
+ assert_equal(2, poly_.dimension)
213
+ end
214
+
215
+
216
+ def test_is_empty
217
+ point1_ = @factory.point(0, 0)
218
+ point2_ = @factory.point(0, 1)
219
+ point3_ = @factory.point(1, 0)
220
+ exterior_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
221
+ poly1_ = @factory.polygon(exterior_)
222
+ assert(!poly1_.is_empty?)
223
+ poly2_ = @factory.polygon(@factory.linear_ring([]))
224
+ assert(poly2_.is_empty?)
225
+ end
226
+
227
+
228
+ end
229
+
230
+ end
231
+ end
232
+ end
@@ -37,6 +37,8 @@
37
37
  require 'test/unit'
38
38
  require 'rgeo'
39
39
 
40
+ require ::File.expand_path('../common/geometry_collection_tests.rb', ::File.dirname(__FILE__))
41
+
40
42
 
41
43
  module RGeo
42
44
  module Tests # :nodoc:
@@ -45,178 +47,12 @@ module RGeo
45
47
  class TestGeometryCollection < ::Test::Unit::TestCase # :nodoc:
46
48
 
47
49
 
48
- def setup
49
- @factory = ::RGeo::Geos.factory
50
- @point1 = @factory.point(0, 0)
51
- @point2 = @factory.point(1, 0)
52
- @point3 = @factory.point(-4, 2)
53
- @point4 = @factory.point(-5, 3)
54
- @line1 = @factory.line_string([@point3, @point4])
55
- @line2 = @factory.line_string([@point3, @point4, @point1])
56
- @line3 = @factory.line(@point3, @point4)
57
- end
58
-
59
-
60
- def test_creation_simple
61
- geom_ = @factory.collection([@point1, @line1])
62
- assert_not_nil(geom_)
63
- assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom_)
64
- assert(::RGeo::Features::GeometryCollection === geom_)
65
- assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
66
- assert_equal(2, geom_.num_geometries)
67
- assert_equal([@point1, @line1], geom_.to_a)
68
- end
69
-
70
-
71
- def test_creation_empty
72
- geom_ = @factory.collection([])
73
- assert_not_nil(geom_)
74
- assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom_)
75
- assert(::RGeo::Features::GeometryCollection === geom_)
76
- assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
77
- assert_equal(0, geom_.num_geometries)
78
- assert_equal([], geom_.to_a)
79
- end
80
-
81
-
82
- def test_creation_save_klass
83
- geom_ = @factory.collection([@point1, @line3])
84
- assert_not_nil(geom_)
85
- assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom_)
86
- assert(::RGeo::Features::GeometryCollection === geom_)
87
- assert_equal(::RGeo::Features::GeometryCollection, geom_.geometry_type)
88
- assert_equal(2, geom_.num_geometries)
89
- assert(geom_[1].eql?(@line3))
90
- end
91
-
92
-
93
- def test_creation_compound
94
- geom1_ = @factory.collection([@point1, @line1])
95
- geom2_ = @factory.collection([@point2, geom1_])
96
- assert_not_nil(geom2_)
97
- assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom2_)
98
- assert(::RGeo::Features::GeometryCollection === geom2_)
99
- assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
100
- assert_equal(2, geom2_.num_geometries)
101
- assert(geom2_[1].eql?(geom1_))
102
- end
103
-
104
-
105
- def test_creation_compound_save_klass
106
- geom1_ = @factory.collection([@point1, @line3])
107
- geom2_ = @factory.collection([@point2, geom1_])
108
- ::GC.start
109
- assert_not_nil(geom2_)
110
- assert_kind_of(::RGeo::Geos::GeometryCollectionImpl, geom2_)
111
- assert(::RGeo::Features::GeometryCollection === geom2_)
112
- assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
113
- assert_equal(2, geom2_.num_geometries)
114
- assert(::RGeo::Features::Line === geom2_[1][1])
115
- end
116
-
117
-
118
- def test_fully_equal
119
- geom1_ = @factory.collection([@point1, @line1])
120
- geom2_ = @factory.collection([@point1, @line1])
121
- assert(geom1_.eql?(geom2_))
122
- assert(geom1_.equals?(geom2_))
123
- end
124
-
125
-
126
- def test_geometrically_equal
127
- geom1_ = @factory.collection([@point2, @line2])
128
- geom2_ = @factory.collection([@point2, @line1, @line2])
129
- assert(!geom1_.eql?(geom2_))
130
- assert(geom1_.equals?(geom2_))
131
- end
132
-
133
-
134
- def test_empty_equal
135
- geom1_ = @factory.collection([])
136
- geom2_ = @factory.collection([])
137
- assert(geom1_.eql?(geom2_))
138
- assert(geom1_.equals?(geom2_))
50
+ def create_factory
51
+ ::RGeo::Geos.factory
139
52
  end
140
53
 
141
54
 
142
- def test_not_equal
143
- geom1_ = @factory.collection([@point1, @line1])
144
- geom2_ = @factory.collection([@point2, @line1])
145
- assert(!geom1_.eql?(geom2_))
146
- assert(!geom1_.equals?(geom2_))
147
- end
148
-
149
-
150
- def test_wkt_creation_simple
151
- parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION(POINT(0 0), LINESTRING(-4 2, -5 3))')
152
- built_geom_ = @factory.collection([@point1, @line1])
153
- assert_equal(built_geom_, parsed_geom_)
154
- end
155
-
156
-
157
- def test_wkt_creation_empty
158
- parsed_geom_ = @factory.parse_wkt('GEOMETRYCOLLECTION EMPTY')
159
- assert_equal(0, parsed_geom_.num_geometries)
160
- assert_equal([], parsed_geom_.to_a)
161
- end
162
-
163
-
164
- def test_clone
165
- geom1_ = @factory.collection([@point1, @line1])
166
- geom2_ = geom1_.clone
167
- assert_equal(geom1_, geom2_)
168
- assert_equal(::RGeo::Features::GeometryCollection, geom2_.geometry_type)
169
- assert_equal(2, geom2_.num_geometries)
170
- assert_equal([@point1, @line1], geom2_.to_a)
171
- end
172
-
173
-
174
- def test_type_check
175
- geom1_ = @factory.collection([@point1, @line1])
176
- assert(::RGeo::Features::Geometry.check_type(geom1_))
177
- assert(!::RGeo::Features::Point.check_type(geom1_))
178
- assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
179
- assert(!::RGeo::Features::MultiPoint.check_type(geom1_))
180
- geom2_ = @factory.collection([@point1, @point2])
181
- assert(::RGeo::Features::Geometry.check_type(geom2_))
182
- assert(!::RGeo::Features::Point.check_type(geom2_))
183
- assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
184
- assert(!::RGeo::Features::MultiPoint.check_type(geom2_))
185
- end
186
-
187
-
188
- def test_as_text_wkt_round_trip
189
- geom1_ = @factory.collection([@point1, @line1])
190
- text_ = geom1_.as_text
191
- geom2_ = @factory.parse_wkt(text_)
192
- assert_equal(geom1_, geom2_)
193
- end
194
-
195
-
196
- def test_as_binary_wkb_round_trip
197
- geom1_ = @factory.collection([@point1, @line1])
198
- binary_ = geom1_.as_binary
199
- geom2_ = @factory.parse_wkb(binary_)
200
- assert_equal(geom1_, geom2_)
201
- end
202
-
203
-
204
- def test_dimension
205
- geom1_ = @factory.collection([@point1, @line1])
206
- assert_equal(1, geom1_.dimension)
207
- geom2_ = @factory.collection([@point1, @point2])
208
- assert_equal(0, geom2_.dimension)
209
- geom3_ = @factory.collection([])
210
- assert_equal(-1, geom3_.dimension)
211
- end
212
-
213
-
214
- def test_is_empty
215
- geom1_ = @factory.collection([@point1, @line1])
216
- assert(!geom1_.is_empty?)
217
- geom2_ = @factory.collection([])
218
- assert(geom2_.is_empty?)
219
- end
55
+ include ::RGeo::Tests::Common::GeometryCollectionTests
220
56
 
221
57
 
222
58
  end