geo_calc 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,8 +3,9 @@ source "http://rubygems.org"
3
3
  # Add dependencies to develop your gem here.
4
4
  # Include everything needed to run rake, tests, features, etc.
5
5
  group :development do
6
- gem "rspec", ">= 2.5.0"
7
- gem "bundler", "~> 1.0.0"
8
- gem "jeweler", "~> 1.5.2"
9
- gem "rcov", ">= 0"
6
+ gem "rspec", ">= 2.5.0"
7
+ gem "bundler", ">= 1"
8
+ gem "jeweler", ">= 1.5.2"
9
+ gem "rcov", ">= 0"
10
+ gem "rake", ">= 0.9"
10
11
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.5.2
data/geo_calc.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geo_calc}
8
- s.version = "0.5.1"
8
+ s.version = "0.5.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Kristian Mandrup}]
@@ -10,6 +10,39 @@ module NumericCheckExt
10
10
  end
11
11
  end
12
12
 
13
+ module GeoUnits
14
+ module Converter
15
+ # Converts numeric degrees to radians
16
+ def to_rad degrees
17
+ degrees * Math::PI / 180
18
+ end
19
+ alias_method :to_radians, :to_rad
20
+ alias_method :as_rad, :to_rad
21
+ alias_method :as_radians, :to_rad
22
+ alias_method :in_rad, :to_rad
23
+ alias_method :in_radians, :to_rad
24
+
25
+
26
+ # Converts radians to numeric (signed) degrees
27
+ # latitude (north to south) from equator +90 up then -90 down (equator again) = 180 then 180 for south = 360 total
28
+ # longitude (west to east) east +180, west -180 = 360 total
29
+ def to_deg radians
30
+ radians * 180 / Math::PI
31
+ end
32
+
33
+ alias_method :to_degrees, :to_deg
34
+ alias_method :as_deg, :to_deg
35
+ alias_method :as_degrees, :to_deg
36
+ alias_method :in_deg, :to_deg
37
+ alias_method :in_degrees, :to_deg
38
+ end
39
+
40
+ def normalize_deg degrees, shift = 0
41
+ (degrees + shift) % 360
42
+ end
43
+ alias_method :normalize_degrees, :normalize_deg
44
+ end
45
+
13
46
  module NumericGeoExt
14
47
  def to_dms format = :dms, dp = nil
15
48
  Geo.to_dms self, format, dp
@@ -21,21 +21,9 @@ class GeoPoint
21
21
  # - Numeric lon: longitude in numeric degrees
22
22
  # - Numeric [rad=6371]: radius of earth if different value is required from standard 6,371km
23
23
 
24
- attr_reader :lat, :lon, :unit, :radius
24
+ attr_reader :lat, :lon
25
+ attr_accessor :radius
25
26
 
26
- (Symbol.lng_symbols - [:lon]).each do |sym|
27
- class_eval %{
28
- alias_method :#{sym}, :lon
29
- }
30
- end
31
-
32
- (Symbol.lat_symbols - [:lat]).each do |sym|
33
- class_eval %{
34
- alias_method :#{sym}, :lat
35
- }
36
- end
37
-
38
-
39
27
  def initialize *args
40
28
  rad = args.delete(args.size) if is_numeric?(args.last) && args.last.is_between?(6350, 6380)
41
29
  rad ||= 6371 # default
@@ -49,6 +37,32 @@ class GeoPoint
49
37
  end
50
38
  end
51
39
 
40
+ def unit
41
+ :degrees
42
+ end
43
+
44
+ def lat= value
45
+ @lat = value.to_lat
46
+ end
47
+
48
+ def lon= value
49
+ @lon = lon.to_lng
50
+ end
51
+
52
+ (Symbol.lng_symbols - [:lon]).each do |sym|
53
+ class_eval %{
54
+ alias_method :#{sym}, :lon
55
+ alias_method :#{sym}=, :lon=
56
+ }
57
+ end
58
+
59
+ (Symbol.lat_symbols - [:lat]).each do |sym|
60
+ class_eval %{
61
+ alias_method :#{sym}, :lat
62
+ alias_method :#{sym}=, :lat=
63
+ }
64
+ end
65
+
52
66
  def [] key
53
67
  case key
54
68
  when Fixnum
@@ -96,8 +110,7 @@ class GeoPoint
96
110
  rad ||= 6371 # earth's mean radius in km
97
111
  @lat = lat.to_lat
98
112
  @lon = lon.to_lng
99
- @radius = rad
100
- @unit = :degrees
113
+ @radius = rad
101
114
  end
102
115
  end
103
116
 
@@ -176,6 +176,29 @@ describe GeoPoint do
176
176
  end
177
177
  end
178
178
 
179
+ describe '#lat=' do
180
+ before :each do
181
+ @p1 = GeoPoint.new 50, 5
182
+ end
183
+
184
+ it 'should set new latitude' do
185
+ @p1.lat = 60
186
+ @p1.lat.should == 60
187
+ end
188
+
189
+ it 'should set new latitude within allowed range' do
190
+ @p1.lat = 520
191
+ @p1.lat.should be_between(0, 360)
192
+ end
193
+
194
+ describe '#latitude (alias)' do
195
+ it 'should set latitude' do
196
+ @p1.lat = 72
197
+ @p1.latitude.should == 72
198
+ end
199
+ end
200
+ end
201
+
179
202
  describe '#[]' do
180
203
  before :each do
181
204
  @p1 = GeoPoint.new 50, 5
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_calc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-05-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2152964520 !ruby/object:Gem::Requirement
16
+ requirement: &2157580520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.5.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152964520
24
+ version_requirements: *2157580520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &2152963980 !ruby/object:Gem::Requirement
27
+ requirement: &2157580040 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152963980
35
+ version_requirements: *2157580040
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &2152955240 !ruby/object:Gem::Requirement
38
+ requirement: &2157579560 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.5.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152955240
46
+ version_requirements: *2157579560
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &2152954660 !ruby/object:Gem::Requirement
49
+ requirement: &2157579080 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152954660
57
+ version_requirements: *2157579080
58
58
  description: Geo calculations in ruby and javascript
59
59
  email: kmandrup@gmail.com
60
60
  executables: []
@@ -95,9 +95,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
95
  - - ! '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
- segments:
99
- - 0
100
- hash: 4431488091185684901
101
98
  required_rubygems_version: !ruby/object:Gem::Requirement
102
99
  none: false
103
100
  requirements: