rgeo 3.0.0.pre.rc.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -0
  3. data/ext/geos_c_impl/factory.c +41 -5
  4. data/ext/geos_c_impl/factory.h +13 -2
  5. data/ext/geos_c_impl/geometry.c +151 -122
  6. data/ext/geos_c_impl/geometry_collection.c +17 -19
  7. data/ext/geos_c_impl/line_string.c +46 -36
  8. data/ext/geos_c_impl/point.c +0 -2
  9. data/ext/geos_c_impl/polygon.c +10 -11
  10. data/ext/geos_c_impl/polygon.h +1 -1
  11. data/ext/geos_c_impl/ruby_more.c +7 -0
  12. data/ext/geos_c_impl/ruby_more.h +8 -0
  13. data/lib/rgeo/cartesian/analysis.rb +5 -3
  14. data/lib/rgeo/cartesian/bounding_box.rb +74 -79
  15. data/lib/rgeo/cartesian/calculations.rb +20 -26
  16. data/lib/rgeo/cartesian/factory.rb +47 -49
  17. data/lib/rgeo/cartesian/planar_graph.rb +10 -16
  18. data/lib/rgeo/cartesian/sweepline_intersector.rb +1 -3
  19. data/lib/rgeo/cartesian/valid_op.rb +1 -3
  20. data/lib/rgeo/coord_sys/cs/entities.rb +87 -101
  21. data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
  22. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +70 -29
  23. data/lib/rgeo/feature/curve.rb +0 -1
  24. data/lib/rgeo/feature/factory.rb +25 -27
  25. data/lib/rgeo/feature/factory_generator.rb +3 -4
  26. data/lib/rgeo/feature/geometry.rb +41 -30
  27. data/lib/rgeo/feature/geometry_collection.rb +3 -4
  28. data/lib/rgeo/feature/line_string.rb +1 -2
  29. data/lib/rgeo/feature/linear_ring.rb +0 -1
  30. data/lib/rgeo/feature/multi_curve.rb +0 -1
  31. data/lib/rgeo/feature/multi_surface.rb +0 -1
  32. data/lib/rgeo/feature/point.rb +0 -1
  33. data/lib/rgeo/feature/polygon.rb +1 -2
  34. data/lib/rgeo/feature/surface.rb +0 -1
  35. data/lib/rgeo/feature/types.rb +73 -83
  36. data/lib/rgeo/geographic/factory.rb +87 -80
  37. data/lib/rgeo/geographic/interface.rb +40 -23
  38. data/lib/rgeo/geographic/projected_feature_methods.rb +2 -6
  39. data/lib/rgeo/geographic/projected_window.rb +35 -21
  40. data/lib/rgeo/geographic/simple_mercator_projector.rb +25 -13
  41. data/lib/rgeo/geographic/spherical_feature_methods.rb +8 -3
  42. data/lib/rgeo/geographic/spherical_math.rb +17 -20
  43. data/lib/rgeo/geos/capi_factory.rb +50 -50
  44. data/lib/rgeo/geos/ffi_factory.rb +41 -42
  45. data/lib/rgeo/geos/ffi_feature_methods.rb +72 -97
  46. data/lib/rgeo/geos/interface.rb +16 -16
  47. data/lib/rgeo/geos/utils.rb +3 -3
  48. data/lib/rgeo/geos/zm_factory.rb +50 -42
  49. data/lib/rgeo/geos/zm_feature_methods.rb +15 -8
  50. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +4 -4
  51. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
  52. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +18 -24
  53. data/lib/rgeo/impl_helper/basic_point_methods.rb +1 -3
  54. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +15 -16
  55. data/lib/rgeo/impl_helper/utils.rb +3 -9
  56. data/lib/rgeo/impl_helper/valid_op.rb +12 -16
  57. data/lib/rgeo/version.rb +1 -1
  58. data/lib/rgeo/wkrep/wkb_generator.rb +42 -47
  59. data/lib/rgeo/wkrep/wkb_parser.rb +17 -18
  60. data/lib/rgeo/wkrep/wkt_generator.rb +23 -16
  61. data/lib/rgeo/wkrep/wkt_parser.rb +23 -13
  62. metadata +5 -5
@@ -10,11 +10,18 @@ module RGeo
10
10
  module Cartesian
11
11
  # This class implements the factory for the simple cartesian
12
12
  # implementation.
13
-
14
13
  class Factory
15
14
  include Feature::Factory::Instance
16
15
  include ImplHelper::Utils
17
16
 
