rgeo 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/ext/geos_c_impl/extconf.rb +5 -3
  3. data/ext/geos_c_impl/factory.c +4 -4
  4. data/ext/geos_c_impl/geometry.c +1 -1
  5. data/lib/rgeo.rb +2 -4
  6. data/lib/rgeo/cartesian.rb +6 -16
  7. data/lib/rgeo/cartesian/analysis.rb +22 -20
  8. data/lib/rgeo/cartesian/bounding_box.rb +83 -79
  9. data/lib/rgeo/cartesian/calculations.rb +40 -38
  10. data/lib/rgeo/cartesian/factory.rb +134 -169
  11. data/lib/rgeo/cartesian/feature_classes.rb +2 -18
  12. data/lib/rgeo/cartesian/feature_methods.rb +37 -39
  13. data/lib/rgeo/cartesian/interface.rb +11 -9
  14. data/lib/rgeo/coord_sys.rb +9 -8
  15. data/lib/rgeo/coord_sys/cs/entities.rb +345 -303
  16. data/lib/rgeo/coord_sys/cs/factories.rb +30 -28
  17. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +128 -126
  18. data/lib/rgeo/coord_sys/srs_database/{interface.rb → entry.rb} +26 -32
  19. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +19 -17
  20. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +21 -19
  21. data/lib/rgeo/error.rb +3 -1
  22. data/lib/rgeo/feature.rb +23 -34
  23. data/lib/rgeo/feature/curve.rb +2 -0
  24. data/lib/rgeo/feature/factory.rb +15 -13
  25. data/lib/rgeo/feature/factory_generator.rb +7 -5
  26. data/lib/rgeo/feature/geometry.rb +31 -29
  27. data/lib/rgeo/feature/geometry_collection.rb +6 -4
  28. data/lib/rgeo/feature/line.rb +2 -0
  29. data/lib/rgeo/feature/line_string.rb +3 -1
  30. data/lib/rgeo/feature/linear_ring.rb +2 -0
  31. data/lib/rgeo/feature/multi_curve.rb +2 -0
  32. data/lib/rgeo/feature/multi_line_string.rb +2 -0
  33. data/lib/rgeo/feature/multi_point.rb +2 -0
  34. data/lib/rgeo/feature/multi_polygon.rb +2 -0
  35. data/lib/rgeo/feature/multi_surface.rb +2 -0
  36. data/lib/rgeo/feature/point.rb +2 -0
  37. data/lib/rgeo/feature/polygon.rb +3 -1
  38. data/lib/rgeo/feature/surface.rb +2 -0
  39. data/lib/rgeo/feature/types.rb +107 -103
  40. data/lib/rgeo/geographic.rb +17 -27
  41. data/lib/rgeo/geographic/factory.rb +154 -199
  42. data/lib/rgeo/geographic/interface.rb +141 -137
  43. data/lib/rgeo/geographic/proj4_projector.rb +28 -23
  44. data/lib/rgeo/geographic/projected_feature_classes.rb +2 -18
  45. data/lib/rgeo/geographic/projected_feature_methods.rb +59 -49
  46. data/lib/rgeo/geographic/projected_window.rb +4 -2
  47. data/lib/rgeo/geographic/simple_mercator_projector.rb +41 -39
  48. data/lib/rgeo/geographic/spherical_feature_classes.rb +2 -18
  49. data/lib/rgeo/geographic/spherical_feature_methods.rb +67 -67
  50. data/lib/rgeo/geographic/spherical_math.rb +81 -87
  51. data/lib/rgeo/geos.rb +23 -34
  52. data/lib/rgeo/geos/capi_factory.rb +106 -135
  53. data/lib/rgeo/geos/capi_feature_classes.rb +19 -37
  54. data/lib/rgeo/geos/ffi_factory.rb +276 -297
  55. data/lib/rgeo/geos/ffi_feature_classes.rb +2 -20
  56. data/lib/rgeo/geos/ffi_feature_methods.rb +170 -166
  57. data/lib/rgeo/geos/interface.rb +25 -23
  58. data/lib/rgeo/geos/utils.rb +47 -39
  59. data/lib/rgeo/geos/zm_factory.rb +171 -185
  60. data/lib/rgeo/geos/zm_feature_classes.rb +2 -20
  61. data/lib/rgeo/geos/zm_feature_methods.rb +76 -72
  62. data/lib/rgeo/impl_helper.rb +1 -11
  63. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +72 -75
  64. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +21 -23
  65. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +57 -49
  66. data/lib/rgeo/impl_helper/basic_point_methods.rb +29 -25
  67. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +31 -27
  68. data/lib/rgeo/impl_helper/math.rb +2 -0
  69. data/lib/rgeo/impl_helper/utils.rb +9 -15
  70. data/lib/rgeo/version.rb +3 -1
  71. data/lib/rgeo/wkrep.rb +20 -30
  72. data/lib/rgeo/wkrep/wkb_generator.rb +87 -84
  73. data/lib/rgeo/wkrep/wkb_parser.rb +93 -93
  74. data/lib/rgeo/wkrep/wkt_generator.rb +67 -63
  75. data/lib/rgeo/wkrep/wkt_parser.rb +172 -168
  76. metadata +17 -32
  77. data/lib/rgeo/feature/mixins.rb +0 -143
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Projected geographic common method definitions
@@ -29,94 +31,88 @@ module RGeo
29
31
  end
30
32
 
31
33
  def boundary
32
- boundary_ = projection.boundary
33
- boundary_ ? factory.unproject(boundary_) : nil
34
+ boundary = projection.boundary
35
+ boundary ? factory.unproject(boundary) : nil
34
36
  end
35
37
 
36
- def equals?(rhs_)
37
- projection.equals?(Feature.cast(rhs_, factory).projection)
38
+ def equals?(rhs)
39
+ projection.equals?(Feature.cast(rhs, factory).projection)
38
40
  end
39
41
 
40
- def disjoint?(rhs_)
41
- projection.disjoint?(Feature.cast(rhs_, factory).projection)
42
+ def disjoint?(rhs)
43
+ projection.disjoint?(Feature.cast(rhs, factory).projection)
42
44
  end
43
45
 
44
- def intersects?(rhs_)
45
- projection.intersects?(Feature.cast(rhs_, factory).projection)
46
+ def intersects?(rhs)
47
+ projection.intersects?(Feature.cast(rhs, factory).projection)
46
48
  end
47
49
 
48
- def touches?(rhs_)
49
- projection.touches?(Feature.cast(rhs_, factory).projection)
50
+ def touches?(rhs)
51
+ projection.touches?(Feature.cast(rhs, factory).projection)
50
52
  end
51
53
 
52
- def crosses?(rhs_)
53
- projection.crosses?(Feature.cast(rhs_, factory).projection)
54
+ def crosses?(rhs)
55
+ projection.crosses?(Feature.cast(rhs, factory).projection)
54
56
  end
55
57
 
56
- def within?(rhs_)
57
- projection.within?(Feature.cast(rhs_, factory).projection)
58
+ def within?(rhs)
59
+ projection.within?(Feature.cast(rhs, factory).projection)
58
60
  end
59
61
 
60
- def contains?(rhs_)
61
- projection.contains?(Feature.cast(rhs_, factory).projection)
62
+ def contains?(rhs)
63
+ projection.contains?(Feature.cast(rhs, factory).projection)
62
64
  end
63
65
 
64
- def overlaps?(rhs_)
65
- projection.overlaps?(Feature.cast(rhs_, factory).projection)
66
+ def overlaps?(rhs)
67
+ projection.overlaps?(Feature.cast(rhs, factory).projection)
66
68
  end
67
69
 
68
- def relate(rhs_, pattern_)
69
- projection.relate(Feature.cast(rhs_, factory).projection, pattern_)
70
+ def relate(rhs, pattern_)
71
+ projection.relate(Feature.cast(rhs, factory).projection, pattern_)
70
72
  end
71
73
 
72
- def distance(rhs_)
73
- projection.distance(Feature.cast(rhs_, factory).projection)
74
+ def distance(rhs)
75
+ projection.distance(Feature.cast(rhs, factory).projection)
74
76
  end
75
77
 
76
- def buffer(distance_)
77
- factory.unproject(projection.buffer(distance_))
78
+ def buffer(distance)
79
+ factory.unproject(projection.buffer(distance))
78
80
  end
79
81
 
80
- def buffer_with_style(distance_, endCapStyle_, joinStyle_, mitreLimit_)
81
- factory.unproject(projection.buffer_with_style(distance_, endCapStyle_, joinStyle_, mitreLimit_))
82
+ def buffer_with_style(distance, end_cap_style, join_style, mitre_limit)
83
+ factory.unproject(projection.buffer_with_style(distance, end_cap_style, join_style, mitre_limit))
82
84
  end
83
85
 
84
- def simplify(tolerance_)
85
- factory.unproject(projection.simplify(tolerance_))
86
+ def simplify(tolerance)
87
+ factory.unproject(projection.simplify(tolerance))
86
88
  end
87
89
 
88
- def simplify_preserve_topology(tolerance_)
89
- factory.unproject(projection.simplify_preserve_topology(tolerance_))
90
+ def simplify_preserve_topology(tolerance)
91
+ factory.unproject(projection.simplify_preserve_topology(tolerance))
90
92
  end
91
93
 
92
94
  def convex_hull
93
95
  factory.unproject(projection.convex_hull)
94
96
  end
95
97
 
96
- def intersection(rhs_)
97
- factory.unproject(projection.intersection(Feature.cast(rhs_, factory).projection))
98
+ def intersection(rhs)
99
+ factory.unproject(projection.intersection(Feature.cast(rhs, factory).projection))
98
100
  end
99
101
 
100
- def union(rhs_)
101
- factory.unproject(projection.union(Feature.cast(rhs_, factory).projection))
102
+ def union(rhs)
103
+ factory.unproject(projection.union(Feature.cast(rhs, factory).projection))
102
104
  end
103
105
 
104
- def difference(rhs_)
105
- factory.unproject(projection.difference(Feature.cast(rhs_, factory).projection))
106
+ def difference(rhs)
107
+ factory.unproject(projection.difference(Feature.cast(rhs, factory).projection))
106
108
  end
107
109
 
108
- def sym_difference(rhs_)
109
- factory.unproject(projection.sym_difference(Feature.cast(rhs_, factory).projection))
110
+ def sym_difference(rhs)
111
+ factory.unproject(projection.sym_difference(Feature.cast(rhs, factory).projection))
110
112
  end
111
113
  end
112
114
 
113
115
  module ProjectedPointMethods # :nodoc:
114
- def _validate_geometry
115
- @y = 85.0511287 if @y > 85.0511287
116
- @y = -85.0511287 if @y < -85.0511287
117
- super
118
- end
119
-
120
116
  def canonical_x
121
117
  x_ = @x % 360.0
122
118
  x_ -= 360.0 if x_ > 180.0
@@ -133,14 +129,22 @@ module RGeo
133
129
  end
134
130
  end
135
131
 
136
- def self.included(klass_)
137
- klass_.module_eval do
132
+ def self.included(klass)
133
+ klass.module_eval do
138
134
  alias_method :longitude, :x
139
135
  alias_method :lon, :x
140
136
  alias_method :latitude, :y
141
137
  alias_method :lat, :y
142
138
  end
143
139
  end
140
+
141
+ private
142
+
143
+ def validate_geometry
144
+ @y = 85.0511287 if @y > 85.0511287
145
+ @y = -85.0511287 if @y < -85.0511287
146
+ super
147
+ end
144
148
  end
145
149
 
146
150
  module ProjectedNCurveMethods # :nodoc:
@@ -150,7 +154,9 @@ module RGeo
150
154
  end
151
155
 
152
156
  module ProjectedLineStringMethods # :nodoc:
153
- def _validate_geometry
157
+ private
158
+
159
+ def validate_geometry
154
160
  @points = @points.map(&:canonical_point)
155
161
  super
156
162
  end
@@ -171,7 +177,9 @@ module RGeo
171
177
  end
172
178
 
173
179
  module ProjectedPolygonMethods # :nodoc:
174
- def _validate_geometry
180
+ private
181
+
182
+ def validate_geometry
175
183
  super
176
184
  unless projection
177
185
  raise Error::InvalidGeometry, "Polygon failed assertions"
@@ -180,7 +188,9 @@ module RGeo
180
188
  end
181
189
 
182
190
  module ProjectedMultiPolygonMethods # :nodoc:
183
- def _validate_geometry
191
+ private
192
+
193
+ def validate_geometry
184
194
  super
185
195
  unless projection
186
196
  raise Error::InvalidGeometry, "MultiPolygon failed assertions"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # A projected window in a geography implementation
@@ -212,7 +214,7 @@ module RGeo
212
214
  # this window.
213
215
 
214
216
  def contains_window?(window_)
215
- return nil if window_.factory != @factory
217
+ return if window_.factory != @factory
216
218
  if window_.y_max <= @y_max && window_.y_min >= @y_min
217
219
  if (@x_max < @x_min) == window_.crosses_seam?
218
220
  window_.x_max <= @x_max && window_.x_min >= @x_min
@@ -354,7 +356,7 @@ module RGeo
354
356
  y_max_ = y_ if !y_max_ || y_max_ < y_
355
357
  y_min_ = y_ if !y_min_ || y_min_ > y_
356
358
  end
357
- return nil unless factory_
359
+ return unless factory_
358
360
  if x_array_
359
361
  x_array_.sort!
360
362
  largest_span_ = nil
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Simple mercator projection
@@ -9,76 +11,76 @@ module RGeo
9
11
  class SimpleMercatorProjector # :nodoc:
10
12
  EQUATORIAL_RADIUS = 6_378_137.0
11
13
 
12
- def initialize(geography_factory_, opts_ = {})
13
- @geography_factory = geography_factory_
14
+ def initialize(geography_factory, opts = {})
15
+ @geography_factory = geography_factory
14
16
  @projection_factory = Cartesian.preferred_factory(srid: 3857,
15
17
  proj4: SimpleMercatorProjector._proj4_3857,
16
18
  coord_sys: SimpleMercatorProjector._coordsys_3857,
17
- buffer_resolution: opts_[:buffer_resolution],
18
- lenient_multi_polygon_assertions: opts_[:lenient_multi_polygon_assertions],
19
- uses_lenient_assertions: opts_[:uses_lenient_assertions],
20
- has_z_coordinate: opts_[:has_z_coordinate],
21
- has_m_coordinate: opts_[:has_m_coordinate])
19
+ buffer_resolution: opts[:buffer_resolution],
20
+ lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions],
21
+ uses_lenient_assertions: opts[:uses_lenient_assertions],
22
+ has_z_coordinate: opts[:has_z_coordinate],
23
+ has_m_coordinate: opts[:has_m_coordinate])
22
24
  end
23
25
 
24
- def _set_factories(geography_factory_, projection_factory_) # :nodoc:
25
- @geography_factory = geography_factory_
26
- @projection_factory = projection_factory_
26
+ def set_factories(geography_factory, projection_factory)
27
+ @geography_factory = geography_factory
28
+ @projection_factory = projection_factory
27
29
  end
28
30
 
29
31
  attr_reader :projection_factory
30
32
 
31
- def project(geometry_)
32
- case geometry_
33
+ def project(geometry)
34
+ case geometry
33
35
  when Feature::Point
34
36
  rpd_ = ImplHelper::Math::RADIANS_PER_DEGREE
35
- radius_ = EQUATORIAL_RADIUS
36
- @projection_factory.point(geometry_.x * rpd_ * radius_,
37
- ::Math.log(::Math.tan(::Math::PI / 4.0 + geometry_.y * rpd_ / 2.0)) * radius_)
37
+ radius = EQUATORIAL_RADIUS
38
+ @projection_factory.point(geometry.x * rpd_ * radius,
39
+ Math.log(Math.tan(Math::PI / 4.0 + geometry.y * rpd_ / 2.0)) * radius)
38
40
  when Feature::Line
39
- @projection_factory.line(project(geometry_.start_point), project(geometry_.end_point))
41
+ @projection_factory.line(project(geometry.start_point), project(geometry.end_point))
40
42
  when Feature::LinearRing
