ffi-geos 2.0.0 → 2.1.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.
@@ -34,7 +34,7 @@ module Geos
34
34
  end
35
35
 
36
36
  def dump_points(cur_path = [])
37
- points = [ exterior_ring.dump_points ]
37
+ points = [exterior_ring.dump_points]
38
38
 
39
39
  interior_rings.each do |ring|
40
40
  points.push(ring.dump_points)
@@ -44,25 +44,25 @@ module Geos
44
44
  end
45
45
 
46
46
  def snap_to_grid!(*args)
47
- if !self.empty?
47
+ unless empty?
48
48
  exterior_ring = self.exterior_ring.coord_seq.snap_to_grid!(*args)
49
49
 
50
- if exterior_ring.length == 0
51
- @ptr = Geos.create_empty_polygon(:srid => self.srid).ptr
50
+ if exterior_ring.empty?
51
+ @ptr = Geos.create_empty_polygon(srid: srid).ptr
52
52
  elsif exterior_ring.length < 4
53
- raise Geos::InvalidGeometryError.new("snap_to_grid! produced an invalid number of points in exterior ring - found #{exterior_ring.length} - must be 0 or >= 4")
53
+ raise Geos::InvalidGeometryError, "snap_to_grid! produced an invalid number of points in exterior ring - found #{exterior_ring.length} - must be 0 or >= 4"
54
54
  else
55
55
  interior_rings = []
56
56
 
57
- self.num_interior_rings.times { |i|
58
- interior_ring = self.interior_ring_n(i).coord_seq.snap_to_grid!(*args)
57
+ num_interior_rings.times do |i|
58
+ interior_ring = interior_ring_n(i).coord_seq.snap_to_grid!(*args)
59
59
 
60
60
  interior_rings << interior_ring unless interior_ring.length < 4
61
- }
61
+ end
62
62
 
63
63
  interior_rings.compact!
64
64
 
65
- polygon = Geos.create_polygon(exterior_ring, interior_rings, :srid => self.srid)
65
+ polygon = Geos.create_polygon(exterior_ring, interior_rings, srid: srid)
66
66
  @ptr = polygon.ptr
67
67
  end
68
68
  end
@@ -71,33 +71,47 @@ module Geos
71
71
  end
72
72
 
73
73
  def snap_to_grid(*args)
74
- ret = self.dup.snap_to_grid!(*args)
75
- ret.srid = pick_srid_according_to_policy(self.srid)
74
+ ret = dup.snap_to_grid!(*args)
75
+ ret.srid = pick_srid_according_to_policy(srid)
76
76
  ret
77
77
  end
78
78
 
79
79
  %w{ max min }.each do |op|
80
80
  %w{ x y }.each do |dimension|
81
- self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
82
- def #{dimension}_#{op}
83
- unless self.empty?
84
- self.envelope.exterior_ring.#{dimension}_#{op}
81
+ native_method = "GEOSGeom_get#{dimension.upcase}#{op[0].upcase}#{op[1..-1]}_r"
82
+
83
+ if FFIGeos.respond_to?(native_method)
84
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
85
+ def #{dimension}_#{op}
86
+ return if empty?
87
+
88
+ double_ptr = FFI::MemoryPointer.new(:double)
89
+ FFIGeos.#{native_method}(Geos.current_handle_pointer, ptr, double_ptr)
90
+ double_ptr.read_double
85
91
  end
86
- end
87
- EOF
92
+ RUBY
93
+ else
94
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
95
+ def #{dimension}_#{op}
96
+ unless empty?
97
+ envelope.exterior_ring.#{dimension}_#{op}
98
+ end
99
+ end
100
+ RUBY
101
+ end
88
102
  end
89
103
 
90
- self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
104
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
91
105
  def z_#{op}
92
- unless self.empty?
93
- if self.has_z?
94
- self.exterior_ring.z_#{op}
106
+ unless empty?
107
+ if has_z?
108
+ exterior_ring.z_#{op}
95
109
  else
96
110
  0
97
111
  end
98
112
  end
99
113
  end
100
- EOF
114
+ RUBY
101
115
  end
102
116
 
103
117
  %w{
@@ -110,21 +124,21 @@ module Geos
110
124
  trans_scale
111
125
  translate
112
126
  }.each do |m|
113
- self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
127
+ class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
114
128
  def #{m}!(*args)
115
- self.exterior_ring.coord_seq.#{m}!(*args)
116
- self.interior_rings.each do |ring|
129
+ exterior_ring.coord_seq.#{m}!(*args)
130
+ interior_rings.each do |ring|
117
131
  ring.coord_seq.#{m}!(*args)
118
132
  end
119
133
  self
120
134
  end
121
135
 
122
136
  def #{m}(*args)
123
- ret = self.dup.#{m}!(*args)
124
- ret.srid = pick_srid_according_to_policy(self.srid)
137
+ ret = dup.#{m}!(*args)
138
+ ret.srid = pick_srid_according_to_policy(srid)
125
139
  ret
126
140
  end
127
- EOF
141
+ RUBY
128
142
  end
129
143
  end
130
144
  end
@@ -37,9 +37,7 @@ module Geos
37
37
  end
38
38
  end
39
39
 
40
- if capacity <= 0
41
- raise ArgumentError, 'STRtree capacity must be greater than 0'
42
- end
40
+ raise ArgumentError, 'STRtree capacity must be greater than 0' if capacity <= 0
43
41
 
44
42
  ptr = FFIGeos.GEOSSTRtree_create_r(Geos.current_handle_pointer, capacity)
45
43
 
@@ -99,7 +97,7 @@ module Geos
99
97
  def remove(geom, item)
100
98
  check_geometry(geom)
101
99
 
102
- key = if storage = @storage.detect { |k, v| v[:item] == item }
100
+ key = if storage = @storage.detect { |_k, v| v[:item] == item }
103
101
  storage[0]
104
102
  end
105
103
 
@@ -180,7 +178,7 @@ module Geos
180
178
 
181
179
  return nil if @storage.empty?
182
180
 
183
- callback = proc { |item, _item2, distance_ptr|
181
+ callback = proc { |item, _item_2, distance_ptr|
184
182
  key = item.read_int
185
183
  geom_from_storage = @storage[key][:geometry]
186
184
 
@@ -47,7 +47,7 @@ module Geos
47
47
  when GEOS_GEOMETRYCOLLECTION
48
48
  GeometryCollection
49
49
  else
50
- raise Geos::InvalidGeometryTypeError.new
50
+ raise Geos::InvalidGeometryTypeError
51
51
  end
52
52
 
53
53
  klass.new(geom_ptr, options).tap do |ret|
@@ -43,9 +43,7 @@ module Geos
43
43
  raise ArgumentError, "Wrong number of arguments (#{args.length} for 1-3)"
44
44
  end
45
45
 
46
- if cs.length != 1
47
- raise ArgumentError, 'IllegalArgumentException: Point coordinate list must contain a single element'
48
- end
46
+ raise ArgumentError, 'IllegalArgumentException: Point coordinate list must contain a single element' if cs.length != 1
49
47
 
50
48
  cs_dup = cs.dup
51
49
  cs_dup.ptr.autorelease = false
@@ -56,9 +54,7 @@ module Geos
56
54
  def create_line_string(cs, options = {})
57
55
  cs = cs_from_cs_or_geom(cs)
58
56
 
59
- if cs.length <= 1 && cs.length != 0
60
- raise ArgumentError, 'IllegalArgumentException: point array must contain 0 or >1 elements'
61
- end
57
+ raise ArgumentError, 'IllegalArgumentException: point array must contain 0 or >1 elements' if cs.length <= 1 && !cs.empty?
62
58
 
63
59
  cs_dup = cs.dup
64
60
  cs_dup.ptr.autorelease = false
@@ -69,9 +65,7 @@ module Geos
69
65
  def create_linear_ring(cs, options = {})
70
66
  cs = cs_from_cs_or_geom(cs)
71
67
 
72
- if cs.length <= 1 && cs.length != 0
73
- raise ArgumentError, 'IllegalArgumentException: point array must contain 0 or >1 elements'
74
- end
68
+ raise ArgumentError, 'IllegalArgumentException: point array must contain 0 or >1 elements' if cs.length <= 1 && !cs.empty?
75
69
 
76
70
  cs.ptr.autorelease = false
77
71
 
@@ -154,9 +148,7 @@ module Geos
154
148
  options = extract_options!(args)
155
149
 
156
150
  geoms = Array(args).flatten.tap do |i|
157
- if i.detect { |g| !g.is_a?(klass) }
158
- raise TypeError, "Expected geoms Array to contain #{klass} objects"
159
- end
151
+ raise TypeError, "Expected geoms Array to contain #{klass} objects" if i.detect { |g| !g.is_a?(klass) }
160
152
  end
161
153
 
162
154
  geoms_dups = geoms.map(&:dup)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Geos
4
- VERSION = '2.0.0'.freeze
4
+ VERSION = '2.1.0'
5
5
  end
@@ -57,9 +57,8 @@ module Geos
57
57
  end
58
58
 
59
59
  def output_dimensions=(dim)
60
- if dim < 2 || dim > 3
61
- raise ArgumentError, 'Output dimensions must be either 2 or 3'
62
- end
60
+ raise ArgumentError, 'Output dimensions must be either 2 or 3' if dim < 2 || dim > 3
61
+
63
62
  FFIGeos.GEOSWKBWriter_setOutputDimension_r(Geos.current_handle_pointer, ptr, dim)
64
63
  end
65
64
 
@@ -29,7 +29,7 @@ module Geos
29
29
  end
30
30
 
31
31
  def set_options(options) #:nodoc:
32
- [ :trim, :old_3d, :rounding_precision, :output_dimensions ].each do |k|
32
+ [:trim, :old_3d, :rounding_precision, :output_dimensions].each do |k|
33
33
  send("#{k}=", options[k]) if respond_to?("#{k}=") && options.key?(k)
34
34
  end
35
35
  end
@@ -67,9 +67,7 @@ module Geos
67
67
  # Available in GEOS 3.3+.
68
68
  def rounding_precision=(r)
69
69
  r = r.to_i
70
- if r > 255
71
- raise ArgumentError, 'Rounding precision cannot be greater than 255'
72
- end
70
+ raise ArgumentError, 'Rounding precision cannot be greater than 255' if r > 255
73
71
 
74
72
  @rounding_precision = r
75
73
  FFIGeos.GEOSWKTWriter_setRoundingPrecision_r(Geos.current_handle_pointer, ptr, @rounding_precision)
@@ -88,9 +86,8 @@ module Geos
88
86
  # Available in GEOS 3.3+.
89
87
  def output_dimensions=(dim)
90
88
  dim = dim.to_i
91
- if dim < 2 || dim > 3
92
- raise ArgumentError, 'Output dimensions must be either 2 or 3'
93
- end
89
+ raise ArgumentError, 'Output dimensions must be either 2 or 3' if dim < 2 || dim > 3
90
+
94
91
  FFIGeos.GEOSWKTWriter_setOutputDimension_r(Geos.current_handle_pointer, ptr, dim)
95
92
  end
96
93
  end
@@ -0,0 +1,16 @@
1
+ sonar.projectKey=dark-panda_ffi-geos
2
+ sonar.organization=dark-panda
3
+
4
+ # This is the name and version displayed in the SonarCloud UI.
5
+ #sonar.projectName=ffi-geos
6
+ #sonar.projectVersion=1.0
7
+
8
+ # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
9
+ sonar.sources=lib, test
10
+
11
+ # Encoding of the source code. Default is default system encoding
12
+ #sonar.sourceEncoding=UTF-8
13
+
14
+ # Additional reports
15
+ sonar.ruby.rubocop.reportPaths=rubocop-report.json
16
+ sonar.ruby.coverage.reportPaths=coverage/.resultset.json
@@ -43,6 +43,28 @@ class CoordinateSequenceTests < Minitest::Test
43
43
  assert_equal(2, @cs.dimensions)
44
44
  end
45
45
 
46
+ def test_counter_clockwise
47
+ skip unless ENV['FORCE_TESTS'] || Geos::CoordinateSequence.method_defined?(:counter_clockwise?)
48
+
49
+ cs = Geos::CoordinateSequence.new([
50
+ [0, 0],
51
+ [1, 0],
52
+ [1, 1],
53
+ [0, 0]
54
+ ])
55
+
56
+ assert(cs.counter_clockwise?)
57
+
58
+ cs = Geos::CoordinateSequence.new([
59
+ [0, 0],
60
+ [1, 1],
61
+ [1, 0],
62
+ [0, 0]
63
+ ])
64
+
65
+ refute(cs.counter_clockwise?)
66
+ end
67
+
46
68
  def test_check_bounds
47
69
  assert_raises(Geos::IndexBoundsError) { @cs.set_x(10, 0.1) }
48
70
  assert_raises(Geos::IndexBoundsError) { @cs.set_x(-1, 0.1) }
@@ -105,11 +127,11 @@ class CoordinateSequenceTests < Minitest::Test
105
127
 
106
128
  def test_read_from_array
107
129
  cs = Geos::CoordinateSequence.new([
108
- [ 0, 0 ],
109
- [ 1, 1 ],
110
- [ 2, 2 ],
111
- [ 3, 3 ],
112
- [ 4, 4 ]
130
+ [0, 0],
131
+ [1, 1],
132
+ [2, 2],
133
+ [3, 3],
134
+ [4, 4]
113
135
  ])
114
136
 
115
137
  assert_equal(2, cs.dimensions)
@@ -117,30 +139,30 @@ class CoordinateSequenceTests < Minitest::Test
117
139
 
118
140
  assert_raises(Geos::CoordinateSequence::ParseError) do
119
141
  cs = Geos::CoordinateSequence.new([
120
- [ 1, 2 ],
121
- [ 1, 2, 3 ]
142
+ [1, 2],
143
+ [1, 2, 3]
122
144
  ])
123
145
  end
124
146
 
125
147
  assert_raises(Geos::CoordinateSequence::ParseError) do
126
148
  cs = Geos::CoordinateSequence.new([
127
- [ 1, 2, 3, 4 ]
149
+ [1, 2, 3, 4]
128
150
  ])
129
151
  end
130
152
  end
131
153
 
132
154
  def test_to_point
133
- cs = Geos::CoordinateSequence.new([ 5, 7 ])
155
+ cs = Geos::CoordinateSequence.new([5, 7])
134
156
  assert_equal('POINT (5 7)', write(cs.to_point, trim: true))
135
157
  end
136
158
 
137
159
  def test_to_to_linear_ring
138
160
  cs = Geos::CoordinateSequence.new([
139
- [ 0, 0 ],
140
- [ 0, 5 ],
141
- [ 5, 5 ],
142
- [ 5, 0 ],
143
- [ 0, 0 ]
161
+ [0, 0],
162
+ [0, 5],
163
+ [5, 5],
164
+ [5, 0],
165
+ [0, 0]
144
166
  ])
145
167
 
146
168
  assert_equal('LINEARRING (0 0, 0 5, 5 5, 5 0, 0 0)', write(cs.to_linear_ring, trim: true))
@@ -150,7 +172,7 @@ class CoordinateSequenceTests < Minitest::Test
150
172
  cs = Geos::CoordinateSequence.new
151
173
  assert_geom_empty(cs)
152
174
 
153
- cs = Geos::CoordinateSequence.new([ 4, 1 ])
175
+ cs = Geos::CoordinateSequence.new([4, 1])
154
176
  refute_geom_empty(cs)
155
177
  end
156
178
 
@@ -162,10 +184,10 @@ class CoordinateSequenceTests < Minitest::Test
162
184
 
163
185
  def test_to_line_string
164
186
  cs = Geos::CoordinateSequence.new([
165
- [ 0, 0 ],
166
- [ 0, 5 ],
167
- [ 5, 5 ],
168
- [ 5, 0 ]
187
+ [0, 0],
188
+ [0, 5],
189
+ [5, 5],
190
+ [5, 0]
169
191
  ])
170
192
 
171
193
  assert_equal('LINESTRING (0 0, 0 5, 5 5, 5 0)', write(cs.to_line_string, trim: true))
@@ -179,11 +201,11 @@ class CoordinateSequenceTests < Minitest::Test
179
201
 
180
202
  def test_to_polygon
181
203
  cs = Geos::CoordinateSequence.new([
182
- [ 0, 0 ],
183
- [ 0, 5 ],
184
- [ 5, 5 ],
185
- [ 5, 0 ],
186
- [ 0, 0 ]
204
+ [0, 0],
205
+ [0, 5],
206
+ [5, 5],
207
+ [5, 0],
208
+ [0, 0]
187
209
  ])
188
210
 
189
211
  assert_equal('POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))', write(cs.to_polygon, trim: true))
@@ -282,8 +304,8 @@ class CoordinateSequenceTests < Minitest::Test
282
304
 
283
305
  def test_array_like_access
284
306
  cs = Geos::CoordinateSequence.new([
285
- [ 0, 1 ],
286
- [ 2, 3 ]
307
+ [0, 1],
308
+ [2, 3]
287
309
  ])
288
310
 
289
311
  assert_equal(0, cs[0][0])
@@ -292,7 +314,7 @@ class CoordinateSequenceTests < Minitest::Test
292
314
  assert_equal(3, cs[1][1])
293
315
 
294
316
  cs = Geos::CoordinateSequence.new([
295
- [ 4, 5, 6 ]
317
+ [4, 5, 6]
296
318
  ])
297
319
 
298
320
  assert_equal(4, cs[0][0])
@@ -302,9 +324,9 @@ class CoordinateSequenceTests < Minitest::Test
302
324
 
303
325
  def test_slice
304
326
  cs = Geos::CoordinateSequence.new([
305
- [ 0, 1 ],
306
- [ 2, 3 ],
307
- [ 4, 5 ]
327
+ [0, 1],
328
+ [2, 3],
329
+ [4, 5]
308
330
  ])
309
331
 
310
332
  assert_equal([[0, 1], [2, 3]], cs.slice(0..1))
@@ -313,21 +335,21 @@ class CoordinateSequenceTests < Minitest::Test
313
335
  end
314
336
 
315
337
  def test_proxy_clone
316
- cs = Geos::CoordinateSequence.new([ 10, 20 ])
317
- cs2 = cs.clone
338
+ cs = Geos::CoordinateSequence.new([10, 20])
339
+ cs_2 = cs.clone
318
340
 
319
341
  cs.x[0] = 100
320
342
 
321
343
  assert_equal(100, cs.x[0])
322
- assert_equal(10, cs2.x[0])
344
+ assert_equal(10, cs_2.x[0])
323
345
 
324
- refute_equal(cs.x, cs2.x)
325
- refute_equal(cs.y, cs2.y)
346
+ refute_equal(cs.x, cs_2.x)
347
+ refute_equal(cs.y, cs_2.y)
326
348
  end
327
349
 
328
350
  def test_has_z
329
- assert_geom_has_z(Geos::CoordinateSequence.new([ 0, 1, 2 ]))
330
- refute_geom_has_z(Geos::CoordinateSequence.new([ 0, 1 ]))
351
+ assert_geom_has_z(Geos::CoordinateSequence.new([0, 1, 2]))
352
+ refute_geom_has_z(Geos::CoordinateSequence.new([0, 1]))
331
353
  refute_geom_has_z(Geos::CoordinateSequence.new(1, 2))
332
354
  assert_geom_has_z(Geos::CoordinateSequence.new(1, 3))
333
355
  assert_geom_has_z(read('POINT (0 0 0)').coord_seq)
@@ -335,38 +357,38 @@ class CoordinateSequenceTests < Minitest::Test
335
357
  end
336
358
 
337
359
  def test_x_max
338
- cs = Geos::CoordinateSequence.new([ -10, -15 ], [ 0, 5 ], [ 10, 20 ])
360
+ cs = Geos::CoordinateSequence.new([-10, -15], [0, 5], [10, 20])
339
361
  assert_equal(10, cs.x_max)
340
362
  end
341
363
 
342
364
  def test_x_min
343
- cs = Geos::CoordinateSequence.new([ -10, -15 ], [ 0, 5 ], [ 10, 20 ])
365
+ cs = Geos::CoordinateSequence.new([-10, -15], [0, 5], [10, 20])
344
366
  assert_equal(-10, cs.x_min)
345
367
  end
346
368
 
347
369
  def test_y_max
348
- cs = Geos::CoordinateSequence.new([ -10, -15 ], [ 0, 5 ], [ 10, 20 ])
370
+ cs = Geos::CoordinateSequence.new([-10, -15], [0, 5], [10, 20])
349
371
  assert_equal(20, cs.y_max)
350
372
  end
351
373
 
352
374
  def test_y_min
353
- cs = Geos::CoordinateSequence.new([ -10, -15 ], [ 0, 5 ], [ 10, 20 ])
375
+ cs = Geos::CoordinateSequence.new([-10, -15], [0, 5], [10, 20])
354
376
  assert_equal(-15, cs.y_min)
355
377
  end
356
378
 
357
379
  def test_z_max
358
- cs = Geos::CoordinateSequence.new([ -10, -15 ], [ 0, 5 ], [ 10, 20 ])
359
- assert(cs.z_max.nan?, " Expected NaN")
380
+ cs = Geos::CoordinateSequence.new([-10, -15], [0, 5], [10, 20])
381
+ assert(cs.z_max.nan?, ' Expected NaN')
360
382
 
361
- cs = Geos::CoordinateSequence.new([ -10, -15, -20 ], [ 0, 5, 10 ], [ 10, 20, 30 ])
383
+ cs = Geos::CoordinateSequence.new([-10, -15, -20], [0, 5, 10], [10, 20, 30])
362
384
  assert_equal(30, cs.z_max)
363
385
  end
364
386
 
365
387
  def test_z_min
366
- cs = Geos::CoordinateSequence.new([ -10, -15 ], [ 0, 5 ], [ 10, 20 ])
367
- assert(cs.z_min.nan?, " Expected NaN")
388
+ cs = Geos::CoordinateSequence.new([-10, -15], [0, 5], [10, 20])
389
+ assert(cs.z_min.nan?, ' Expected NaN')
368
390
 
369
- cs = Geos::CoordinateSequence.new([ -10, -15, -20 ], [ 0, 5, 10 ], [ 10, 20, 30 ])
391
+ cs = Geos::CoordinateSequence.new([-10, -15, -20], [0, 5, 10], [10, 20, 30])
370
392
  assert_equal(-20, cs.z_min)
371
393
  end
372
394
 
@@ -384,9 +406,9 @@ class CoordinateSequenceTests < Minitest::Test
384
406
  ]
385
407
 
386
408
  coordinates = [
387
- [ -10.123456789, -15.123456789 ],
388
- [ 0.123456789, 5.123456789 ],
389
- [ 10.123456789, 20.123456789 ]
409
+ [-10.123456789, -15.123456789],
410
+ [0.123456789, 5.123456789],
411
+ [10.123456789, 20.123456789]
390
412
  ]
391
413
 
392
414
  9.times do |i|
@@ -407,54 +429,54 @@ class CoordinateSequenceTests < Minitest::Test
407
429
 
408
430
  def test_snap_to_grid_with_hash
409
431
  cs = Geos::CoordinateSequence.new(
410
- [ 10, 10 ],
411
- [ 20, 20 ],
412
- [ 30, 30 ]
432
+ [10, 10],
433
+ [20, 20],
434
+ [30, 30]
413
435
  )
414
- cs.snap_to_grid!(:size_x => 1, :size_y => 1, :offset_x => 12.5, :offset_y => 12.5)
436
+ cs.snap_to_grid!(size_x: 1, size_y: 1, offset_x: 12.5, offset_y: 12.5)
415
437
 
416
438
  assert_equal([
417
- [ 9.5, 9.5 ],
418
- [ 20.5, 20.5 ],
419
- [ 30.5, 30.5 ]
439
+ [9.5, 9.5],
440
+ [20.5, 20.5],
441
+ [30.5, 30.5]
420
442
  ], cs.to_a)
421
443
  end
422
444
 
423
445
  def test_snap_to_grid_with_geometry_origin
424
446
  cs = Geos::CoordinateSequence.new(
425
- [ 10, 10 ],
426
- [ 20, 20 ],
427
- [ 30, 30 ]
447
+ [10, 10],
448
+ [20, 20],
449
+ [30, 30]
428
450
  )
429
- cs.snap_to_grid!(:size => 1, :offset => read('LINESTRING (0 0, 25 25)'))
451
+ cs.snap_to_grid!(size: 1, offset: read('LINESTRING (0 0, 25 25)'))
430
452
 
431
453
  assert_equal([
432
- [ 9.5, 9.5 ],
433
- [ 20.5, 20.5 ],
434
- [ 30.5, 30.5 ]
454
+ [9.5, 9.5],
455
+ [20.5, 20.5],
456
+ [30.5, 30.5]
435
457
  ], cs.to_a)
436
458
  end
437
459
 
438
460
  def test_snap_to_grid_with_z
439
461
  cs = Geos::CoordinateSequence.new(
440
- [ 10, 10, 10 ],
441
- [ 20, 20, 20 ],
442
- [ 30, 30, 30 ]
462
+ [10, 10, 10],
463
+ [20, 20, 20],
464
+ [30, 30, 30]
443
465
  )
444
466
  cs.snap_to_grid!(
445
- :size_x => 1,
446
- :size_y => 1,
447
- :size_z => 1,
467
+ size_x: 1,
468
+ size_y: 1,
469
+ size_z: 1,
448
470
 
449
- :offset_x => 12.5,
450
- :offset_y => 12.5,
451
- :offset_z => 12.5
471
+ offset_x: 12.5,
472
+ offset_y: 12.5,
473
+ offset_z: 12.5
452
474
  )
453
475
 
454
476
  assert_equal([
455
- [ 9.5, 9.5, 9.5 ],
456
- [ 20.5, 20.5, 20.5 ],
457
- [ 30.5, 30.5, 30.5 ]
477
+ [9.5, 9.5, 9.5],
478
+ [20.5, 20.5, 20.5],
479
+ [30.5, 30.5, 30.5]
458
480
  ], cs.to_a)
459
481
  end
460
482
 
@@ -486,10 +508,10 @@ class CoordinateSequenceTests < Minitest::Test
486
508
  assert_equal(expected, cs.to_a)
487
509
 
488
510
  cs = Geos::CoordinateSequence.new(coords)
489
- cs2 = cs.snap_to_grid
511
+ cs_2 = cs.snap_to_grid
490
512
 
491
513
  assert_equal(coords, cs.to_a)
492
- assert_equal(expected, cs2.to_a)
514
+ assert_equal(expected, cs_2.to_a)
493
515
  end
494
516
 
495
517
  undef :affine_tester
@@ -502,83 +524,83 @@ class CoordinateSequenceTests < Minitest::Test
502
524
  end
503
525
 
504
526
  cs = Geos::CoordinateSequence.new(coords)
505
- cs2 = cs.send(method, *args)
527
+ cs_2 = cs.send(method, *args)
506
528
 
507
529
  expected.length.times do |i|
508
530
  assert_in_delta(coords[i], cs.get_ordinate(0, i), TOLERANCE)
509
- assert_in_delta(expected[i], cs2.get_ordinate(0, i), TOLERANCE)
531
+ assert_in_delta(expected[i], cs_2.get_ordinate(0, i), TOLERANCE)
510
532
  end
511
533
  end
512
534
 
513
535
  def test_rotate
514
- affine_tester(:rotate, [ 29.0, 11.0 ], [ 1, 1 ], Math::PI / 2, [ 10.0, 20.0 ])
515
- affine_tester(:rotate, [ -2.0, 0.0 ], [ 1, 1 ], -Math::PI / 2, [ -1.0, 2.0 ])
516
- affine_tester(:rotate, [ 19.0, 1.0 ], [ 1, 1 ], Math::PI / 2, read('POINT(10 10)'))
517
- affine_tester(:rotate, [ -0.5, 0.5 ], [ 1, 1 ], Math::PI / 2, read('LINESTRING(0 0, 1 0)'))
536
+ affine_tester(:rotate, [29.0, 11.0], [1, 1], Math::PI / 2, [10.0, 20.0])
537
+ affine_tester(:rotate, [-2.0, 0.0], [1, 1], -Math::PI / 2, [-1.0, 2.0])
538
+ affine_tester(:rotate, [19.0, 1.0], [1, 1], Math::PI / 2, read('POINT(10 10)'))
539
+ affine_tester(:rotate, [-0.5, 0.5], [1, 1], Math::PI / 2, read('LINESTRING(0 0, 1 0)'))
518
540
  end
519
541
 
520
542
  def test_rotate_x
521
- affine_tester(:rotate_x, [ 1, -1, -1 ], [ 1, 1, 1 ], Math::PI)
522
- affine_tester(:rotate_x, [ 1, -1, 1 ], [ 1, 1, 1 ], Math::PI / 2)
523
- affine_tester(:rotate_x, [ 1, 1, -1 ], [ 1, 1, 1 ], Math::PI + Math::PI / 2)
524
- affine_tester(:rotate_x, [ 1, 1, 1 ], [ 1, 1, 1 ], Math::PI * 2)
543
+ affine_tester(:rotate_x, [1, -1, -1], [1, 1, 1], Math::PI)
544
+ affine_tester(:rotate_x, [1, -1, 1], [1, 1, 1], Math::PI / 2)
545
+ affine_tester(:rotate_x, [1, 1, -1], [1, 1, 1], Math::PI + Math::PI / 2)
546
+ affine_tester(:rotate_x, [1, 1, 1], [1, 1, 1], Math::PI * 2)
525
547
  end
526
548
 
527
549
  def test_rotate_y
528
- affine_tester(:rotate_y, [ -1, 1, -1 ], [ 1, 1, 1 ], Math::PI)
529
- affine_tester(:rotate_y, [ 1, 1, -1 ], [ 1, 1, 1 ], Math::PI / 2)
530
- affine_tester(:rotate_y, [ -1, 1, 1 ], [ 1, 1, 1 ], Math::PI + Math::PI / 2)
531
- affine_tester(:rotate_y, [ 1, 1, 1 ], [ 1, 1, 1 ], Math::PI * 2)
550
+ affine_tester(:rotate_y, [-1, 1, -1], [1, 1, 1], Math::PI)
551
+ affine_tester(:rotate_y, [1, 1, -1], [1, 1, 1], Math::PI / 2)
552
+ affine_tester(:rotate_y, [-1, 1, 1], [1, 1, 1], Math::PI + Math::PI / 2)
553
+ affine_tester(:rotate_y, [1, 1, 1], [1, 1, 1], Math::PI * 2)
532
554
  end
533
555
 
534
556
  def test_rotate_z
535
- affine_tester(:rotate_z, [ -1, -1 ], [ 1, 1 ], Math::PI)
536
- affine_tester(:rotate_z, [ -1, 1 ], [ 1, 1 ], Math::PI / 2)
537
- affine_tester(:rotate_z, [ 1, -1 ], [ 1, 1 ], Math::PI + Math::PI / 2)
538
- affine_tester(:rotate_z, [ 1, 1 ], [ 1, 1 ], Math::PI * 2)
557
+ affine_tester(:rotate_z, [-1, -1], [1, 1], Math::PI)
558
+ affine_tester(:rotate_z, [-1, 1], [1, 1], Math::PI / 2)
559
+ affine_tester(:rotate_z, [1, -1], [1, 1], Math::PI + Math::PI / 2)
560
+ affine_tester(:rotate_z, [1, 1], [1, 1], Math::PI * 2)
539
561
  end
540
562
 
541
563
  def test_scale
542
- affine_tester(:scale, [ 5, 5 ], [ 1, 1 ], 5, 5)
543
- affine_tester(:scale, [ 3, 2 ], [ 1, 1 ], 3, 2)
544
- affine_tester(:scale, [ 40, 40, 40 ], [ 10, 20, -5 ], 4, 2, -8)
564
+ affine_tester(:scale, [5, 5], [1, 1], 5, 5)
565
+ affine_tester(:scale, [3, 2], [1, 1], 3, 2)
566
+ affine_tester(:scale, [40, 40, 40], [10, 20, -5], 4, 2, -8)
545
567
  end
546
568
 
547
569
  def test_scale_hash
548
- affine_tester(:scale, [ 5, 5 ], [ 1, 1 ], :x => 5, :y => 5)
549
- affine_tester(:scale, [ 3, 2 ], [ 1, 1 ], :x => 3, :y => 2)
550
- affine_tester(:scale, [ 40, 40, 40 ], [ 10, 20, -5 ], :x => 4, :y => 2, :z => -8)
570
+ affine_tester(:scale, [5, 5], [1, 1], x: 5, y: 5)
571
+ affine_tester(:scale, [3, 2], [1, 1], x: 3, y: 2)
572
+ affine_tester(:scale, [40, 40, 40], [10, 20, -5], x: 4, y: 2, z: -8)
551
573
  end
552
574
 
553
575
  def test_trans_scale
554
- affine_tester(:trans_scale, [ 2, 2 ], [ 1, 1 ], 1, 1, 1, 1)
555
- affine_tester(:trans_scale, [ 3, 3 ], [ 2, 2 ], 1, 1, 1, 1)
556
- affine_tester(:trans_scale, [ 0, 0 ], [ 1, 1 ], -1, -1, -1, -1)
557
- affine_tester(:trans_scale, [ 1, 2 ], [ 1, 1 ], 0, 1, 1, 1)
558
- affine_tester(:trans_scale, [ 2, 1 ], [ 1, 1 ], 1, 0, 1, 1)
559
- affine_tester(:trans_scale, [ 0, 2 ], [ 1, 1 ], 1, 1, 0, 1)
560
- affine_tester(:trans_scale, [ 2, 0 ], [ 1, 1 ], 1, 1, 1, 0)
561
- affine_tester(:trans_scale, [ 3, 2 ], [ 1, 1 ], 2, 1, 1, 1)
562
- affine_tester(:trans_scale, [ 2, 3 ], [ 1, 1 ], 1, 2, 1, 1)
563
- affine_tester(:trans_scale, [ 4, 2 ], [ 1, 1 ], 1, 1, 2, 1)
564
- affine_tester(:trans_scale, [ 2, 4 ], [ 1, 1 ], 1, 1, 1, 2)
565
- affine_tester(:trans_scale, [ 15, 28 ], [ 1, 1 ], 2, 3, 5, 7)
566
- affine_tester(:trans_scale, [ 15, 28, 1 ], [ 1, 1, 1 ], 2, 3, 5, 7)
576
+ affine_tester(:trans_scale, [2, 2], [1, 1], 1, 1, 1, 1)
577
+ affine_tester(:trans_scale, [3, 3], [2, 2], 1, 1, 1, 1)
578
+ affine_tester(:trans_scale, [0, 0], [1, 1], -1, -1, -1, -1)
579
+ affine_tester(:trans_scale, [1, 2], [1, 1], 0, 1, 1, 1)
580
+ affine_tester(:trans_scale, [2, 1], [1, 1], 1, 0, 1, 1)
581
+ affine_tester(:trans_scale, [0, 2], [1, 1], 1, 1, 0, 1)
582
+ affine_tester(:trans_scale, [2, 0], [1, 1], 1, 1, 1, 0)
583
+ affine_tester(:trans_scale, [3, 2], [1, 1], 2, 1, 1, 1)
584
+ affine_tester(:trans_scale, [2, 3], [1, 1], 1, 2, 1, 1)
585
+ affine_tester(:trans_scale, [4, 2], [1, 1], 1, 1, 2, 1)
586
+ affine_tester(:trans_scale, [2, 4], [1, 1], 1, 1, 1, 2)
587
+ affine_tester(:trans_scale, [15, 28], [1, 1], 2, 3, 5, 7)
588
+ affine_tester(:trans_scale, [15, 28, 1], [1, 1, 1], 2, 3, 5, 7)
567
589
  end
568
590
 
569
591
  def test_trans_scale_hash
570
- affine_tester(:trans_scale, [ 2, 2 ], [ 1, 1 ], :delta_x => 1, :delta_y => 1, :x_factor => 1, :y_factor => 1)
571
- affine_tester(:trans_scale, [ 15, 28, 1 ], [ 1, 1, 1 ], :delta_x => 2, :delta_y => 3, :x_factor => 5, :y_factor => 7)
572
- affine_tester(:trans_scale, [ 3, 1, 1 ], [ 1, 1, 1 ], :delta_x => 2, :z_factor => 2)
592
+ affine_tester(:trans_scale, [2, 2], [1, 1], delta_x: 1, delta_y: 1, x_factor: 1, y_factor: 1)
593
+ affine_tester(:trans_scale, [15, 28, 1], [1, 1, 1], delta_x: 2, delta_y: 3, x_factor: 5, y_factor: 7)
594
+ affine_tester(:trans_scale, [3, 1, 1], [1, 1, 1], delta_x: 2, z_factor: 2)
573
595
  end
574
596
 
575
597
  def test_translate
576
- affine_tester(:translate, [ 5, 12 ], [ 0, 0 ], 5, 12)
577
- affine_tester(:translate, [ -3, -7, 3 ], [ 0, 0, 0 ], -3, -7, 3)
598
+ affine_tester(:translate, [5, 12], [0, 0], 5, 12)
599
+ affine_tester(:translate, [-3, -7, 3], [0, 0, 0], -3, -7, 3)
578
600
  end
579
601
 
580
602
  def test_translate_hash
581
- affine_tester(:translate, [ 5, 12 ], [ 0, 0 ], :x => 5, :y => 12)
582
- affine_tester(:translate, [ -3, -7, 3 ], [ 0, 0, 0 ], :x => -3, :y => -7, :z => 3)
603
+ affine_tester(:translate, [5, 12], [0, 0], x: 5, y: 12)
604
+ affine_tester(:translate, [-3, -7, 3], [0, 0, 0], x: -3, y: -7, z: 3)
583
605
  end
584
606
  end