17
+ attr_reader :coordinate_dimension, :spatial_dimension
18
+
19
+ # Returns the SRID.
20
+ attr_reader :srid
21
+
22
+ # See RGeo::Feature::Factory#coord_sys
23
+ attr_reader :coord_sys
24
+
18
25
  # Create a new simple cartesian factory.
19
26
  #
20
27
  # See RGeo::Cartesian.simple_factory for a list of supported options.
@@ -35,43 +42,46 @@ module RGeo
35
42
  @buffer_resolution = 1 if @buffer_resolution < 1
36
43
 
37
44
  wkt_generator = opts[:wkt_generator]
38
- case wkt_generator
39
- when Hash
40
- @wkt_generator = WKRep::WKTGenerator.new(wkt_generator)
41
- else
42
- @wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
43
- end
45
+ @wkt_generator =
46
+ case wkt_generator
47
+ when Hash
48
+ WKRep::WKTGenerator.new(wkt_generator)
49
+ else
50
+ WKRep::WKTGenerator.new(convert_case: :upper)
51
+ end
44
52
  wkb_generator = opts[:wkb_generator]
45
- case wkb_generator
46
- when Hash
47
- @wkb_generator = WKRep::WKBGenerator.new(wkb_generator)
48
- else
49
- @wkb_generator = WKRep::WKBGenerator.new
50
- end
53
+ @wkb_generator =
54
+ case wkb_generator
55
+ when Hash
56
+ WKRep::WKBGenerator.new(wkb_generator)
57
+ else
58
+ WKRep::WKBGenerator.new
59
+ end
51
60
  wkt_parser = opts[:wkt_parser]
52
- case wkt_parser
53
- when Hash
54
- @wkt_parser = WKRep::WKTParser.new(self, wkt_parser)
55
- else
56
- @wkt_parser = WKRep::WKTParser.new(self)
57
- end
61
+ @wkt_parser =
62
+ case wkt_parser
63
+ when Hash
64
+ WKRep::WKTParser.new(self, wkt_parser)
65
+ else
66
+ WKRep::WKTParser.new(self)
67
+ end
58
68
  wkb_parser = opts[:wkb_parser]
59
- case wkb_parser
60
- when Hash
61
- @wkb_parser = WKRep::WKBParser.new(self, wkb_parser)
62
- else
63
- @wkb_parser = WKRep::WKBParser.new(self)
64
- end
69
+ @wkb_parser =
70
+ case wkb_parser
71
+ when Hash
72
+ WKRep::WKBParser.new(self, wkb_parser)
73
+ else
74
+ WKRep::WKBParser.new(self)
75
+ end
65
76
  end
66
- attr_reader :coordinate_dimension, :spatial_dimension
67
77
 
68
78
  # Equivalence test.
69
79
 
70
- def eql?(rhs)
71
- rhs.is_a?(self.class) && @srid == rhs.srid &&
72
- @has_z == rhs.property(:has_z_coordinate) &&
73
- @has_m == rhs.property(:has_m_coordinate) &&
74
- @coord_sys == rhs.instance_variable_get(:@coord_sys)
80
+ def eql?(other)
81
+ other.is_a?(self.class) && @srid == other.srid &&
82
+ @has_z == other.property(:has_z_coordinate) &&
83
+ @has_m == other.property(:has_m_coordinate) &&
84
+ @coord_sys == other.instance_variable_get(:@coord_sys)
75
85
  end
76
86
  alias == eql?
77
87
 
@@ -99,11 +109,9 @@ module RGeo
99
109
  end
100
110
 
101
111
  def marshal_load(data) # :nodoc:
102
- if (coord_sys_data = data["cs"])
103
- coord_sys = CoordSys::CONFIG.default_coord_sys_class.create_from_wkt(coord_sys_data)
104
- else
105
- coord_sys = nil
106
- end
112
+ cs_class = CoordSys::CONFIG.default_coord_sys_class
113
+ coord_sys = data["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
114
+
107
115
  initialize(
108
116
  has_z_coordinate: data["hasz"],
109
117
  has_m_coordinate: data["hasm"],
@@ -132,11 +140,9 @@ module RGeo
132
140
  end
133
141
 
134
142
  def init_with(coder) # :nodoc:
135
- if (coord_sys_data = coder["cs"])
136
- coord_sys = CoordSys::CONFIG.default_coord_sys_class.create_from_wkt(coord_sys_data.to_s)
137
- else
138
- coord_sys = nil
139
- end
143
+ cs_class = CoordSys::CONFIG.default_coord_sys_class
144
+ coord_sys = coder["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
145
+
140
146
  initialize(
141
147
  has_z_coordinate: coder["has_z_coordinate"],
142
148
  has_m_coordinate: coder["has_m_coordinate"],
@@ -150,10 +156,6 @@ module RGeo
150
156
  )
151
157
  end
152
158
 
153
- # Returns the SRID.
154
-
155
- attr_reader :srid
156
-
157
159
  # See RGeo::Feature::Factory#property
158
160
 
159
161
  def property(name)
@@ -235,10 +237,6 @@ module RGeo
235
237
  MultiPolygonImpl.new(self, elems)
236
238
  end
237
239
 
238
- # See RGeo::Feature::Factory#coord_sys
239
-
240
- attr_reader :coord_sys
241
-
242
240
  def generate_wkt(obj)
243
241
  @wkt_generator.generate(obj)
244
242
  end
@@ -166,17 +166,15 @@ module RGeo
166
166
  # list of intersections for that edge.
167
167
  s1_intersects = int.point != int.s1.s && int.point != int.s1.e
168
168
  if s1_intersects
169
- unless intersection_map[int.s1]
170
- intersection_map[int.s1] = []
171
- end
169
+ intersection_map[int.s1] ||= []
172
170
  intersection_map[int.s1] << int.point
173
171
  end
174
172
 
175
173
  s2_intersects = int.point != int.s2.s && int.point != int.s2.e
174
+
176
175
  next unless s2_intersects
177
- unless intersection_map[int.s2]
178
- intersection_map[int.s2] = []
179
- end
176
+
177
+ intersection_map[int.s2] ||= []
180
178
  intersection_map[int.s2] << int.point
181
179
  end
182
180
  intersection_map
@@ -194,11 +192,9 @@ module RGeo
194
192
  insert_half_edge(e2)
195
193
  end
196
194
 
197
- def insert_half_edge(he)
198
- unless incident_edges[he.origin.coordinates]
199
- @incident_edges[he.origin.coordinates] = []
200
- end
201
- @incident_edges[he.origin.coordinates] << he
195
+ def insert_half_edge(half_edge)
196
+ @incident_edges[half_edge.origin.coordinates] ||= []
197
+ @incident_edges[half_edge.origin.coordinates] << half_edge
202
198
  end
203
199
 
204
200
  # Links all half-edges where possible.
@@ -299,9 +295,7 @@ module RGeo
299
295
  def add_line_string(geom)
300
296
  add_edges(geom.segments)
301
297
 
302
- hedge = unless geom.empty?
303
- @incident_edges[geom.start_point.coordinates].first
304
- end
298
+ hedge = @incident_edges[geom.start_point.coordinates].first unless geom.empty?
305
299
 
306
300
  @geom_edges << GeomEdge.new(hedge, nil)
307
301
  end
@@ -350,7 +344,7 @@ module RGeo
350
344
  # @param ccw [Boolean] true for CCW, false for CW
351
345
  # @return [HalfEdge, nil]
352
346
  def find_hedge(ring, ccw: true)
353
- return nil if ring.num_points.zero?
347
+ return nil if ring.num_points == 0
354
348
  ccw_target = ccw ? 1 : -1
355
349
 
356
350
  coords = ring.start_point.coordinates
@@ -361,7 +355,7 @@ module RGeo
361
355
  start_seg = Segment.new(ring.start_point, ring.point_n(1))
362
356
  end_seg = Segment.new(ring.point_n(ring.num_points - 2), ring.end_point)
363
357
  colinear_hedges = hedges.select do |he|
364
- start_seg.side(he.destination).zero? || end_seg.side(he.destination).zero?
358
+ start_seg.side(he.destination) == 0 || end_seg.side(he.destination) == 0
365
359
  end
366
360
 
367
361
  colinear_hedges.find do |hedge|
@@ -46,9 +46,7 @@ module RGeo
46
46
  s2 = intersection.s2
47
47
  pt = intersection.point
48
48
 
49
- unless (pt == s1.s && pt == s2.e) || (pt == s1.e && pt == s2.s)
50
- @proper_intersections << intersection
51
- end
49
+ @proper_intersections << intersection unless (pt == s1.s && pt == s2.e) || (pt == s1.e && pt == s2.s)
52
50
  end
53
51
  @proper_intersections
54
52
  end
@@ -33,9 +33,7 @@ module RGeo
33
33
 
34
34
  # if additional nodes were added, there must be an intersection
35
35
  # through a boundary.
36
- if poly.send(:graph).incident_edges.size > num_points
37
- return Error::SELF_INTERSECTION
38
- end
36
+ return Error::SELF_INTERSECTION if poly.send(:graph).incident_edges.size > num_points
39
37
 
40
38
  rings = [poly.exterior_ring] + poly.interior_rings
41
39
  return Error::SELF_INTERSECTION if rings.uniq.size != rings.size