41
- @projection_factory.linear_ring(geometry_.points.map { |p_| project(p_) })
43
+ @projection_factory.linear_ring(geometry.points.map { |p| project(p) })
42
44
  when Feature::LineString
43
- @projection_factory.line_string(geometry_.points.map { |p_| project(p_) })
45
+ @projection_factory.line_string(geometry.points.map { |p| project(p) })
44
46
  when Feature::Polygon
45
- @projection_factory.polygon(project(geometry_.exterior_ring),
46
- geometry_.interior_rings.map { |p_| project(p_) })
47
+ @projection_factory.polygon(project(geometry.exterior_ring),
48
+ geometry.interior_rings.map { |p| project(p) })
47
49
  when Feature::MultiPoint
48
- @projection_factory.multi_point(geometry_.map { |p_| project(p_) })
50
+ @projection_factory.multi_point(geometry.map { |p| project(p) })
49
51
  when Feature::MultiLineString
50
- @projection_factory.multi_line_string(geometry_.map { |p_| project(p_) })
52
+ @projection_factory.multi_line_string(geometry.map { |p| project(p) })
51
53
  when Feature::MultiPolygon
52
- @projection_factory.multi_polygon(geometry_.map { |p_| project(p_) })
54
+ @projection_factory.multi_polygon(geometry.map { |p| project(p) })
53
55
  when Feature::GeometryCollection
54
- @projection_factory.collection(geometry_.map { |p_| project(p_) })
56
+ @projection_factory.collection(geometry.map { |p| project(p) })
55
57
  end
56
58
  end
57
59
 
58
- def unproject(geometry_)
59
- case geometry_
60
+ def unproject(geometry)
61
+ case geometry
60
62
  when Feature::Point
61
- dpr_ = ImplHelper::Math::DEGREES_PER_RADIAN
62
- radius_ = EQUATORIAL_RADIUS
63
- @geography_factory.point(geometry_.x / radius_ * dpr_,
64
- (2.0 * ::Math.atan(::Math.exp(geometry_.y / radius_)) - ::Math::PI / 2.0) * dpr_)
63
+ dpr = ImplHelper::Math::DEGREES_PER_RADIAN
64
+ radius = EQUATORIAL_RADIUS
65
+ @geography_factory.point(geometry.x / radius * dpr,
66
+ (2.0 * Math.atan(Math.exp(geometry.y / radius)) - Math::PI / 2.0) * dpr)
65
67
  when Feature::Line
66
- @geography_factory.line(unproject(geometry_.start_point), unproject(geometry_.end_point))
68
+ @geography_factory.line(unproject(geometry.start_point), unproject(geometry.end_point))
67
69
  when Feature::LinearRing
68
- @geography_factory.linear_ring(geometry_.points.map { |p_| unproject(p_) })
70
+ @geography_factory.linear_ring(geometry.points.map { |p| unproject(p) })
69
71
  when Feature::LineString
70
- @geography_factory.line_string(geometry_.points.map { |p_| unproject(p_) })
72
+ @geography_factory.line_string(geometry.points.map { |p| unproject(p) })
71
73
  when Feature::Polygon
72
- @geography_factory.polygon(unproject(geometry_.exterior_ring),
73
- geometry_.interior_rings.map { |p_| unproject(p_) })
74
+ @geography_factory.polygon(unproject(geometry.exterior_ring),
75
+ geometry.interior_rings.map { |p| unproject(p) })
74
76
  when Feature::MultiPoint
75
- @geography_factory.multi_point(geometry_.map { |p_| unproject(p_) })
77
+ @geography_factory.multi_point(geometry.map { |p| unproject(p) })
76
78
  when Feature::MultiLineString
77
- @geography_factory.multi_line_string(geometry_.map { |p_| unproject(p_) })
79
+ @geography_factory.multi_line_string(geometry.map { |p| unproject(p) })
78
80
  when Feature::MultiPolygon
79
- @geography_factory.multi_polygon(geometry_.map { |p_| unproject(p_) })
81
+ @geography_factory.multi_polygon(geometry.map { |p| unproject(p) })
80
82
  when Feature::GeometryCollection
