rgeo 0.5.3 → 0.6.0

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 (96) hide show
  1. checksums.yaml +4 -4
  2. data/ext/geos_c_impl/extconf.rb +1 -0
  3. data/ext/geos_c_impl/factory.c +10 -1
  4. data/ext/geos_c_impl/geometry.c +25 -3
  5. data/ext/geos_c_impl/line_string.c +1 -12
  6. data/ext/geos_c_impl/polygon.c +0 -3
  7. data/ext/geos_c_impl/preface.h +3 -0
  8. data/lib/rgeo.rb +0 -1
  9. data/lib/rgeo/feature/geometry.rb +17 -0
  10. data/lib/rgeo/feature/types.rb +4 -4
  11. data/lib/rgeo/geographic/projected_feature_methods.rb +1 -22
  12. data/lib/rgeo/geos/ffi_feature_methods.rb +5 -0
  13. data/lib/rgeo/geos/utils.rb +2 -0
  14. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +1 -0
  15. data/lib/rgeo/version.rb +1 -1
  16. metadata +11 -171
  17. data/lib/rgeo/yaml.rb +0 -23
  18. data/test/cartesian_analysis_test.rb +0 -65
  19. data/test/cartesian_bbox_test.rb +0 -123
  20. data/test/common/factory_tests.rb +0 -78
  21. data/test/common/geometry_collection_tests.rb +0 -237
  22. data/test/common/line_string_tests.rb +0 -330
  23. data/test/common/multi_line_string_tests.rb +0 -182
  24. data/test/common/multi_point_tests.rb +0 -200
  25. data/test/common/multi_polygon_tests.rb +0 -191
  26. data/test/common/point_tests.rb +0 -370
  27. data/test/common/polygon_tests.rb +0 -228
  28. data/test/coord_sys/ogc_cs_test.rb +0 -342
  29. data/test/coord_sys/proj4_srs_data_test.rb +0 -41
  30. data/test/coord_sys/proj4_test.rb +0 -150
  31. data/test/coord_sys/sr_org_test.rb +0 -32
  32. data/test/coord_sys/url_reader_test.rb +0 -42
  33. data/test/geos_capi/factory_test.rb +0 -31
  34. data/test/geos_capi/geometry_collection_test.rb +0 -24
  35. data/test/geos_capi/line_string_test.rb +0 -24
  36. data/test/geos_capi/misc_test.rb +0 -116
  37. data/test/geos_capi/multi_line_string_test.rb +0 -24
  38. data/test/geos_capi/multi_point_test.rb +0 -24
  39. data/test/geos_capi/multi_polygon_test.rb +0 -39
  40. data/test/geos_capi/parsing_unparsing_test.rb +0 -40
  41. data/test/geos_capi/point_test.rb +0 -72
  42. data/test/geos_capi/polygon_test.rb +0 -154
  43. data/test/geos_capi/zmfactory_test.rb +0 -57
  44. data/test/geos_ffi/factory_test.rb +0 -31
  45. data/test/geos_ffi/geometry_collection_test.rb +0 -24
  46. data/test/geos_ffi/line_string_test.rb +0 -24
  47. data/test/geos_ffi/misc_test.rb +0 -63
  48. data/test/geos_ffi/multi_line_string_test.rb +0 -24
  49. data/test/geos_ffi/multi_point_test.rb +0 -24
  50. data/test/geos_ffi/multi_polygon_test.rb +0 -33
  51. data/test/geos_ffi/parsing_unparsing_test.rb +0 -41
  52. data/test/geos_ffi/point_test.rb +0 -77
  53. data/test/geos_ffi/polygon_test.rb +0 -46
  54. data/test/geos_ffi/zmfactory_test.rb +0 -58
  55. data/test/mixins_test.rb +0 -141
  56. data/test/oneoff_test.rb +0 -26
  57. data/test/projected_geographic/factory_test.rb +0 -25
  58. data/test/projected_geographic/geometry_collection_test.rb +0 -24
  59. data/test/projected_geographic/line_string_test.rb +0 -24
  60. data/test/projected_geographic/multi_line_string_test.rb +0 -26
  61. data/test/projected_geographic/multi_point_test.rb +0 -30
  62. data/test/projected_geographic/multi_polygon_test.rb +0 -25
  63. data/test/projected_geographic/point_test.rb +0 -51
  64. data/test/projected_geographic/polygon_test.rb +0 -24
  65. data/test/simple_cartesian/calculations_test.rb +0 -99
  66. data/test/simple_cartesian/factory_test.rb +0 -27
  67. data/test/simple_cartesian/geometry_collection_test.rb +0 -30
  68. data/test/simple_cartesian/line_string_test.rb +0 -31
  69. data/test/simple_cartesian/multi_line_string_test.rb +0 -28
  70. data/test/simple_cartesian/multi_point_test.rb +0 -31
  71. data/test/simple_cartesian/multi_polygon_test.rb +0 -31
  72. data/test/simple_cartesian/point_test.rb +0 -50
  73. data/test/simple_cartesian/polygon_test.rb +0 -28
  74. data/test/simple_mercator/factory_test.rb +0 -25
  75. data/test/simple_mercator/geometry_collection_test.rb +0 -24
  76. data/test/simple_mercator/line_string_test.rb +0 -24
  77. data/test/simple_mercator/multi_line_string_test.rb +0 -26
  78. data/test/simple_mercator/multi_point_test.rb +0 -29
  79. data/test/simple_mercator/multi_polygon_test.rb +0 -25
  80. data/test/simple_mercator/point_test.rb +0 -55
  81. data/test/simple_mercator/polygon_test.rb +0 -24
  82. data/test/simple_mercator/window_test.rb +0 -173
  83. data/test/spherical_geographic/calculations_test.rb +0 -167
  84. data/test/spherical_geographic/factory_test.rb +0 -27
  85. data/test/spherical_geographic/geometry_collection_test.rb +0 -31
  86. data/test/spherical_geographic/line_string_test.rb +0 -31
  87. data/test/spherical_geographic/multi_line_string_test.rb +0 -29
  88. data/test/spherical_geographic/multi_point_test.rb +0 -31
  89. data/test/spherical_geographic/multi_polygon_test.rb +0 -31
  90. data/test/spherical_geographic/point_test.rb +0 -78
  91. data/test/spherical_geographic/polygon_test.rb +0 -28
  92. data/test/types_test.rb +0 -42
  93. data/test/wkrep/wkb_generator_test.rb +0 -185
  94. data/test/wkrep/wkb_parser_test.rb +0 -293
  95. data/test/wkrep/wkt_generator_test.rb +0 -294
  96. data/test/wkrep/wkt_parser_test.rb +0 -412
@@ -1,200 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Common tests for multi point implementations
4
- #
5
- # -----------------------------------------------------------------------------
6
-
7
- require "rgeo"
8
-
9
- module RGeo
10
- module Tests # :nodoc:
11
- module Common # :nodoc:
12
- module MultiPointTests # :nodoc:
13
- def setup
14
- @factory = create_factory
15
- @point1 = @factory.point(0, 0)
16
- @point2 = @factory.point(1, 0)
17
- @point3 = @factory.point(-4, 2)
18
- @point4 = @factory.point(-5, 3)
19
- @point5 = @factory.point(-5, 3)
20
- end
21
-
22
- def test_creation_simple
23
- geom_ = @factory.multi_point([@point1, @point2])
24
- assert_not_nil(geom_)
25
- assert(::RGeo::Feature::MultiPoint === geom_)
26
- assert_equal(::RGeo::Feature::MultiPoint, geom_.geometry_type)
27
- assert_equal(2, geom_.num_geometries)
28
- assert(@point1.eql?(geom_[0]))
29
- assert(@point2.eql?(geom_[1]))
30
- end
31
-
32
- def test_creation_empty
33
- geom_ = @factory.multi_point([])
34
- assert_not_nil(geom_)
35
- assert(::RGeo::Feature::MultiPoint === geom_)
36
- assert_equal(::RGeo::Feature::MultiPoint, geom_.geometry_type)
37
- assert_equal(0, geom_.num_geometries)
38
- assert_equal([], geom_.to_a)
39
- end
40
-
41
- def test_creation_casting
42
- mp1_ = @factory.collection([@point3])
43
- mp2_ = @factory.multi_point([@point4])
44
- geom_ = @factory.multi_point([@point1, @point2, mp1_, mp2_])
45
- assert_not_nil(geom_)
46
- assert_equal(::RGeo::Feature::MultiPoint, geom_.geometry_type)
47
- assert_equal(4, geom_.num_geometries)
48
- assert(@point1.eql?(geom_[0]))
49
- assert(@point2.eql?(geom_[1]))
50
- assert(@point3.eql?(geom_[2]))
51
- assert(@point4.eql?(geom_[3]))
52
- end
53
-
54
- def test_creation_wrong_type
55
- line_ = @factory.line_string([@point1, @point2])
56
- geom_ = @factory.multi_point([@point3, line_])
57
- assert_nil(geom_)
58
- end
59
-
60
- def test_required_equivalences
61
- geom1_ = @factory.multi_point([@point1, @point2])
62
- geom2_ = @factory.multi_point([@point1, @point2])
63
- assert(geom1_.eql?(geom2_))
64
- assert(geom1_ == geom2_)
65
- end
66
-
67
- def test_fully_equal
68
- geom1_ = @factory.multi_point([@point1, @point2])
69
- geom2_ = @factory.multi_point([@point1, @point2])
70
- assert(geom1_.rep_equals?(geom2_))
71
- assert(geom1_.equals?(geom2_))
72
- end
73
-
74
- def test_geometrically_equal
75
- geom1_ = @factory.multi_point([@point1, @point4])
76
- geom2_ = @factory.multi_point([@point1, @point4, @point5])
77
- assert(!geom1_.rep_equals?(geom2_))
78
- assert(geom1_.equals?(geom2_))
79
- end
80
-
81
- def test_not_equal
82
- geom1_ = @factory.multi_point([@point1, @point2])
83
- geom2_ = @factory.multi_point([@point1])
84
- assert(!geom1_.rep_equals?(geom2_))
85
- assert(!geom1_.equals?(geom2_))
86
- end
87
-
88
- def test_hashes_equal_for_representationally_equivalent_objects
89
- geom1_ = @factory.multi_point([@point1, @point2])
90
- geom2_ = @factory.multi_point([@point1, @point2])
91
- assert_equal(geom1_.hash, geom2_.hash)
92
- end
93
-
94
- def test_wkt_creation_simple
95
- parsed_geom_ = @factory.parse_wkt("MULTIPOINT((0 0), (-4 2), (-5 3))")
96
- built_geom_ = @factory.multi_point([@point1, @point3, @point4])
97
- assert(built_geom_.eql?(parsed_geom_))
98
- end
99
-
100
- def test_wkt_creation_empty
101
- parsed_geom_ = @factory.parse_wkt("MULTIPOINT EMPTY")
102
- assert(::RGeo::Feature::MultiPoint === parsed_geom_)
103
- assert_equal(0, parsed_geom_.num_geometries)
104
- assert_equal([], parsed_geom_.to_a)
105
- end
106
-
107
- def test_clone
108
- geom1_ = @factory.multi_point([@point1, @point2])
109
- geom2_ = geom1_.clone
110
- assert(geom1_.eql?(geom2_))
111
- assert_equal(::RGeo::Feature::MultiPoint, geom2_.geometry_type)
112
- assert_equal(2, geom2_.num_geometries)
113
- assert(@point1.eql?(geom2_[0]))
114
- assert(@point2.eql?(geom2_[1]))
115
- end
116
-
117
- def test_type_check
118
- geom1_ = @factory.multi_point([@point1, @point2])
119
- assert(::RGeo::Feature::Geometry.check_type(geom1_))
120
- assert(!::RGeo::Feature::Point.check_type(geom1_))
121
- assert(::RGeo::Feature::GeometryCollection.check_type(geom1_))
122
- assert(::RGeo::Feature::MultiPoint.check_type(geom1_))
123
- assert(!::RGeo::Feature::MultiLineString.check_type(geom1_))
124
- geom2_ = @factory.multi_point([])
125
- assert(::RGeo::Feature::Geometry.check_type(geom2_))
126
- assert(!::RGeo::Feature::Point.check_type(geom2_))
127
- assert(::RGeo::Feature::GeometryCollection.check_type(geom2_))
128
- assert(::RGeo::Feature::MultiPoint.check_type(geom2_))
129
- assert(!::RGeo::Feature::MultiLineString.check_type(geom2_))
130
- end
131
-
132
- def test_as_text_wkt_round_trip
133
- geom1_ = @factory.multi_point([@point1, @point2])
134
- text_ = geom1_.as_text
135
- geom2_ = @factory.parse_wkt(text_)
136
- assert(geom1_.eql?(geom2_))
137
- end
138
-
139
- def test_as_binary_wkb_round_trip
140
- geom1_ = @factory.multi_point([@point1, @point2])
141
- binary_ = geom1_.as_binary
142
- geom2_ = @factory.parse_wkb(binary_)
143
- assert(geom1_.eql?(geom2_))
144
- end
145
-
146
- def test_dimension
147
- geom1_ = @factory.multi_point([@point1, @point2])
148
- assert_equal(0, geom1_.dimension)
149
- geom2_ = @factory.multi_point([])
150
- assert_equal(-1, geom2_.dimension)
151
- end
152
-
153
- def test_is_empty
154
- geom1_ = @factory.multi_point([@point1, @point2])
155
- assert(!geom1_.is_empty?)
156
- geom2_ = @factory.multi_point([])
157
- assert(geom2_.is_empty?)
158
- end
159
-
160
- def test_union
161
- geom1_ = @factory.multi_point([@point1, @point2])
162
- geom2_ = @factory.multi_point([@point1, @point3])
163
- geom3_ = @factory.multi_point([@point1, @point2, @point3])
164
- assert_equal(geom3_, geom1_.union(geom2_))
165
- assert_equal(geom3_, geom1_ + geom2_)
166
- end
167
-
168
- def test_difference
169
- geom1_ = @factory.multi_point([@point1, @point2])
170
- geom2_ = @factory.multi_point([@point1, @point3])
171
- assert_equal(@point2, geom1_.difference(geom2_))
172
- assert_equal(@point2, geom1_ - geom2_)
173
- end
174
-
175
- def test_intersection
176
- geom1_ = @factory.multi_point([@point1, @point2])
177
- geom2_ = @factory.multi_point([@point1, @point3])
178
- assert_equal(@point1, geom1_.intersection(geom2_))
179
- assert_equal(@point1, geom1_ * geom2_)
180
- end
181
-
182
- def test_zm
183
- factory_ = create_factory(has_z_coordinate: true, has_m_coordinate: true)
184
- p1_ = factory_.point(1, 2, 3, 4)
185
- mp_ = factory_.multi_point([p1_])
186
- assert_equal(p1_, mp_[0])
187
- end
188
-
189
- def test_coordinate
190
- p0 = @factory.point(0, 0)
191
- p1 = @factory.point(1, 1)
192
- p2 = @factory.point(2, 2)
193
- points = [p0, p1, p2]
194
- mp = @factory.multi_point(points)
195
- assert_equal(mp.coordinates, points.map(&:coordinates))
196
- end
197
- end
198
- end
199
- end
200
- end
@@ -1,191 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Common tests for multi polygon implementations
4
- #
5
- # -----------------------------------------------------------------------------
6
-
7
- require "rgeo"
8
-
9
- module RGeo
10
- module Tests # :nodoc:
11
- module Common # :nodoc:
12
- module MultiPolygonTests # :nodoc:
13
- def setup
14
- create_factories
15
- point1_ = @factory.point(0, 0)
16
- point2_ = @factory.point(0, 10)
17
- point3_ = @factory.point(10, 10)
18
- point4_ = @factory.point(10, 0)
19
- point5_ = @factory.point(4, 4)
20
- point6_ = @factory.point(5, 6)
21
- point7_ = @factory.point(6, 4)
22
- point8_ = @factory.point(0, -10)
23
- point9_ = @factory.point(-10, 0)
24
- exterior1_ = @factory.linear_ring([point1_, point8_, point9_, point1_])
25
- exterior2_ = @factory.linear_ring([point1_, point2_, point3_, point4_, point1_])
26
- exterior3_ = @factory.linear_ring([point1_, point2_, point3_, point1_])
27
- exterior4_ = @factory.linear_ring([point1_, point3_, point4_, point1_])
28
- interior1_ = @factory.linear_ring([point5_, point6_, point7_, point5_])
29
- @poly1 = @factory.polygon(exterior1_)
30
- @poly2 = @factory.polygon(exterior2_, [interior1_])
31
- @poly3 = @factory.polygon(exterior3_)
32
- @poly4 = @factory.polygon(exterior4_)
33
- @line1 = interior1_
34
- end
35
-
36
- def test_creation_simple
37
- geom_ = @factory.multi_polygon([@poly1, @poly2])
38
- assert_not_nil(geom_)
39
- assert(::RGeo::Feature::MultiPolygon === geom_)
40
- assert_equal(::RGeo::Feature::MultiPolygon, geom_.geometry_type)
41
- assert_equal(2, geom_.num_geometries)
42
- assert(@poly1.eql?(geom_[0]))
43
- assert(@poly2.eql?(geom_[1]))
44
- end
45
-
46
- def test_creation_empty
47
- geom_ = @factory.multi_polygon([])
48
- assert_not_nil(geom_)
49
- assert(::RGeo::Feature::MultiPolygon === geom_)
50
- assert_equal(::RGeo::Feature::MultiPolygon, geom_.geometry_type)
51
- assert_equal(0, geom_.num_geometries)
52
- assert_equal([], geom_.to_a)
53
- end
54
-
55
- def test_creation_wrong_type
56
- geom_ = @factory.multi_polygon([@poly1, @line1])
57
- assert_nil(geom_)
58
- end
59
-
60
- def test_creation_overlapping
61
- geom_ = @factory.multi_polygon([@poly1, @poly1])
62
- assert_nil(geom_)
63
- geom2_ = @lenient_factory.multi_polygon([@poly1, @poly1])
64
- assert_not_nil(geom2_)
65
- end
66
-
67
- def test_creation_connected
68
- geom_ = @factory.multi_polygon([@poly3, @poly4])
69
- assert_nil(geom_)
70
- geom2_ = @lenient_factory.multi_polygon([@poly3, @poly4])
71
- assert_not_nil(geom2_)
72
- end
73
-
74
- def test_required_equivalences
75
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
76
- geom2_ = @factory.multi_polygon([@poly1, @poly2])
77
- assert(geom1_.eql?(geom2_))
78
- assert(geom1_ == geom2_)
79
- end
80
-
81
- def test_equal
82
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
83
- geom2_ = @factory.multi_polygon([@poly1, @poly2])
84
- assert(geom1_.rep_equals?(geom2_))
85
- assert(geom1_.equals?(geom2_))
86
- end
87
-
88
- def test_not_equal
89
- geom1_ = @factory.multi_polygon([@poly1])
90
- geom2_ = @factory.multi_polygon([@poly2])
91
- assert(!geom1_.rep_equals?(geom2_))
92
- assert(!geom1_.equals?(geom2_))
93
- end
94
-
95
- def test_hashes_equal_for_representationally_equivalent_objects
96
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
97
- geom2_ = @factory.multi_polygon([@poly1, @poly2])
98
- assert_equal(geom1_.hash, geom2_.hash)
99
- end
100
-
101
- def test_wkt_creation_simple
102
- 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)))")
103
- built_geom_ = @factory.multi_polygon([@poly1, @poly2])
104
- assert(built_geom_.eql?(parsed_geom_))
105
- end
106
-
107
- def test_wkt_creation_empty
108
- parsed_geom_ = @factory.parse_wkt("MULTIPOLYGON EMPTY")
109
- assert_equal(::RGeo::Feature::MultiPolygon, parsed_geom_.geometry_type)
110
- assert_equal(0, parsed_geom_.num_geometries)
111
- assert_equal([], parsed_geom_.to_a)
112
- end
113
-
114
- def test_clone
115
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
116
- geom2_ = geom1_.clone
117
- assert(geom1_.eql?(geom2_))
118
- assert_equal(::RGeo::Feature::MultiPolygon, geom2_.geometry_type)
119
- assert_equal(2, geom2_.num_geometries)
120
- assert(@poly1.eql?(geom2_[0]))
121
- assert(@poly2.eql?(geom2_[1]))
122
- end
123
-
124
- def test_type_check
125
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
126
- assert(::RGeo::Feature::Geometry.check_type(geom1_))
127
- assert(!::RGeo::Feature::Polygon.check_type(geom1_))
128
- assert(::RGeo::Feature::GeometryCollection.check_type(geom1_))
129
- assert(!::RGeo::Feature::MultiPoint.check_type(geom1_))
130
- assert(::RGeo::Feature::MultiPolygon.check_type(geom1_))
131
- geom2_ = @factory.multi_polygon([])
132
- assert(::RGeo::Feature::Geometry.check_type(geom2_))
133
- assert(!::RGeo::Feature::Polygon.check_type(geom2_))
134
- assert(::RGeo::Feature::GeometryCollection.check_type(geom2_))
135
- assert(!::RGeo::Feature::MultiPoint.check_type(geom2_))
136
- assert(::RGeo::Feature::MultiPolygon.check_type(geom2_))
137
- end
138
-
139
- def test_as_text_wkt_round_trip
140
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
141
- text_ = geom1_.as_text
142
- geom2_ = @factory.parse_wkt(text_)
143
- assert(geom1_.eql?(geom2_))
144
- end
145
-
146
- def test_as_binary_wkb_round_trip
147
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
148
- binary_ = geom1_.as_binary
149
- geom2_ = @factory.parse_wkb(binary_)
150
- assert(geom1_.eql?(geom2_))
151
- end
152
-
153
- def test_dimension
154
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
155
- assert_equal(2, geom1_.dimension)
156
- geom2_ = @factory.multi_polygon([])
157
- assert_equal(-1, geom2_.dimension)
158
- end
159
-
160
- def test_is_empty
161
- geom1_ = @factory.multi_polygon([@poly1, @poly2])
162
- assert(!geom1_.is_empty?)
163
- geom2_ = @factory.multi_polygon([])
164
- assert(geom2_.is_empty?)
165
- end
166
-
167
- def test_multi_polygon_coordinates
168
- poly1_coordinates = [
169
- [[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0]],
170
- [[0.25, 0.25], [0.75, 0.25], [0.75, 0.75], [0.25, 0.75], [0.25, 0.25]]
171
- ]
172
- poly2_coordinates = [
173
- [[2.0, 2.0], [3.0, 2.0], [3.0, 3.0], [2.0, 3.0], [2.0, 2.0]],
174
- [[2.25, 2.25], [2.75, 2.25], [2.75, 2.75], [2.25, 2.75], [2.25, 2.25]]
175
- ]
176
-
177
- ring = @factory.line_string(poly1_coordinates.first.map { |(x, y)| @factory.point x, y })
178
- inner_ring = @factory.line_string(poly1_coordinates.last.map { |(x, y)| @factory.point x, y })
179
- poly1 = @factory.polygon ring, [inner_ring]
180
-
181
- ring = @factory.line_string(poly2_coordinates.first.map { |(x, y)| @factory.point x, y })
182
- inner_ring = @factory.line_string(poly2_coordinates.last.map { |(x, y)| @factory.point x, y })
183
- poly2 = @factory.polygon ring, [inner_ring]
184
-
185
- multi_polygon = @factory.multi_polygon [poly1, poly2]
186
- assert_equal(multi_polygon.coordinates, [poly1_coordinates, poly2_coordinates])
187
- end
188
- end
189
- end
190
- end
191
- end
@@ -1,370 +0,0 @@
1
- # -----------------------------------------------------------------------------
2
- #
3
- # Common tests for point implementations
4
- #
5
- # -----------------------------------------------------------------------------
6
-
7
- require "rgeo"
8
-
9
- module RGeo
10
- module Tests # :nodoc:
11
- module Common # :nodoc:
12
- module PointTests # :nodoc:
13
- def assert_close_enough(p1_, p2_)
14
- assert((p1_.x - p2_.x).abs < 0.00000001 && (p1_.y - p2_.y).abs < 0.00000001)
15
- end
16
-
17
- def assert_contains_approx(p_, mp_)
18
- assert(mp_.any? { |q_| (p_.x - q_.x).abs < 0.00000001 && (p_.y - q_.y).abs < 0.00000001 })
19
- end
20
-
21
- def test_creation
22
- point_ = @factory.point(21, -22)
23
- assert_equal(21, point_.x)
24
- assert_equal(-22, point_.y)
25
- end
26
-
27
- def test_wkt_creation
28
- point1_ = @factory.parse_wkt("Point (21 -22)")
29
- assert_equal(21, point1_.x)
30
- assert_equal(-22, point1_.y)
31
- end
32
-
33
- def test_clone
34
- point1_ = @factory.point(11, 12)
35
- point2_ = point1_.clone
36
- assert_equal(point1_, point2_)
37
- point3_ = @factory.point(13, 12)
38
- point4_ = point3_.dup
39
- assert_equal(point3_, point4_)
40
- assert_not_equal(point2_, point4_)
41
- end
42
-
43
- def test_type_check
44
- point_ = @factory.point(21, 22)
45
- assert(::RGeo::Feature::Geometry.check_type(point_))
46
- assert(::RGeo::Feature::Point.check_type(point_))
47
- assert(!::RGeo::Feature::GeometryCollection.check_type(point_))
48
- assert(!::RGeo::Feature::Curve.check_type(point_))
49
- end
50
-
51
- def test_geometry_type
52
- point_ = @factory.point(11, 12)
53
- assert_equal(::RGeo::Feature::Point, point_.geometry_type)
54
- end
55
-
56
- def test_dimension
57
- point_ = @factory.point(11, 12)
58
- assert_equal(0, point_.dimension)
59
- end
60
-
61
- def test_envelope
62
- point_ = @factory.point(11, 12)
63
- assert_close_enough(point_, point_.envelope)
64
- end
65
-
66
- def test_as_text
67
- point_ = @factory.point(11, 12)
68
- assert_equal("POINT (11.0 12.0)", point_.as_text)
69
- end
70
-
71
- def test_as_text_wkt_round_trip
72
- point1_ = @factory.point(11, 12)
73
- text_ = point1_.as_text
74
- point2_ = @factory.parse_wkt(text_)
75
- assert_equal(point2_, point1_)
76
- end
77
-
78
- def test_as_binary_wkb_round_trip
79
- point1_ = @factory.point(211, 12)
80
- binary_ = point1_.as_binary
81
- point2_ = @factory.parse_wkb(binary_)
82
- assert_equal(point2_, point1_)
83
- end
84
-
85
- def test_is_empty
86
- point1_ = @factory.point(0, 0)
87
- assert(!point1_.is_empty?)
88
- end
89
-
90
- def test_is_simple
91
- point1_ = @factory.point(0, 0)
92
- assert(point1_.is_simple?)
93
- end
94
-
95
- def test_boundary
96
- point_ = @factory.point(11, 12)
97
- boundary_ = point_.boundary
98
- assert(boundary_.is_empty?)
99
- end
100
-
101
- def test_equals
102
- point1_ = @factory.point(11, 12)
103
- point2_ = @factory.point(11, 12)
104
- point3_ = @factory.point(13, 12)
105
- assert(point1_.equals?(point2_))
106
- assert(point1_ == point2_)
107
- assert(point1_.rep_equals?(point2_))
108
- assert(point1_.eql?(point2_))
109
- assert(!point1_.equals?(point3_))
110
- assert(point1_ != point3_)
111
- assert(!point1_.rep_equals?(point3_))
112
- assert(!point1_.eql?(point3_))
113
- assert(point1_ != "hello")
114
- assert(!point1_.eql?("hello"))
115
- end
116
-
117
- def test_out_of_order_is_not_equal
118
- point1_ = @factory.point(11, 12)
119
- point2_ = @factory.point(12, 11)
120
- assert_not_equal(point1_, point2_)
121
- assert_not_equal(point1_.hash, point2_.hash)
122
- end
123
-
124
- def test_hashes_equal_for_representationally_equivalent_objects
125
- point1_ = @factory.point(11, 12)
126
- point2_ = @factory.point(11, 12)
127
- assert_equal(point1_.hash, point2_.hash)
128
- end
129
-
130
- def test_point_as_hash_key
131
- hash_ = { @factory.point(11, 12) => :hello }
132
- assert_equal(:hello, hash_[@factory.point(11, 12)])
133
- end
134
-
135
- def test_disjoint
136
- point1_ = @factory.point(11, 12)
137
- point2_ = @factory.point(11, 12)
138
- point3_ = @factory.point(12, 12)
139
- assert(!point1_.disjoint?(point2_))
140
- assert(point1_.disjoint?(point3_))
141
- end
142
-
143
- def test_intersects
144
- point1_ = @factory.point(11, 12)
145
- point2_ = @factory.point(11, 12)
146
- point3_ = @factory.point(12, 12)
147
- assert(point1_.intersects?(point2_))
148
- assert(!point1_.intersects?(point3_))
149
- end
150
-
151
- def test_touches
152
- point1_ = @factory.point(11, 12)
153
- point2_ = @factory.point(11, 12)
154
- point3_ = @factory.point(12, 12)
155
- assert(!point1_.touches?(point2_))
156
- assert(!point1_.touches?(point3_))
157
- end
158
-
159
- def test_crosses
160
- point1_ = @factory.point(11, 12)
161
- point2_ = @factory.point(11, 12)
162
- point3_ = @factory.point(12, 12)
163
- assert(!point1_.crosses?(point2_))
164
- assert(!point1_.crosses?(point3_))
165
- end
166
-
167
- def test_within
168
- point1_ = @factory.point(11, 12)
169
- point2_ = @factory.point(11, 12)
170
- point3_ = @factory.point(12, 12)
171
- assert(point1_.within?(point2_))
172
- assert(!point1_.within?(point3_))
173
- end
174
-
175
- def test_contains
176
- point1_ = @factory.point(11, 12)
177
- point2_ = @factory.point(11, 12)
178
- point3_ = @factory.point(12, 12)
179
- assert(point1_.contains?(point2_))
180
- assert(!point1_.contains?(point3_))
181
- end
182
-
183
- def test_overlaps
184
- point1_ = @factory.point(11, 12)
185
- point2_ = @factory.point(11, 12)
186
- point3_ = @factory.point(12, 12)
187
- assert(!point1_.overlaps?(point2_))
188
- assert(!point1_.overlaps?(point3_))
189
- end
190
-
191
- def test_convex_hull
192
- point_ = @factory.point(11, 12)
193
- assert_close_enough(point_, point_.convex_hull)
194
- end
195
-
196
- def test_intersection
197
- point1_ = @factory.point(11, 12)
198
- point2_ = @factory.point(11, 12)
199
- point3_ = @factory.point(12, 12)
200
- assert_close_enough(point1_, point1_.intersection(point2_))
201
- int13_ = point1_.intersection(point3_)
202
- assert(int13_.is_empty?)
203
- end
204
-
205
- def test_union
206
- point1_ = @factory.point(11, 12)
207
- point2_ = @factory.point(11, 12)
208
- point3_ = @factory.point(12, 12)
209
- union12_ = point1_.union(point2_)
210
- union13_ = point1_.union(point3_)
211
- assert_close_enough(point1_, union12_)
212
- assert_equal(::RGeo::Feature::MultiPoint, union13_.geometry_type)
213
- assert_contains_approx(point1_, union13_)
214
- assert_contains_approx(point3_, union13_)
215
- end
216
-
217
- def test_difference
218
- point1_ = @factory.point(11, 12)
219
- point2_ = @factory.point(11, 12)
220
- point3_ = @factory.point(12, 12)
221
- diff12_ = point1_.difference(point2_)
222
- diff13_ = point1_.difference(point3_)
223
- assert_equal(::RGeo::Feature::GeometryCollection, diff12_.geometry_type)
224
- assert(diff12_.is_empty?)
225
- assert_close_enough(point1_, diff13_)
226
- end
227
-
228
- def test_sym_difference
229
- point1_ = @factory.point(11, 12)
230
- point2_ = @factory.point(11, 12)
231
- point3_ = @factory.point(12, 12)
232
- diff12_ = point1_.sym_difference(point2_)
233
- diff13_ = point1_.sym_difference(point3_)
234
- assert_equal(::RGeo::Feature::GeometryCollection, diff12_.geometry_type)
235
- assert(diff12_.is_empty?)
236
- assert_equal(::RGeo::Feature::MultiPoint, diff13_.geometry_type)
237
- assert_contains_approx(point1_, diff13_)
238
- assert_contains_approx(point3_, diff13_)
239
- end
240
-
241
- def test_buffer
242
- point_ = @factory.point(11, 12)
243
- buffer_ = point_.buffer(4)
244
- assert_equal(::RGeo::Feature::Polygon, buffer_.geometry_type)
245
- assert_equal(33, buffer_.exterior_ring.num_points)
246
- end
247
-
248
- def test_3dz_creation
249
- point_ = @zfactory.point(11, 12, 13)
250
- assert_equal(11, point_.x)
251
- assert_equal(12, point_.y)
252
- assert_equal(13, point_.z)
253
- point2_ = @zfactory.point(21, 22)
254
- assert_equal(21, point2_.x)
255
- assert_equal(22, point2_.y)
256
- assert_equal(0, point2_.z)
257
- end
258
-
259
- def test_3dm_creation
260
- point_ = @mfactory.point(11, 12, 13)
261
- assert_equal(11, point_.x)
262
- assert_equal(12, point_.y)
263
- assert_equal(13, point_.m)
264
- point2_ = @mfactory.point(21, 22)
265
- assert_equal(21, point2_.x)
266
- assert_equal(22, point2_.y)
267
- assert_equal(0, point2_.m)
268
- end
269
-
270
- def test_4d_creation
271
- point_ = @zmfactory.point(11, 12, 13, 14)
272
- assert_equal(11, point_.x)
273
- assert_equal(12, point_.y)
274
- assert_equal(13, point_.z)
275
- assert_equal(14, point_.m)
276
- point2_ = @zmfactory.point(21, 22)
277
- assert_equal(21, point2_.x)
278
- assert_equal(22, point2_.y)
279
- assert_equal(0, point2_.z)
280
- assert_equal(0, point2_.m)
281
- end
282
-
283
- def test_wkt_creation_3d
284
- point2_ = @zfactory.parse_wkt("POINT(11 12 13)")
285
- assert_equal(11, point2_.x)
286
- assert_equal(12, point2_.y)
287
- assert_equal(13, point2_.z)
288
- point1_ = @zfactory.parse_wkt("POINT(21 22)")
289
- assert_equal(21, point1_.x)
290
- assert_equal(22, point1_.y)
291
- # Z is undefined in this case.
292
- # We'd like to define it to be 0, but the GEOS
293
- # parser doesn't behave that way.
294
- end
295
-
296
- def test_marshal_roundtrip
297
- point_ = @factory.point(11, 12)
298
- data_ = ::Marshal.dump(point_)
299
- point2_ = ::Marshal.load(data_)
300
- assert_equal(point_, point2_)
301
- end
302
-
303
- def test_marshal_roundtrip_3d
304
- point_ = @zfactory.point(11, 12, 13)
305
- data_ = ::Marshal.dump(point_)
306
- point2_ = ::Marshal.load(data_)
307
- assert_equal(point_, point2_)
308
- end
309
-
310
- def test_marshal_roundtrip_4d
311
- point_ = @zmfactory.point(11, 12, 13, 14)
312
- data_ = ::Marshal.dump(point_)
313
- point2_ = ::Marshal.load(data_)
314
- assert_equal(point_, point2_)
315
- end
316
-
317
- def test_coordinates
318
- point_ = @factory.point(11.0, 12.0)
319
- assert_equal([11.0, 12.0], point_.coordinates)
320
- end
321
-
322
- def test_coordinates_3dz
323
- point_ = @zfactory.point(11, 12, 13)
324
- assert_equal([11.0, 12.0, 13.0], point_.coordinates)
325
- point2_ = @zfactory.point(21, 22)
326
- assert_equal([21.0, 22.0, 0.0], point2_.coordinates)
327
- end
328
-
329
- def test_coordinates_3dm
330
- point_ = @mfactory.point(11, 12, 13)
331
- assert_equal([11.0, 12.0, 13.0], point_.coordinates)
332
- point2_ = @mfactory.point(21, 22)
333
- assert_equal([21.0, 22.0, 0.0], point2_.coordinates)
334
- end
335
-
336
- def test_coordinates_4d
337
- point_ = @zmfactory.point(11, 12, 13, 14)
338
- assert_equal([11.0, 12.0, 13.0, 14.0], point_.coordinates)
339
- point2_ = @zmfactory.point(21, 22)
340
- assert_equal([21.0, 22.0, 0.0, 0.0], point2_.coordinates)
341
- end
342
-
343
- if ::RGeo.yaml_supported?
344
-
345
- def test_psych_roundtrip
346
- point_ = @factory.point(11, 12)
347
- data_ = ::Psych.dump(point_)
348
- point2_ = ::Psych.load(data_)
349
- assert_equal(point_, point2_)
350
- end
351
-
352
- def test_psych_roundtrip_3d
353
- point_ = @zfactory.point(11, 12, 13)
354
- data_ = ::Psych.dump(point_)
355
- point2_ = ::Psych.load(data_)
356
- assert_equal(point_, point2_)
357
- end
358
-
359
- def test_psych_roundtrip_4d
360
- point_ = @zmfactory.point(11, 12, 13, 14)
361
- data_ = ::Psych.dump(point_)
362
- point2_ = ::Psych.load(data_)
363
- assert_equal(point_, point2_)
364
- end
365
-
366
- end
367
- end
368
- end
369
- end
370
- end