rgeo 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,206 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for multi line string 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 MultiLineStringTests # :nodoc:
45
+
46
+
47
+ def setup
48
+ @factory = create_factory
49
+ point1_ = @factory.point(0, 0)
50
+ point2_ = @factory.point(1, 0)
51
+ point3_ = @factory.point(-4, 2)
52
+ point4_ = @factory.point(-5, 3)
53
+ point5_ = @factory.point(-3, 5)
54
+ @linestring1 = @factory.line_string([point1_, point2_])
55
+ @linestring2 = @factory.line_string([point3_, point4_, point5_])
56
+ @linearring1 = @factory.linear_ring([point5_, point3_, point4_, point5_])
57
+ @line1 = @factory.line(point1_, point2_)
58
+ end
59
+
60
+
61
+ def test_creation_simple
62
+ geom_ = @factory.multi_line_string([@linestring1, @linestring2])
63
+ assert_not_nil(geom_)
64
+ assert(::RGeo::Features::MultiLineString === geom_)
65
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
66
+ assert_equal(2, geom_.num_geometries)
67
+ assert_equal([@linestring1, @linestring2], geom_.to_a)
68
+ end
69
+
70
+
71
+ def test_creation_empty
72
+ geom_ = @factory.multi_line_string([])
73
+ assert_not_nil(geom_)
74
+ assert(::RGeo::Features::MultiLineString === geom_)
75
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
76
+ assert_equal(0, geom_.num_geometries)
77
+ assert_equal([], geom_.to_a)
78
+ end
79
+
80
+
81
+ def test_creation_save_types
82
+ geom_ = @factory.multi_line_string([@linestring1, @linearring1, @line1])
83
+ assert_not_nil(geom_)
84
+ assert(::RGeo::Features::MultiLineString === geom_)
85
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
86
+ assert_equal(3, geom_.num_geometries)
87
+ assert(geom_[1].eql?(@linearring1))
88
+ assert(geom_[2].eql?(@line1))
89
+ end
90
+
91
+
92
+ def test_creation_compound
93
+ mls1_ = @factory.multi_line_string([@linestring1, @linestring2])
94
+ mls2_ = @factory.collection([@line1])
95
+ mls3_ = @factory.collection([mls1_])
96
+ geom_ = @factory.multi_line_string([mls3_, mls2_, @linearring1])
97
+ assert_not_nil(geom_)
98
+ assert(::RGeo::Features::MultiLineString === geom_)
99
+ assert_equal(::RGeo::Features::MultiLineString, geom_.geometry_type)
100
+ assert_equal(4, geom_.num_geometries)
101
+ assert(geom_.to_a.eql?([@linestring1, @linestring2, @line1, @linearring1]))
102
+ end
103
+
104
+
105
+ def test_fully_equal
106
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
107
+ geom2_ = @factory.multi_line_string([@linestring1, @linestring2])
108
+ assert(geom1_.eql?(geom2_))
109
+ assert(geom1_.equals?(geom2_))
110
+ end
111
+
112
+
113
+ def test_geometrically_equal
114
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2, @linearring1])
115
+ geom2_ = @factory.multi_line_string([@line1, @linearring1])
116
+ assert(!geom1_.eql?(geom2_))
117
+ assert(geom1_.equals?(geom2_))
118
+ end
119
+
120
+
121
+ def test_not_equal
122
+ geom1_ = @factory.multi_line_string([@linestring2])
123
+ geom2_ = @factory.multi_line_string([@linearring1])
124
+ assert(!geom1_.eql?(geom2_))
125
+ assert(!geom1_.equals?(geom2_))
126
+ end
127
+
128
+
129
+ def test_wkt_creation_simple
130
+ parsed_geom_ = @factory.parse_wkt('MULTILINESTRING((0 0, 1 0), (-4 2, -5 3, -3 5))')
131
+ built_geom_ = @factory.multi_line_string([@linestring1, @linestring2])
132
+ assert_equal(built_geom_, parsed_geom_)
133
+ end
134
+
135
+
136
+ def test_wkt_creation_empty
137
+ parsed_geom_ = @factory.parse_wkt('MULTILINESTRING EMPTY')
138
+ assert_equal(::RGeo::Features::MultiLineString, parsed_geom_.geometry_type)
139
+ assert_equal(0, parsed_geom_.num_geometries)
140
+ assert_equal([], parsed_geom_.to_a)
141
+ end
142
+
143
+
144
+ def test_clone
145
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
146
+ geom2_ = geom1_.clone
147
+ assert_equal(geom1_, geom2_)
148
+ assert_equal(::RGeo::Features::MultiLineString, geom2_.geometry_type)
149
+ assert_equal(2, geom2_.num_geometries)
150
+ assert_equal([@linestring1, @linestring2], geom2_.to_a)
151
+ end
152
+
153
+
154
+ def test_type_check
155
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
156
+ assert(::RGeo::Features::Geometry.check_type(geom1_))
157
+ assert(!::RGeo::Features::LineString.check_type(geom1_))
158
+ assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
159
+ assert(!::RGeo::Features::MultiPoint.check_type(geom1_))
160
+ assert(::RGeo::Features::MultiLineString.check_type(geom1_))
161
+ geom2_ = @factory.multi_line_string([])
162
+ assert(::RGeo::Features::Geometry.check_type(geom2_))
163
+ assert(!::RGeo::Features::LineString.check_type(geom2_))
164
+ assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
165
+ assert(!::RGeo::Features::MultiPoint.check_type(geom2_))
166
+ assert(::RGeo::Features::MultiLineString.check_type(geom2_))
167
+ end
168
+
169
+
170
+ def test_as_text_wkt_round_trip
171
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
172
+ text_ = geom1_.as_text
173
+ geom2_ = @factory.parse_wkt(text_)
174
+ assert_equal(geom1_, geom2_)
175
+ end
176
+
177
+
178
+ def test_as_binary_wkb_round_trip
179
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
180
+ binary_ = geom1_.as_binary
181
+ geom2_ = @factory.parse_wkb(binary_)
182
+ assert_equal(geom1_, geom2_)
183
+ end
184
+
185
+
186
+ def test_dimension
187
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
188
+ assert_equal(1, geom1_.dimension)
189
+ geom2_ = @factory.multi_line_string([])
190
+ assert_equal(-1, geom2_.dimension)
191
+ end
192
+
193
+
194
+ def test_is_empty
195
+ geom1_ = @factory.multi_line_string([@linestring1, @linestring2])
196
+ assert(!geom1_.is_empty?)
197
+ geom2_ = @factory.multi_line_string([])
198
+ assert(geom2_.is_empty?)
199
+ end
200
+
201
+
202
+ end
203
+
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,198 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for multi 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 MultiPointTests # :nodoc:
45
+
46
+
47
+ def setup
48
+ @factory = create_factory
49
+ @point1 = @factory.point(0, 0)
50
+ @point2 = @factory.point(1, 0)
51
+ @point3 = @factory.point(-4, 2)
52
+ @point4 = @factory.point(-5, 3)
53
+ @point5 = @factory.point(-5, 3)
54
+ end
55
+
56
+
57
+ def test_creation_simple
58
+ geom_ = @factory.multi_point([@point1, @point2])
59
+ assert_not_nil(geom_)
60
+ assert(::RGeo::Features::MultiPoint === geom_)
61
+ assert_equal(::RGeo::Features::MultiPoint, geom_.geometry_type)
62
+ assert_equal(2, geom_.num_geometries)
63
+ assert_equal([@point1, @point2], geom_.to_a)
64
+ end
65
+
66
+
67
+ def test_creation_empty
68
+ geom_ = @factory.multi_point([])
69
+ assert_not_nil(geom_)
70
+ assert(::RGeo::Features::MultiPoint === geom_)
71
+ assert_equal(::RGeo::Features::MultiPoint, geom_.geometry_type)
72
+ assert_equal(0, geom_.num_geometries)
73
+ assert_equal([], geom_.to_a)
74
+ end
75
+
76
+
77
+ def test_creation_compound
78
+ mp1_ = @factory.multi_point([@point1, @point2])
79
+ mp2_ = @factory.collection([@point3])
80
+ mp3_ = @factory.collection([mp1_])
81
+ geom_ = @factory.multi_point([mp3_, mp2_, @point4])
82
+ assert_not_nil(geom_)
83
+ assert(::RGeo::Features::MultiPoint === geom_)
84
+ assert_equal(::RGeo::Features::MultiPoint, geom_.geometry_type)
85
+ assert_equal(4, geom_.num_geometries)
86
+ assert_equal([@point1, @point2, @point3, @point4], geom_.to_a)
87
+ end
88
+
89
+
90
+ def test_creation_wrong_type
91
+ line_ = @factory.line_string([@point1, @point2])
92
+ geom_ = @factory.multi_point([@point3, line_])
93
+ assert_nil(geom_)
94
+ end
95
+
96
+
97
+ def test_fully_equal
98
+ geom1_ = @factory.multi_point([@point1, @point2])
99
+ geom2_ = @factory.multi_point([@point1, @point2])
100
+ assert(geom1_.eql?(geom2_))
101
+ assert(geom1_.equals?(geom2_))
102
+ end
103
+
104
+
105
+ def test_geometrically_equal
106
+ geom1_ = @factory.multi_point([@point1, @point4])
107
+ geom2_ = @factory.multi_point([@point1, @point4, @point5])
108
+ assert(!geom1_.eql?(geom2_))
109
+ assert(geom1_.equals?(geom2_))
110
+ end
111
+
112
+
113
+ def test_not_equal
114
+ geom1_ = @factory.multi_point([@point1, @point2])
115
+ geom2_ = @factory.multi_point([@point1])
116
+ assert(!geom1_.eql?(geom2_))
117
+ assert(!geom1_.equals?(geom2_))
118
+ end
119
+
120
+
121
+ def test_wkt_creation_simple
122
+ parsed_geom_ = @factory.parse_wkt('MULTIPOINT((0 0), (-4 2), (-5 3))')
123
+ built_geom_ = @factory.multi_point([@point1, @point3, @point4])
124
+ assert_equal(built_geom_, parsed_geom_)
125
+ end
126
+
127
+
128
+ def test_wkt_creation_empty
129
+ parsed_geom_ = @factory.parse_wkt('MULTIPOINT EMPTY')
130
+ assert(::RGeo::Features::MultiPoint === parsed_geom_)
131
+ assert_equal(0, parsed_geom_.num_geometries)
132
+ assert_equal([], parsed_geom_.to_a)
133
+ end
134
+
135
+
136
+ def test_clone
137
+ geom1_ = @factory.multi_point([@point1, @point2])
138
+ geom2_ = geom1_.clone
139
+ assert_equal(geom1_, geom2_)
140
+ assert_equal(::RGeo::Features::MultiPoint, geom2_.geometry_type)
141
+ assert_equal(2, geom2_.num_geometries)
142
+ assert_equal([@point1, @point2], geom2_.to_a)
143
+ end
144
+
145
+
146
+ def test_type_check
147
+ geom1_ = @factory.multi_point([@point1, @point2])
148
+ assert(::RGeo::Features::Geometry.check_type(geom1_))
149
+ assert(!::RGeo::Features::Point.check_type(geom1_))
150
+ assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
151
+ assert(::RGeo::Features::MultiPoint.check_type(geom1_))
152
+ assert(!::RGeo::Features::MultiLineString.check_type(geom1_))
153
+ geom2_ = @factory.multi_point([])
154
+ assert(::RGeo::Features::Geometry.check_type(geom2_))
155
+ assert(!::RGeo::Features::Point.check_type(geom2_))
156
+ assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
157
+ assert(::RGeo::Features::MultiPoint.check_type(geom2_))
158
+ assert(!::RGeo::Features::MultiLineString.check_type(geom2_))
159
+ end
160
+
161
+
162
+ def test_as_text_wkt_round_trip
163
+ geom1_ = @factory.multi_point([@point1, @point2])
164
+ text_ = geom1_.as_text
165
+ geom2_ = @factory.parse_wkt(text_)
166
+ assert_equal(geom1_, geom2_)
167
+ end
168
+
169
+
170
+ def test_as_binary_wkb_round_trip
171
+ geom1_ = @factory.multi_point([@point1, @point2])
172
+ binary_ = geom1_.as_binary
173
+ geom2_ = @factory.parse_wkb(binary_)
174
+ assert_equal(geom1_, geom2_)
175
+ end
176
+
177
+
178
+ def test_dimension
179
+ geom1_ = @factory.multi_point([@point1, @point2])
180
+ assert_equal(0, geom1_.dimension)
181
+ geom2_ = @factory.multi_point([])
182
+ assert_equal(-1, geom2_.dimension)
183
+ end
184
+
185
+
186
+ def test_is_empty
187
+ geom1_ = @factory.multi_point([@point1, @point2])
188
+ assert(!geom1_.is_empty?)
189
+ geom2_ = @factory.multi_point([])
190
+ assert(geom2_.is_empty?)
191
+ end
192
+
193
+
194
+ end
195
+
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,206 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Common tests for multi 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 MultiPolygonTests # :nodoc:
45
+
46
+
47
+ def setup
48
+ create_factories
49
+ point1_ = @factory.point(0, 0)
50
+ point2_ = @factory.point(0, 10)
51
+ point3_ = @factory.point(10, 10)
52
+ point4_ = @factory.point(10, 0)
53
+ point5_ = @factory.point(4, 4)
54
+ point6_ = @factory.point(5, 6)
55
+ point7_ = @factory.point(6, 4)
56
+ point8_ = @factory.point(0, -10)
57
+ point9_ = @factory.point(-10, 0)
58
+ exterior1_ = @factory.linear_ring([point1_, point8_, point9_, point1_])
59
+ exterior2_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
60
+ exterior3_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
61
+ exterior4_ = @factory.linear_ring([point1_, point3_, point4_, point1_])
62
+ interior1_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
63
+ @poly1 = @factory.polygon(exterior1_)
64
+ @poly2 = @factory.polygon(exterior2_, [interior1_])
65
+ @poly3 = @factory.polygon(exterior3_)
66
+ @poly4 = @factory.polygon(exterior4_)
67
+ @line1 = interior1_
68
+ end
69
+
70
+
71
+ def test_creation_simple
72
+ geom_ = @factory.multi_polygon([@poly1, @poly2])
73
+ assert_not_nil(geom_)
74
+ assert(::RGeo::Features::MultiPolygon === geom_)
75
+ assert_equal(::RGeo::Features::MultiPolygon, geom_.geometry_type)
76
+ assert_equal(2, geom_.num_geometries)
77
+ assert_equal([@poly1, @poly2], geom_.to_a)
78
+ end
79
+
80
+
81
+ def test_creation_empty
82
+ geom_ = @factory.multi_polygon([])
83
+ assert_not_nil(geom_)
84
+ assert(::RGeo::Features::MultiPolygon === geom_)
85
+ assert_equal(::RGeo::Features::MultiPolygon, geom_.geometry_type)
86
+ assert_equal(0, geom_.num_geometries)
87
+ assert_equal([], geom_.to_a)
88
+ end
89
+
90
+
91
+ def test_creation_wrong_type
92
+ geom_ = @factory.multi_polygon([@poly1, @line1])
93
+ assert_nil(geom_)
94
+ end
95
+
96
+
97
+ def test_creation_overlapping
98
+ geom_ = @factory.multi_polygon([@poly1, @poly1])
99
+ assert_nil(geom_)
100
+ geom2_ = @lenient_factory.multi_polygon([@poly1, @poly1])
101
+ assert_not_nil(geom2_)
102
+ end
103
+
104
+
105
+ def test_creation_connected
106
+ geom_ = @factory.multi_polygon([@poly3, @poly4])
107
+ assert_nil(geom_)
108
+ geom2_ = @lenient_factory.multi_polygon([@poly3, @poly4])
109
+ assert_not_nil(geom2_)
110
+ end
111
+
112
+
113
+ def test_equal
114
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
115
+ geom2_ = @factory.multi_polygon([@poly1, @poly2])
116
+ assert(geom1_.eql?(geom2_))
117
+ assert(geom1_.equals?(geom2_))
118
+ end
119
+
120
+
121
+ def test_not_equal
122
+ geom1_ = @factory.multi_polygon([@poly1])
123
+ geom2_ = @factory.multi_polygon([@poly2])
124
+ assert(!geom1_.eql?(geom2_))
125
+ assert(!geom1_.equals?(geom2_))
126
+ end
127
+
128
+
129
+ def test_wkt_creation_simple
130
+ parsed_geom_ = @factory.parse_wkt('MULTIPOLYGON(((0 0, 0 -10, -10 0, 0 0)), ((0 0, 0 10, 10 10, 10 0, 0 0), (4 4, 5 6, 6 4, 4 4)))')
131
+ built_geom_ = @factory.multi_polygon([@poly1, @poly2])
132
+ assert_equal(built_geom_, parsed_geom_)
133
+ end
134
+
135
+
136
+ def test_wkt_creation_empty
137
+ parsed_geom_ = @factory.parse_wkt('MULTIPOLYGON EMPTY')
138
+ assert_equal(::RGeo::Features::MultiPolygon, parsed_geom_.geometry_type)
139
+ assert_equal(0, parsed_geom_.num_geometries)
140
+ assert_equal([], parsed_geom_.to_a)
141
+ end
142
+
143
+
144
+ def test_clone
145
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
146
+ geom2_ = geom1_.clone
147
+ assert_equal(geom1_, geom2_)
148
+ assert_equal(::RGeo::Features::MultiPolygon, geom2_.geometry_type)
149
+ assert_equal(2, geom2_.num_geometries)
150
+ assert_equal([@poly1, @poly2], geom2_.to_a)
151
+ end
152
+
153
+
154
+ def test_type_check
155
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
156
+ assert(::RGeo::Features::Geometry.check_type(geom1_))
157
+ assert(!::RGeo::Features::Polygon.check_type(geom1_))
158
+ assert(::RGeo::Features::GeometryCollection.check_type(geom1_))
159
+ assert(!::RGeo::Features::MultiPoint.check_type(geom1_))
160
+ assert(::RGeo::Features::MultiPolygon.check_type(geom1_))
161
+ geom2_ = @factory.multi_polygon([])
162
+ assert(::RGeo::Features::Geometry.check_type(geom2_))
163
+ assert(!::RGeo::Features::Polygon.check_type(geom2_))
164
+ assert(::RGeo::Features::GeometryCollection.check_type(geom2_))
165
+ assert(!::RGeo::Features::MultiPoint.check_type(geom2_))
166
+ assert(::RGeo::Features::MultiPolygon.check_type(geom2_))
167
+ end
168
+
169
+
170
+ def test_as_text_wkt_round_trip
171
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
172
+ text_ = geom1_.as_text
173
+ geom2_ = @factory.parse_wkt(text_)
174
+ assert_equal(geom1_, geom2_)
175
+ end
176
+
177
+
178
+ def test_as_binary_wkb_round_trip
179
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
180
+ binary_ = geom1_.as_binary
181
+ geom2_ = @factory.parse_wkb(binary_)
182
+ assert_equal(geom1_, geom2_)
183
+ end
184
+
185
+
186
+ def test_dimension
187
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
188
+ assert_equal(2, geom1_.dimension)
189
+ geom2_ = @factory.multi_polygon([])
190
+ assert_equal(-1, geom2_.dimension)
191
+ end
192
+
193
+
194
+ def test_is_empty
195
+ geom1_ = @factory.multi_polygon([@poly1, @poly2])
196
+ assert(!geom1_.is_empty?)
197
+ geom2_ = @factory.multi_polygon([])
198
+ assert(geom2_.is_empty?)
199
+ end
200
+
201
+
202
+ end
203
+
204
+ end
205
+ end
206
+ end