81
- @geography_factory.collection(geometry_.map { |p_| unproject(p_) })
83
+ @geography_factory.collection(geometry.map { |p| unproject(p) })
82
84
  end
83
85
  end
84
86
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Spherical geographic feature classes
@@ -12,8 +14,6 @@ module RGeo
12
14
  include ImplHelper::BasicPointMethods
13
15
  include SphericalGeometryMethods
14
16
  include SphericalPointMethods
15
-
16
- Feature::MixinCollection::GLOBAL.for_type(Feature::Point).include_in_class(self, true)
17
17
  end
18
18
 
19
19
  class SphericalLineStringImpl # :nodoc:
@@ -22,8 +22,6 @@ module RGeo
22
22
  include ImplHelper::BasicLineStringMethods
23
23
  include SphericalGeometryMethods
24
24
  include SphericalLineStringMethods
25
-
26
- Feature::MixinCollection::GLOBAL.for_type(Feature::LineString).include_in_class(self, true)
27
25
  end
28
26
 
29
27
  class SphericalLineImpl # :nodoc:
@@ -33,8 +31,6 @@ module RGeo
33
31
  include ImplHelper::BasicLineMethods
34
32
  include SphericalGeometryMethods
35
33
  include SphericalLineStringMethods
36
-
37
- Feature::MixinCollection::GLOBAL.for_type(Feature::Line).include_in_class(self, true)
38
34
  end
39
35
 
40
36
  class SphericalLinearRingImpl # :nodoc:
@@ -44,8 +40,6 @@ module RGeo
44
40
  include ImplHelper::BasicLinearRingMethods
45
41
  include SphericalGeometryMethods
46
42
  include SphericalLineStringMethods
47
-
48
- Feature::MixinCollection::GLOBAL.for_type(Feature::LinearRing).include_in_class(self, true)
49
43
  end
50
44
 
51
45
  class SphericalPolygonImpl # :nodoc:
@@ -53,8 +47,6 @@ module RGeo
53
47
  include ImplHelper::BasicGeometryMethods
54
48
  include ImplHelper::BasicPolygonMethods
55
49
  include SphericalGeometryMethods
56
-
57
- Feature::MixinCollection::GLOBAL.for_type(Feature::Polygon).include_in_class(self, true)
58
50
  end
59
51
 
60
52
  class SphericalGeometryCollectionImpl # :nodoc:
@@ -62,8 +54,6 @@ module RGeo
62
54
  include ImplHelper::BasicGeometryMethods
63
55
  include ImplHelper::BasicGeometryCollectionMethods
64
56
  include SphericalGeometryMethods
65
-
66
- Feature::MixinCollection::GLOBAL.for_type(Feature::GeometryCollection).include_in_class(self, true)
67
57
  end
68
58
 
69
59
  class SphericalMultiPointImpl # :nodoc:
@@ -72,8 +62,6 @@ module RGeo
72
62
  include ImplHelper::BasicGeometryCollectionMethods
73
63
  include ImplHelper::BasicMultiPointMethods
74
64
  include SphericalGeometryMethods
75
-
76
- Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPoint).include_in_class(self, true)
77
65
  end
78
66
 
79
67
  class SphericalMultiLineStringImpl # :nodoc:
@@ -83,8 +71,6 @@ module RGeo
83
71
  include ImplHelper::BasicMultiLineStringMethods
84
72
  include SphericalGeometryMethods
85
73
  include SphericalMultiLineStringMethods
86
-
87
- Feature::MixinCollection::GLOBAL.for_type(Feature::MultiLineString).include_in_class(self, true)
88
74
  end
89
75
 
90
76
  class SphericalMultiPolygonImpl # :nodoc:
@@ -93,8 +79,6 @@ module RGeo
93
79
  include ImplHelper::BasicGeometryCollectionMethods
94
80
  include ImplHelper::BasicMultiPolygonMethods
95
81
  include SphericalGeometryMethods
96
-
97
- Feature::MixinCollection::GLOBAL.for_type(Feature::MultiPolygon).include_in_class(self, true)
98
82
  end
99
83
  end
100
84
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Spherical geographic common methods
@@ -13,121 +15,119 @@ module RGeo
13
15
  end
14
16
 
15
17
  module SphericalPointMethods # :nodoc:
16
- def _validate_geometry
17
- if @x < -180.0 || @x > 180.0
18
- @x = @x % 360.0
19
- @x -= 360.0 if @x > 180.0
20
- end
21
- @y = 90.0 if @y > 90.0
22
- @y = -90.0 if @y < -90.0
23
- super
24
- end
25
-
26
- def _xyz
18
+ def xyz
27
19
  @xyz ||= SphericalMath::PointXYZ.from_latlon(@y, @x)
28
20
  end
29
21
 
30
- def distance(rhs_)
31
- rhs_ = Feature.cast(rhs_, @factory)
32
- case rhs_
22
+ def distance(rhs)
23
+ rhs = Feature.cast(rhs, @factory)
24
+ case rhs
33
25
  when SphericalPointImpl
34
- _xyz.dist_to_point(rhs_._xyz) * SphericalMath::RADIUS
26
+ xyz.dist_to_point(rhs.xyz) * SphericalMath::RADIUS
35
27
  else
36
28
  super
37
29
  end
38
30
  end
39
31
 
40
- def equals?(rhs_)
41
- return false unless rhs_.is_a?(self.class) && rhs_.factory == factory
42
- case rhs_
32
+ def equals?(rhs)
33
+ return false unless rhs.is_a?(self.class) && rhs.factory == factory
34
+ case rhs
43
35
  when Feature::Point
44
36
  if @y == 90
45
- rhs_.y == 90
37
+ rhs.y == 90
46
38
  elsif @y == -90
47
- rhs_.y == -90
39
+ rhs.y == -90
48
40
  else
49
- rhs_.x == @x && rhs_.y == @y
41
+ rhs.x == @x && rhs.y == @y
50
42
  end
51
43
  when Feature::LineString
52
- rhs_.num_points > 0 && rhs_.points.all? { |elem_| equals?(elem_) }
44
+ rhs.num_points > 0 && rhs.points.all? { |elem| equals?(elem) }
53
45
  when Feature::GeometryCollection
54
- rhs_.num_geometries > 0 && rhs_.all? { |elem_| equals?(elem_) }
46
+ rhs.num_geometries > 0 && rhs.all? { |elem| equals?(elem) }
55
47
  else
56
48
  false
57
49
  end
58
50
  end
59
51
 
60
- def buffer(distance_)
61
- radius_ = distance_ / SphericalMath::RADIUS
62
- radius_ = 1.5 if radius_ > 1.5
63
- cos_ = ::Math.cos(radius_)
64
- sin_ = ::Math.sin(radius_)
65
- point_count_ = factory.property(:buffer_resolution) * 4
66
- p0_ = _xyz
67
- p1_ = p0_.create_perpendicular
68
- p2_ = p1_ % p0_
69
- angle_ = ::Math::PI * 2.0 / point_count_
70
- points_ = (0...point_count_).map do |i_|
71
- r_ = angle_ * i_
72
- pi_ = SphericalMath::PointXYZ.weighted_combination(p1_, ::Math.cos(r_), p2_, ::Math.sin(r_))
73
- p_ = SphericalMath::PointXYZ.weighted_combination(p0_, cos_, pi_, sin_)
74
- factory.point(*p_.lonlat)
52
+ def buffer(distance)
53
+ radius = distance / SphericalMath::RADIUS
54
+ radius = 1.5 if radius > 1.5
55
+ cos = Math.cos(radius)
56
+ sin = Math.sin(radius)
57
+ point_count = factory.property(:buffer_resolution) * 4
58
+ p0 = xyz
59
+ p1 = p0.create_perpendicular
60
+ p2 = p1 % p0
61
+ angle = Math::PI * 2.0 / point_count
62
+ points = (0...point_count).map do |i|
63
+ r = angle * i
64
+ pi = SphericalMath::PointXYZ.weighted_combination(p1, Math.cos(r), p2, Math.sin(r))
65
+ p = SphericalMath::PointXYZ.weighted_combination(p0, cos, pi, sin)
66
+ factory.point(*p.lonlat)
75
67
  end
