geos-extensions 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -6,6 +6,14 @@ require 'rubygems/package_task'
6
6
  require 'rake/testtask'
7
7
  require 'rdoc/task'
8
8
 
9
+ if RUBY_VERSION >= '1.9'
10
+ begin
11
+ gem 'psych'
12
+ rescue Exception => e
13
+ # it's okay, fall back on the bundled psych
14
+ end
15
+ end
16
+
9
17
  $:.push 'lib'
10
18
 
11
19
  version = File.read('VERSION') rescue ''
@@ -27,7 +35,7 @@ end
27
35
 
28
36
  desc 'Test GEOS interface'
29
37
  Rake::TestTask.new(:test) do |t|
30
- t.pattern = 'test/**/*_test.rb'
38
+ t.test_files = FileList['test/**/*_tests.rb']
31
39
  t.verbose = false
32
40
  end
33
41
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{geos-extensions}
8
- s.version = "0.1.3"
7
+ s.name = "geos-extensions"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{J Smith}]
12
- s.date = %q{2011-07-12}
13
- s.description = %q{Extensions for the GEOS library.}
14
- s.email = %q{code@zoocasa.com}
11
+ s.authors = ["J Smith"]
12
+ s.date = "2011-11-09"
13
+ s.description = "Extensions for the GEOS library."
14
+ s.email = "code@zoocasa.com"
15
15
  s.extra_rdoc_files = [
16
16
  "README.rdoc"
17
17
  ]
@@ -36,20 +36,22 @@ Gem::Specification.new do |s|
36
36
  "lib/geos/rails/engine.rb",
37
37
  "lib/geos_extensions.rb",
38
38
  "lib/tasks/test.rake",
39
- "test/adapter_test.rb",
39
+ "test/adapter_tests.rb",
40
40
  "test/fixtures/foos.yml",
41
- "test/geometry_columns_test.rb",
42
- "test/geospatial_scopes_test.rb",
43
- "test/google_maps_api_2_test.rb",
44
- "test/google_maps_api_3_test.rb",
45
- "test/reader_test.rb",
41
+ "test/geometry_columns_tests.rb",
42
+ "test/geospatial_scopes_tests.rb",
43
+ "test/google_maps_api_2_tests.rb",
44
+ "test/google_maps_api_3_tests.rb",
45
+ "test/google_maps_polyline_encoder_tests.rb",
46
+ "test/misc_tests.rb",
47
+ "test/reader_tests.rb",
46
48
  "test/test_helper.rb",
47
- "test/writer_test.rb"
49
+ "test/writer_tests.rb"
48
50
  ]
49
- s.homepage = %q{http://github.com/zoocasa/geos-extensions}
50
- s.require_paths = [%q{lib}]
51
- s.rubygems_version = %q{1.8.5}
52
- s.summary = %q{Extensions for the GEOS library.}
51
+ s.homepage = "http://github.com/zoocasa/geos-extensions"
52
+ s.require_paths = ["lib"]
53
+ s.rubygems_version = "1.8.11"
54
+ s.summary = "Extensions for the GEOS library."
53
55
 
54
56
  if s.respond_to? :specification_version then
55
57
  s.specification_version = 3
@@ -22,6 +22,7 @@ module Geos
22
22
  # * st_touches
23
23
  # * st_within
24
24
  # * st_dwithin
25
+ # * st_dfullywithin
25
26
  #
26
27
  # The first argument to each of these methods can be a Geos::Geometry-based
27
28
  # object or anything readable by Geos.read along with an optional
@@ -81,6 +82,9 @@ module Geos
81
82
  # * :nulls - the order_by scopes also allow you to specify whether you
82
83
  # want NULL values to be sorted first or last.
83
84
  #
85
+ # Because it's quite common to only want to flip the ordering to DESC,
86
+ # you can also just pass :desc on its own rather than as an options Hash.
87
+ #
84
88
  # == SRID Detection
85
89
  #
86
90
  # * if the geometry itself has an SRID, we'll compare it to the
@@ -117,6 +121,7 @@ module Geos
117
121
  }.freeze
118
122
 
119
123
  ZERO_ARGUMENT_MEASUREMENTS = %w{
124
+ area
120
125
  ndims
121
126
  npoints
122
127
  nrings
@@ -138,6 +143,11 @@ module Geos
138
143
  maxdistance
139
144
  }
140
145
 
146
+ ONE_GEOMETRY_ARGUMENT_AND_ONE_ARGUMENT_RELATIONSHIPS = %w{
147
+ dwithin
148
+ dfullywithin
149
+ }
150
+
141
151
  ONE_ARGUMENT_MEASUREMENTS = %w{
142
152
  length2d_spheroid
143
153
  length3d_spheroid
@@ -177,10 +187,19 @@ module Geos
177
187
  end
178
188
  end
179
189
 
180
- def default_options(options)
190
+ def default_options(*args)
191
+ options = args.extract_options!
192
+
193
+ desc = if args.first == :desc
194
+ true
195
+ else
196
+ options[:desc]
197
+ end
198
+
181
199
  {
182
200
  :column => 'the_geom',
183
- :use_index => true
201
+ :use_index => true,
202
+ :desc => desc
184
203
  }.merge(options || {})
185
204
  end
186
205
 
@@ -221,11 +240,17 @@ module Geos
221
240
  end
222
241
  end
223
242
 
224
- def additional_ordering(options = nil)
225
- options ||= {}
243
+ def additional_ordering(*args)
244
+ options = args.extract_options!
245
+
246
+ desc = if args.first == :desc
247
+ true
248
+ else
249
+ options[:desc]
250
+ end
226
251
 
227
252
  ''.tap do |ret|
228
- if options[:desc]
253
+ if desc
229
254
  ret << ' DESC'
230
255
  end
231
256
 
@@ -258,19 +283,24 @@ module Geos
258
283
  base.class_eval(src, __FILE__, line)
259
284
  end
260
285
 
261
- base.class_eval do
262
- send(SCOPE_METHOD, :st_dwithin, lambda { |*args|
263
- assert_arguments_length(args, 2, 3)
264
- geom, distance, options = args
286
+ ONE_GEOMETRY_ARGUMENT_AND_ONE_ARGUMENT_RELATIONSHIPS.each do |relationship|
287
+ src, line = <<-EOF, __LINE__ + 1
288
+ #{SCOPE_METHOD} :st_#{relationship}, lambda { |*args|
289
+ assert_arguments_length(args, 2, 3)
290
+ geom, distance, options = args
265
291
 
266
- {
267
- :conditions => [
268
- build_function_call('dwithin', geom, options, :additional_args => 1),
269
- distance
270
- ]
292
+ {
293
+ :conditions => [
294
+ build_function_call('#{relationship}', geom, options, :additional_args => 1),
295
+ distance
296
+ ]
297
+ }
271
298
  }
272
- })
299
+ EOF
300
+ base.class_eval(src, __FILE__, line)
301
+ end
273
302
 
303
+ base.class_eval do
274
304
  send(SCOPE_METHOD, :st_geometry_type, lambda { |*args|
275
305
  assert_arguments_length(args, 1)
276
306
  options = args.extract_options!
@@ -12,6 +12,10 @@ module Geos
12
12
  # The level parameter is the zoom level you're encoding at. See the
13
13
  # Google Maps API reference for details on that.
14
14
  def encode(points, level = 3)
15
+ if points.is_a?(Geos::LineString)
16
+ points = points.coord_seq
17
+ end
18
+
15
19
  encoded_points = String.new
16
20
  encoded_levels = String.new
17
21
 
@@ -35,6 +39,25 @@ module Geos
35
39
  { :points => encoded_points, :levels => encoded_levels }
36
40
  end
37
41
 
42
+ def decode(encoded)
43
+ retval = []
44
+ index = 0
45
+ lat = 0
46
+ lng = 0
47
+
48
+ while (index < encoded.length)
49
+ shift = 0
50
+ result = 0
51
+
52
+ index, lat = decode_number(encoded, lat, index)
53
+ index, lng = decode_number(encoded, lng, index)
54
+
55
+ retval.push([ lng * 1e-5, lat * 1e-5])
56
+ end
57
+
58
+ retval
59
+ end
60
+
38
61
  protected
39
62
 
40
63
  # Encodes a signed number into the Google Maps encoded polyline format.
@@ -44,6 +67,25 @@ module Geos
44
67
  encode_number signed
45
68
  end
46
69
 
70
+ # Decodes a lat or lng value based on the index and the previous
71
+ # value.
72
+ def decode_number(encoded, last, index) #:nodoc:
73
+ shift = 0
74
+ result = 0
75
+
76
+ begin
77
+ b = encoded[index].ord - 63
78
+ index += 1
79
+ result = result | ((b & 0x1f) << shift)
80
+ shift += 5
81
+ end while (b >= 0x20)
82
+
83
+ [
84
+ index,
85
+ last + ((result & 1) != 0 ? ~(result >> 1) : (result >> 1))
86
+ ]
87
+ end
88
+
47
89
  # Encodes a number into the Google Maps encoded polyline format.
48
90
  def encode_number(n) #:nodoc:
49
91
  str = String.new
@@ -221,7 +221,7 @@ module Geos
221
221
 
222
222
  # Returns a Point for the envelope's upper left coordinate.
223
223
  def upper_left
224
- if @upper_left
224
+ if defined?(@upper_left)
225
225
  @upper_left
226
226
  else
227
227
  cs = self.envelope.exterior_ring.coord_seq
@@ -233,11 +233,11 @@ module Geos
233
233
 
234
234
  # Returns a Point for the envelope's upper right coordinate.
235
235
  def upper_right
236
- if @upper_right
236
+ if defined?(@upper_right)
237
237
  @upper_right
238
238
  else
239
239
  cs = self.envelope.exterior_ring.coord_seq
240
- @upper_right ||= Geos::wkt_reader_singleton.read("POINT(#{cs.get_x(2)} #{cs.get_y(2)})")
240
+ @upper_right = Geos::wkt_reader_singleton.read("POINT(#{cs.get_x(2)} #{cs.get_y(2)})")
241
241
  end
242
242
  end
243
243
  alias :ne :upper_right
@@ -245,11 +245,11 @@ module Geos
245
245
 
246
246
  # Returns a Point for the envelope's lower right coordinate.
247
247
  def lower_right
248
- if @lower_right
248
+ if defined?(@lower_right)
249
249
  @lower_right
250
250
  else
251
251
  cs = self.envelope.exterior_ring.coord_seq
252
- @lower_right ||= Geos::wkt_reader_singleton.read("POINT(#{cs.get_x(1)} #{cs.get_y(1)})")
252
+ @lower_right = Geos::wkt_reader_singleton.read("POINT(#{cs.get_x(1)} #{cs.get_y(1)})")
253
253
  end
254
254
  end
255
255
  alias :se :lower_right
@@ -257,11 +257,11 @@ module Geos
257
257
 
258
258
  # Returns a Point for the envelope's lower left coordinate.
259
259
  def lower_left
260
- if @lower_left
260
+ if defined?(@lower_left)
261
261
  @lower_left
262
262
  else
263
263
  cs = self.envelope.exterior_ring.coord_seq
264
- @lower_left ||= Geos::wkt_reader_singleton.read("POINT(#{cs.get_x(0)} #{cs.get_y(0)})")
264
+ @lower_left = Geos::wkt_reader_singleton.read("POINT(#{cs.get_x(0)} #{cs.get_y(0)})")
265
265
  end
266
266
  end
267
267
  alias :sw :lower_left
@@ -269,28 +269,44 @@ module Geos
269
269
 
270
270
  # Northern-most Y coordinate.
271
271
  def top
272
- @top ||= self.upper_right.to_a[1]
272
+ if defined?(@top)
273
+ @top
274
+ else
275
+ @top = self.upper_right.y
276
+ end
273
277
  end
274
278
  alias :n :top
275
279
  alias :north :top
276
280
 
277
281
  # Eastern-most X coordinate.
278
282
  def right
279
- @right ||= self.upper_right.to_a[0]
283
+ if defined?(@right)
284
+ @right
285
+ else
286
+ @right = self.upper_right.x
287
+ end
280
288
  end
281
289
  alias :e :right
282
290
  alias :east :right
283
291
 
284
292
  # Southern-most Y coordinate.
285
293
  def bottom
286
- @bottom ||= self.lower_left.to_a[1]
294
+ if defined?(@bottom)
295
+ @bottom
296
+ else
297
+ @bottom = self.lower_left.y
298
+ end
287
299
  end
288
300
  alias :s :bottom
289
301
  alias :south :bottom
290
302
 
291
303
  # Western-most X coordinate.
292
304
  def left
293
- @left ||= self.lower_left.to_a[0]
305
+ if defined?(@left)
306
+ @left
307
+ else
308
+ @left = self.lower_left.x
309
+ end
294
310
  end
295
311
  alias :w :left
296
312
  alias :west :left
@@ -393,21 +409,31 @@ module Geos
393
409
 
394
410
 
395
411
  class Point
396
- # Returns the Y coordinate of the Point, which is actually the
397
- # latitude.
398
- def lat
412
+ # Returns the Y coordinate of the Point.
413
+ def y
399
414
  self.to_a[1]
400
415
  end
401
- alias :latitude :lat
402
- alias :y :lat
403
416
 
404
- # Returns the X coordinate of the Point, which is actually the
405
- # longitude.
406
- def lng
417
+ %w{
418
+ latitude lat north south n s
419
+ }.each do |name|
420
+ self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
421
+ alias #{name} :y
422
+ EOF
423
+ end
424
+
425
+ # Returns the X coordinate of the Point.
426
+ def x
407
427
  self.to_a[0]
408
428
  end
409
- alias :longitude :lng
410
- alias :x :lng
429
+
430
+ %w{
431
+ longitude lng east west e w
432
+ }.each do |name|
433
+ self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
434
+ alias #{name} :x
435
+ EOF
436
+ end
411
437
 
412
438
  # Returns the Z coordinate of the Point.
413
439
  def z
@@ -425,27 +451,29 @@ module Geos
425
451
  # The Z coordinate will only be present for Points which have a Z
426
452
  # dimension.
427
453
  def to_a
428
- cs = self.coord_seq
429
- @to_a ||= if self.has_z?
430
- [ cs.get_x(0), cs.get_y(0), cs.get_z(0) ]
454
+ if defined?(@to_a)
455
+ @to_a
431
456
  else
432
- [ cs.get_x(0), cs.get_y(0) ]
457
+ cs = self.coord_seq
458
+ @to_a = if self.has_z?
459
+ [ cs.get_x(0), cs.get_y(0), cs.get_z(0) ]
460
+ else
461
+ [ cs.get_x(0), cs.get_y(0) ]
462
+ end
433
463
  end
434
464
  end
435
465
 
436
466
  # Optimize some unnecessary code away:
437
467
  %w{
438
468
  upper_left upper_right lower_right lower_left
439
- top bottom right left
440
- n s e w
441
469
  ne nw se sw
470
+ northwest northeast southeast southwest
442
471
  }.each do |name|
443
- src, line = <<-EOF, __LINE__ + 1
472
+ self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
444
473
  def #{name}
445
474
  self
446
475
  end
447
476
  EOF
448
- self.class_eval(src, __FILE__, line)
449
477
  end
450
478
 
451
479
  # Build some XmlMarkup for KML. You can set KML options for extrude and
File without changes
@@ -67,6 +67,10 @@ if ENV['TEST_ACTIVERECORD']
67
67
  ids_tester(:st_dwithin, [ 'POINT(5 5)', 10 ], [ 1, 2, 3 ])
68
68
  end
69
69
 
70
+ def test_dfullywithin
71
+ ids_tester(:st_dfullywithin, [ 'POINT(5 5)', 10 ], [ 1, 2 ])
72
+ end
73
+
70
74
  def test_geometry_type
71
75
  ids_tester(:st_geometry_type, 'ST_Point', [ 1, 2 ])
72
76
  ids_tester(:st_geometry_type, [ 'ST_Point', 'ST_Polygon' ], [ 1, 2, 3 ])
@@ -124,6 +128,14 @@ if ENV['TEST_ACTIVERECORD']
124
128
  assert_equal([2, 3, 1], Foo.order_by_maxdistance('POINT(1 1)', :desc => true).all.collect(&:id))
125
129
  end
126
130
 
131
+ def test_order_by_area
132
+ assert_equal([1, 2, 3], Foo.order_by_area.order('id').all.collect(&:id))
133
+ end
134
+
135
+ def test_order_by_area_desc
136
+ assert_equal([3, 1, 2], Foo.order_by_area(:desc => true).order('id').all.collect(&:id))
137
+ end
138
+
127
139
  def test_order_by_ndims
128
140
  assert_equal([1, 2, 3], Foo.order_by_ndims.order('id').all.collect(&:id))
129
141
  end
@@ -273,5 +285,9 @@ if ENV['TEST_ACTIVERECORD']
273
285
  def test_order_by_distance_spheroid_desc
274
286
  assert_equal([1, 3, 2], Foo.order_by_distance_spheroid('POINT(10 10)', 'SPHEROID["WGS 84", 6378137, 298.257223563]', :desc => true).order('id').all.collect(&:id))
275
287
  end
288
+
289
+ def test_order_by_area_with_desc_symbol
290
+ assert_equal([3, 1, 2], Foo.order_by_area(:desc).order('id').all.collect(&:id))
291
+ end
276
292
  end
277
293
  end
@@ -115,8 +115,8 @@ class GoogleMapsApi2Tests < Test::Unit::TestCase
115
115
  [ $1, $2, $3 ]
116
116
  end
117
117
 
118
- assert_in_delta(lng.to_f, 10.00, 0.000001)
119
- assert_in_delta(lat.to_f, 10.01, 0.000001)
118
+ assert_in_delta(10.00, lng.to_f, 0.000001)
119
+ assert_in_delta(10.01, lat.to_f, 0.000001)
120
120
  assert_equal(
121
121
  {},
122
122
  JSON.load(json)
@@ -138,8 +138,8 @@ class GoogleMapsApi2Tests < Test::Unit::TestCase
138
138
  [ $1, $2, $3 ]
139
139
  end
140
140
 
141
- assert_in_delta(lng.to_f, 10.00, 0.000001)
142
- assert_in_delta(lat.to_f, 10.01, 0.000001)
141
+ assert_in_delta(10.00, lng.to_f, 0.000001)
142
+ assert_in_delta(10.01, lat.to_f, 0.000001)
143
143
  assert_equal(
144
144
  {},
145
145
  JSON.load(json)
@@ -165,8 +165,8 @@ class GoogleMapsApi2Tests < Test::Unit::TestCase
165
165
  [ $1, $2, $3 ]
166
166
  end
167
167
 
168
- assert_in_delta(lng.to_f, 10.00, 0.000001)
169
- assert_in_delta(lat.to_f, 10.01, 0.000001)
168
+ assert_in_delta(10.00, lng.to_f, 0.000001)
169
+ assert_in_delta(10.01, lat.to_f, 0.000001)
170
170
  assert_equal(
171
171
  { "bounceGravity" => 1, "bouncy" => true },
172
172
  JSON.load(json)
@@ -160,8 +160,8 @@ class GoogleMapsApi3Tests < Test::Unit::TestCase
160
160
  [ $1, $2, $3 ]
161
161
  end
162
162
 
163
- assert_in_delta(lng.to_f, 10.00, 0.000001)
164
- assert_in_delta(lat.to_f, 10.01, 0.000001)
163
+ assert_in_delta(10.00, lng.to_f, 0.000001)
164
+ assert_in_delta(10.01, lat.to_f, 0.000001)
165
165
  end
166
166
 
167
167
 
@@ -0,0 +1,32 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class GoogleMapsPolylineEncoderTests < Test::Unit::TestCase
6
+ include TestHelper
7
+
8
+ ENCODED = '_p~iF~ps|U_ulLnnqC_mqNvxq`@'
9
+ DECODED = [
10
+ [ -120.2, 38.5 ],
11
+ [ -120.95, 40.7 ],
12
+ [ -126.453, 43.252 ]
13
+ ]
14
+
15
+ def test_encode
16
+ linestring = Geos.read("LINESTRING(#{DECODED.collect { |d| d.join(' ') }.join(', ')})")
17
+
18
+ assert_equal(ENCODED, Geos::GoogleMaps::PolylineEncoder.encode(linestring)[:points])
19
+ assert_equal(ENCODED,
20
+ Geos::GoogleMaps::PolylineEncoder.encode(DECODED)[:points]
21
+ )
22
+ end
23
+
24
+ def test_decode
25
+ decoded = Geos::GoogleMaps::PolylineEncoder.decode(ENCODED)
26
+
27
+ decoded.each_with_index do |(lng, lat), i|
28
+ assert_in_delta(DECODED[i][0], lng, 0.0000001)
29
+ assert_in_delta(DECODED[i][1], lat, 0.0000001)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,105 @@
1
+
2
+ $: << File.dirname(__FILE__)
3
+ require 'test_helper'
4
+
5
+ class GeosMiscTests < Test::Unit::TestCase
6
+ include TestHelper
7
+
8
+ def initialize(*args)
9
+ @polygon = Geos.read(POLYGON_WKB)
10
+ @point = Geos.read(POINT_WKB)
11
+ super(*args)
12
+ end
13
+
14
+ def write(g)
15
+ g.to_wkt(:rounding_precision => 0)
16
+ end
17
+
18
+ def test_upper_left
19
+ assert_equal('POINT (0 5)', write(@polygon.upper_left))
20
+ assert_equal('POINT (10 10)', write(@point.upper_left))
21
+
22
+ assert_equal('POINT (0 5)', write(@polygon.northwest))
23
+ assert_equal('POINT (10 10)', write(@point.northwest))
24
+
25
+ assert_equal('POINT (0 5)', write(@polygon.nw))
26
+ assert_equal('POINT (10 10)', write(@point.nw))
27
+ end
28
+
29
+ def test_upper_right
30
+ assert_equal('POINT (5 5)', write(@polygon.upper_right))
31
+ assert_equal('POINT (10 10)', write(@point.upper_right))
32
+
33
+ assert_equal('POINT (5 5)', write(@polygon.northeast))
34
+ assert_equal('POINT (10 10)', write(@point.northeast))
35
+
36
+ assert_equal('POINT (5 5)', write(@polygon.ne))
37
+ assert_equal('POINT (10 10)', write(@point.ne))
38
+ end
39
+
40
+ def test_lower_left
41
+ assert_equal('POINT (0 0)', write(@polygon.lower_left))
42
+ assert_equal('POINT (10 10)', write(@point.lower_left))
43
+
44
+ assert_equal('POINT (0 0)', write(@polygon.southwest))
45
+ assert_equal('POINT (10 10)', write(@point.southwest))
46
+
47
+ assert_equal('POINT (0 0)', write(@polygon.sw))
48
+ assert_equal('POINT (10 10)', write(@point.sw))
49
+ end
50
+
51
+ def test_lower_right
52
+ assert_equal('POINT (5 0)', write(@polygon.lower_right))
53
+ assert_equal('POINT (10 10)', write(@point.lower_right))
54
+
55
+ assert_equal('POINT (5 0)', write(@polygon.southeast))
56
+ assert_equal('POINT (10 10)', write(@point.southeast))
57
+
58
+ assert_equal('POINT (5 0)', write(@polygon.se))
59
+ assert_equal('POINT (10 10)', write(@point.se))
60
+ end
61
+
62
+ def test_top
63
+ assert_equal(5.0, @polygon.top)
64
+ assert_equal(10.01, @point.top)
65
+
66
+ assert_equal(5.0, @polygon.north)
67
+ assert_equal(10.01, @point.north)
68
+
69
+ assert_equal(5.0, @polygon.n)
70
+ assert_equal(10.01, @point.n)
71
+ end
72
+
73
+ def test_bottom
74
+ assert_equal(0.0, @polygon.bottom)
75
+ assert_equal(10.01, @point.bottom)
76
+
77
+ assert_equal(0.0, @polygon.south)
78
+ assert_equal(10.01, @point.south)
79
+
80
+ assert_equal(0.0, @polygon.s)
81
+ assert_equal(10.01, @point.s)
82
+ end
83
+
84
+ def test_left
85
+ assert_equal(0.0, @polygon.left)
86
+ assert_equal(10.0, @point.left)
87
+
88
+ assert_equal(0.0, @polygon.west)
89
+ assert_equal(10.0, @point.west)
90
+
91
+ assert_equal(0.0, @polygon.w)
92
+ assert_equal(10.0, @point.w)
93
+ end
94
+
95
+ def test_right
96
+ assert_equal(5.0, @polygon.right)
97
+ assert_equal(10.0, @point.right)
98
+
99
+ assert_equal(5.0, @polygon.east)
100
+ assert_equal(10.0, @point.east)
101
+
102
+ assert_equal(5.0, @polygon.e)
103
+ assert_equal(10.0, @point.e)
104
+ end
105
+ end
File without changes
data/test/test_helper.rb CHANGED
@@ -24,6 +24,7 @@ end
24
24
  require File.join(File.dirname(__FILE__), %w{ .. lib geos_extensions })
25
25
 
26
26
  puts "Ruby version #{RUBY_VERSION} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
27
+ puts "ffi version #{Gem.loaded_specs['ffi'].version}" if Gem.loaded_specs['ffi']
27
28
  puts "Geos library version #{Geos::VERSION}" if defined?(Geos::VERSION)
28
29
  puts "GEOS version #{Geos::GEOS_VERSION}"
29
30
  puts "GEOS extensions version #{Geos::GEOS_EXTENSIONS_VERSION}"
@@ -45,11 +46,15 @@ if ENV['TEST_ACTIVERECORD']
45
46
  ActiveRecord::Base.establish_connection 'arunit'
46
47
  ARBC = ActiveRecord::Base.connection
47
48
 
49
+ if postgresql_version = ARBC.query('SELECT version()').flatten.to_s
50
+ puts "PostgreSQL info from version(): #{postgresql_version}"
51
+ end
52
+
48
53
  puts "Checking for PostGIS install"
49
54
  2.times do
50
55
  begin
51
- if postgis_version = ARBC.query('SELECT postgis_version()').to_s
52
- puts "PostGIS info from postgis_version(): #{postgis_version}"
56
+ if postgis_version = ARBC.query('SELECT postgis_full_version()').flatten.to_s
57
+ puts "PostGIS info from postgis_full_version(): #{postgis_version}"
53
58
  break
54
59
  end
55
60
  rescue ActiveRecord::StatementInvalid
@@ -33,8 +33,8 @@ class GeosWriterTests < Test::Unit::TestCase
33
33
  lng, lat = $1.to_f, $2.to_f
34
34
  end
35
35
 
36
- assert_in_delta(lng, 10.00, 0.000001)
37
- assert_in_delta(lat, 10.01, 0.000001)
36
+ assert_in_delta(10.00, lng, 0.000001)
37
+ assert_in_delta(10.01, lat, 0.000001)
38
38
  end
39
39
 
40
40
  def test_to_ewkb_bin
@@ -52,8 +52,8 @@ class GeosWriterTests < Test::Unit::TestCase
52
52
  lng, lat = $1.to_f, $2.to_f
53
53
  end
54
54
 
55
- assert_in_delta(lng, 10.00, 0.000001)
56
- assert_in_delta(lat, 10.01, 0.000001)
55
+ assert_in_delta(10.00, lng, 0.000001)
56
+ assert_in_delta(10.01, lat, 0.000001)
57
57
  end
58
58
 
59
59
  def test_to_flickr_bbox
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geos-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-12 00:00:00.000000000Z
12
+ date: 2011-11-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Extensions for the GEOS library.
15
15
  email: code@zoocasa.com
@@ -38,15 +38,17 @@ files:
38
38
  - lib/geos/rails/engine.rb
39
39
  - lib/geos_extensions.rb
40
40
  - lib/tasks/test.rake
41
- - test/adapter_test.rb
41
+ - test/adapter_tests.rb
42
42
  - test/fixtures/foos.yml
43
- - test/geometry_columns_test.rb
44
- - test/geospatial_scopes_test.rb
45
- - test/google_maps_api_2_test.rb
46
- - test/google_maps_api_3_test.rb
47
- - test/reader_test.rb
43
+ - test/geometry_columns_tests.rb
44
+ - test/geospatial_scopes_tests.rb
45
+ - test/google_maps_api_2_tests.rb
46
+ - test/google_maps_api_3_tests.rb
47
+ - test/google_maps_polyline_encoder_tests.rb
48
+ - test/misc_tests.rb
49
+ - test/reader_tests.rb
48
50
  - test/test_helper.rb
49
- - test/writer_test.rb
51
+ - test/writer_tests.rb
50
52
  homepage: http://github.com/zoocasa/geos-extensions
51
53
  licenses: []
52
54
  post_install_message:
@@ -67,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  version: '0'
68
70
  requirements: []
69
71
  rubyforge_project:
70
- rubygems_version: 1.8.5
72
+ rubygems_version: 1.8.11
71
73
  signing_key:
72
74
  specification_version: 3
73
75
  summary: Extensions for the GEOS library.