76
- factory.polygon(factory.linear_ring(points_))
68
+ factory.polygon(factory.linear_ring(points))
77
69
  end
78
70
 
79
- def self.included(klass_)
80
- klass_.module_eval do
71
+ def self.included(klass)
72
+ klass.module_eval do
81
73
  alias_method :longitude, :x
82
74
  alias_method :lon, :x
83
75
  alias_method :latitude, :y
84
76
  alias_method :lat, :y
85
77
  end
86
78
  end
79
+
80
+ private
81
+
82
+ def validate_geometry
83
+ if @x < -180.0 || @x > 180.0
84
+ @x = @x % 360.0
85
+ @x -= 360.0 if @x > 180.0
86
+ end
87
+ @y = 90.0 if @y > 90.0
88
+ @y = -90.0 if @y < -90.0
89
+ super
90
+ end
87
91
  end
88
92
 
89
93
  module SphericalLineStringMethods # :nodoc:
90
- def _arcs
91
- unless defined?(@arcs)
92
- @arcs = (0..num_points - 2).map do |i_|
93
- SphericalMath::ArcXYZ.new(point_n(i_)._xyz, point_n(i_ + 1)._xyz)
94
- end
94
+ def arcs
95
+ @arcs ||= (0..num_points - 2).map do |i|
96
+ SphericalMath::ArcXYZ.new(point_n(i).xyz, point_n(i + 1).xyz)
95
97
  end
96
- @arcs
97
98
  end
98
99
 
99
100
  def is_simple?
100
- arcs_ = _arcs
101
- len_ = arcs_.length
102
- return false if arcs_.any?(&:degenerate?)
103
- return true if len_ == 1
104
- return arcs_[0].s != arcs_[1].e if len_ == 2
105
- arcs_.each_with_index do |arc_, index_|
106
- nindex_ = index_ + 1
107
- nindex_ = nil if nindex_ == len_
108
- return false if nindex_ && arc_.contains_point?(arcs_[nindex_].e)
109
- pindex_ = index_ - 1
110
- pindex_ = nil if pindex_ < 0
111
- return false if pindex_ && arc_.contains_point?(arcs_[pindex_].s)
112
- next unless nindex_
113
- oindex_ = nindex_ + 1
114
- while oindex_ < len_
115
- oarc_ = arcs_[oindex_]
116
- return false if !(index_ == 0 && oindex_ == len_ - 1 && arc_.s == oarc_.e) && arc_.intersects_arc?(oarc_)
117
- oindex_ += 1
101
+ len = arcs.length
102
+ return false if arcs.any?(&:degenerate?)
103
+ return true if len == 1
104
+ return arcs[0].s != arcs[1].e if len == 2
105
+ arcs.each_with_index do |arc, index|
106
+ nindex = index + 1
107
+ nindex = nil if nindex == len
108
+ return false if nindex && arc.contains_point?(arcs[nindex].e)
109
+ pindex = index - 1
110
+ pindex = nil if pindex < 0
111
+ return false if pindex && arc.contains_point?(arcs[pindex].s)
112
+ next unless nindex
113
+ oindex = nindex + 1
114
+ while oindex < len
115
+ oarc = arcs[oindex]
116
+ return false if !(index == 0 && oindex == len - 1 && arc.s == oarc.e) && arc.intersects_arc?(oarc)
117
+ oindex += 1
118
118
  end
119
119
  end
120
120
  true
121
121
  end
122
122
 
123
123
  def length
124
- _arcs.inject(0.0) { |sum_, arc_| sum_ + arc_.length } * SphericalMath::RADIUS
124
+ arcs.inject(0.0) { |sum, arc| sum + arc.length } * SphericalMath::RADIUS
125
125
  end
126
126
  end
127
127
 
128
128
  module SphericalMultiLineStringMethods # :nodoc:
129
129
  def length
130
- inject(0.0) { |sum_, geom_| sum_ + geom_.length }
130
+ inject(0.0) { |sum, geom| sum + geom.length }
131
131
  end
132
132
  end
133
133
  end