navigate 1.0.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53412925eb7c7c776e1e618bd00427542eed887e
4
- data.tar.gz: 91ff503dde1685f6188940b5aa915179918e365b
3
+ metadata.gz: d65809740ba55a6fb3e05b3a19807e1bd5b611f5
4
+ data.tar.gz: edf223e53205e350915a40f2b79ee5629048ed1c
5
5
  SHA512:
6
- metadata.gz: 2811b9ca2835e6ed8dfc9c0ee5036fbb4fb5b0b6644050f684f2dd88b34123b81be158e0bdce25b907f0326774256b626bb61ab5631ec98f214cb46c0a1c3469
7
- data.tar.gz: 92b950abfda34c7be652384aac5c12e1639dd9be5b282fcd0e6e5010417f45998a3df1d2dfe436290e3bdc7dcda83accb08e6e8d5766efa8e62e3d5433051922
6
+ metadata.gz: dabd73770c433a9aa3eb0aceb2875e14776471ef378a459db1b4a329783f1a8cb5931bc5213884af74577e828b44a047faf83e7a32fb0688b753c9dccb1828ad
7
+ data.tar.gz: 606a843635d970e9705eab0bf0acafba287b6a97e054c52734708fcad572dc69de9e6ac30e35f75d9c43db3d597002979f8c24853f4d83b103bdec468641574c
data/Gemfile CHANGED
@@ -13,6 +13,8 @@ group :development do
13
13
  gem "simplecov", ">= 0"
14
14
  end
15
15
 
16
+ gem 'coveralls', require: false
17
+
16
18
  group :test do
17
19
  gem 'rake'
18
20
  end
data/Gemfile.lock CHANGED
@@ -9,9 +9,17 @@ GEM
9
9
  tzinfo (~> 1.1)
10
10
  addressable (2.3.8)
11
11
  builder (3.2.2)
12
+ coveralls (0.8.1)
13
+ json (~> 1.8)
14
+ rest-client (>= 1.6.8, < 2)
15
+ simplecov (~> 0.10.0)
16
+ term-ansicolor (~> 1.3)
17
+ thor (~> 0.19.1)
12
18
  descendants_tracker (0.0.4)
13
19
  thread_safe (~> 0.3, >= 0.3.1)
14
20
  docile (1.1.5)
21
+ domain_name (0.5.24)
22
+ unf (>= 0.0.5, < 1.0.0)
15
23
  faraday (0.9.1)
16
24
  multipart-post (>= 1.2, < 3)
17
25
  git (1.2.9.1)
@@ -25,6 +33,8 @@ GEM
25
33
  oauth2
26
34
  hashie (3.4.1)
27
35
  highline (1.7.2)
36
+ http-cookie (1.0.2)
37
+ domain_name (~> 0.5)
28
38
  i18n (0.7.0)
29
39
  jeweler (2.0.1)
30
40
  builder
@@ -37,11 +47,13 @@ GEM
37
47
  rdoc
38
48
  json (1.8.2)
39
49
  jwt (1.4.1)
50
+ mime-types (2.6.1)
40
51
  mini_portile (0.6.2)
41
52
  minitest (5.6.1)
42
53
  multi_json (1.11.0)
43
54
  multi_xml (0.5.5)
44
55
  multipart-post (2.0.0)
56
+ netrc (0.10.3)
45
57
  nokogiri (1.6.6.2)
46
58
  mini_portile (~> 0.6.0)
47
59
  oauth2 (1.0.0)
@@ -54,6 +66,10 @@ GEM
54
66
  rake (10.4.2)
55
67
  rdoc (3.12.2)
56
68
  json (~> 1.4)
69
+ rest-client (1.8.0)
70
+ http-cookie (>= 1.0.2, < 2.0)
71
+ mime-types (>= 1.16, < 3.0)
72
+ netrc (~> 0.7)
57
73
  shoulda (3.5.0)
58
74
  shoulda-context (~> 1.0, >= 1.0.1)
59
75
  shoulda-matchers (>= 1.4.1, < 3.0)
@@ -65,15 +81,23 @@ GEM
65
81
  json (~> 1.8)
66
82
  simplecov-html (~> 0.10.0)
67
83
  simplecov-html (0.10.0)
84
+ term-ansicolor (1.3.0)
85
+ tins (~> 1.0)
86
+ thor (0.19.1)
68
87
  thread_safe (0.3.5)
88
+ tins (1.5.2)
69
89
  tzinfo (1.2.2)
70
90
  thread_safe (~> 0.1)
91
+ unf (0.1.4)
92
+ unf_ext
93
+ unf_ext (0.0.7.1)
71
94
 
72
95
  PLATFORMS
73
96
  ruby
74
97
 
75
98
  DEPENDENCIES
76
99
  bundler (~> 1.0)
100
+ coveralls
77
101
  jeweler (~> 2.0.1)
78
102
  rake
79
103
  rdoc (~> 3.12)
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Build Status](https://travis-ci.org/jonatasrancan/navigate.svg?branch=master)](https://travis-ci.org/jonatasrancan/navigate)
2
+ [![Gem Version](https://badge.fury.io/rb/navigate.svg)](http://badge.fury.io/rb/navigate)
3
+ [![Coverage Status](https://coveralls.io/repos/jonatasrancan/navigate/badge.svg?branch=master)](https://coveralls.io/r/jonatasrancan/navigate?branch=master)
2
4
  ## navigate
3
5
 
4
6
  A simple gem with some functions, to calculate the distance, bearing between two positions or
@@ -51,7 +53,7 @@ Navigate::bearing(position1, position2)
51
53
  ```ruby
52
54
  position1 = Navigate::Position.new(-90.0, 180.0)
53
55
 
54
- Navigate::bearing(position1)
56
+ Navigate::destination(position1)
55
57
  # => #<Navigate::Position:0x00000003edc7b0 @latitude=-89.10067966450693, @longitude=-90.0>
56
58
  ```
57
59
  By default the function will use a bearing = 90.0, distance = 100 KM
@@ -59,24 +61,24 @@ By default the function will use a bearing = 90.0, distance = 100 KM
59
61
  It receive a hash of options to pass the bearing, distance and the unit of the distance
60
62
 
61
63
  ```ruby
62
- Navigate::bearing(position1, bearing: 180.0, distance: 150, radius_unit: 'FT')
63
- # => #<Navigate::Position:0x00000003e9b198 @latitude=-90.0, @longitude=-180.0>
64
+ Navigate::destination(position1, bearing: 180.0, distance: 150, radius_unit: 'FT')
65
+ # => #<Navigate::Position:0x00000003e9b198 @latitude=-90.0, @longitude=-180.0>
64
66
  ```
65
67
 
66
68
  Contributing to navigate
67
- ------------------------
69
+ ------------------------
68
70
  Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
69
-
71
+
70
72
  Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
71
-
73
+
72
74
  Fork the project.
73
-
75
+
74
76
  Start a feature/bugfix branch.
75
-
77
+
76
78
  Commit and push until you are happy with your contribution.
77
-
79
+
78
80
  Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
79
-
81
+
80
82
  Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
81
83
 
82
84
  License
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.1
data/lib/navigate.rb CHANGED
@@ -2,42 +2,15 @@ module Navigate
2
2
  EARTH_RADIUS = { 'KM' => 6371.009, 'MI' => 3958.761, 'NM' => 3440.070, 'YD' => 6967420, 'FT' => 20902260 }
3
3
 
4
4
  def self.distance_between(position1, position2, radius_unit = 'KM')
5
- Math::acos(
6
- Math::sin(position1.latitude.to_radians) * Math::sin(position2.latitude.to_radians) +
7
- Math::cos(position1.latitude.to_radians) * Math::cos(position2.latitude.to_radians) *
8
- Math::cos((position2.longitude - position1.longitude).to_radians)
9
- ) * EARTH_RADIUS[radius_unit]
5
+ DistanceBetween.calculate(position1, position2, radius_unit)
10
6
  end
11
7
 
12
8
  def self.bearing(position1, position2)
13
- dLon = (position2.longitude - position1.longitude).to_radians
14
-
15
- y = Math::sin(dLon) * Math::cos(position2.latitude.to_radians)
16
- x = Math::cos(position1.latitude.to_radians) * Math::sin(position2.latitude.to_radians) -
17
- Math::sin(position1.latitude.to_radians) * Math::cos(position2.latitude.to_radians) * Math::cos(dLon)
18
-
19
- Math::atan2(y, x).to_bearing
9
+ Bearing.calculate(position1, position2)
20
10
  end
21
11
 
22
12
  def self.destination(position, options = {})
23
- radius = EARTH_RADIUS[options[:radius_unit] || 'KM']
24
- distance = options[:distance] || 100.0
25
- brng = options[:bearing] || 90.0
26
-
27
- new_lat = Math::asin(
28
- Math::sin(position.latitude.to_radians) * Math::cos(distance / radius) +
29
- Math::cos(position.latitude.to_radians) * Math::sin(distance / radius) *
30
- Math::cos(brng)
31
- )
32
-
33
- new_lon = position.longitude.to_radians + Math::atan2(
34
- Math::sin(brng) * Math::sin(distance / radius) * Math::cos(position.latitude.to_radians),
35
- Math::cos(distance / radius) - Math::sin(position.latitude.to_radians) * Math::sin(new_lat)
36
- )
37
-
38
- new_lon = (new_lon + Math::PI) % (2 * Math::PI) - Math::PI
39
-
40
- Position.new new_lat.to_degrees, new_lon.to_degrees
13
+ Destination.calculate(position, options)
41
14
  end
42
15
  end
43
16
 
@@ -45,3 +18,6 @@ path = File.expand_path(File.dirname(__FILE__))
45
18
  $:.unshift path unless $:.include?(path)
46
19
  require 'navigate/conversions'
47
20
  require 'navigate/position'
21
+ require 'navigate/bearing'
22
+ require 'navigate/distance_between'
23
+ require 'navigate/destination'
@@ -22,8 +22,6 @@ module Navigate
22
22
  def valid?
23
23
  valid_latitude?
24
24
  valid_longitude?
25
-
26
- true
27
25
  end
28
26
  end
29
27
  end
data/test/helper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'simplecov'
2
+ require 'coveralls'
3
+ Coveralls.wear!
2
4
 
3
5
  module SimpleCov::Configuration
4
6
  def clean_filters
@@ -1,39 +1,42 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Navigate do
4
- context "#distance" do
5
- it 'calculates the distance between 2 positions in kilometers' do
6
- position1 = Navigate::Position.new(90.0, 120.0)
7
- position2 = Navigate::Position.new(90.0, 120.0)
4
+ before do
5
+ @position1 = Navigate::Position.new(90.0, 120.0)
6
+ @position2 = Navigate::Position.new(80.0, 120.0)
7
+ end
8
8
 
9
- Navigate::distance_between(position1, position2).must_equal 0
9
+ describe "#distance_between" do
10
+ it 'calculates the distance between 2 positions in kilometers' do
11
+ Navigate::distance_between(@position1, @position1).must_equal 0
10
12
  end
11
13
 
12
14
  it 'calculates the distance between 2 positions in kilometers' do
13
- position1 = Navigate::Position.new(90.0, 120.0)
14
- position2 = Navigate::Position.new(80.0, 120.0)
15
-
16
- km = Navigate::distance_between(position1, position2).round(2)
15
+ km = Navigate::distance_between(@position1, @position2).round(2)
17
16
 
18
17
  km.must_equal 1111.95
19
18
  end
20
19
 
21
20
  it 'calculates the distance between 2 positions in nautic miles' do
22
- position1 = Navigate::Position.new(90.0, 120.0)
23
- position2 = Navigate::Position.new(80.0, 120.0)
24
-
25
- nm = Navigate::distance_between(position1, position2, 'NM').round(2)
21
+ nm = Navigate::distance_between(@position1, @position2, 'NM').round(2)
26
22
 
27
23
  nm.must_equal 600.41
28
24
  end
29
- end
30
25
 
31
- describe '#bearing' do
32
- before do
33
- @position1 = Navigate::Position.new(90.0, 120.0)
34
- @position2 = Navigate::Position.new(80.0, 120.0)
26
+ it "raise exception when first arg isn't a Navigate::Position" do
27
+ exception = assert_raises(RuntimeError) { Navigate::distance_between('wrong type', 90.0) }
28
+
29
+ assert_match /First arg, must be a Navigate::Position instance/, exception.message
35
30
  end
36
31
 
32
+ it "raise exception when second arg isn't a Navigate::Position" do
33
+ exception = assert_raises(RuntimeError) { Navigate::distance_between(@position1, 500) }
34
+
35
+ assert_match /Second arg, must be a Navigate::Position instance/, exception.message
36
+ end
37
+ end
38
+
39
+ describe '#bearing' do
37
40
  it 'calculates the bearing between 2 positions' do
38
41
  bearing = Navigate::bearing(@position1, @position2)
39
42
 
@@ -45,13 +48,23 @@ describe Navigate do
45
48
 
46
49
  bearing.must_equal 0
47
50
  end
51
+
52
+ it "raise exception when first arg isn't a Navigate::Position" do
53
+ exception = assert_raises(RuntimeError) { Navigate::bearing('wrong type', 90.0) }
54
+
55
+ assert_match /First arg, must be a Navigate::Position instance/, exception.message
56
+ end
57
+
58
+ it "raise exception when second arg isn't a Navigate::Position" do
59
+ exception = assert_raises(RuntimeError) { Navigate::bearing(@position1, 500) }
60
+
61
+ assert_match /Second arg, must be a Navigate::Position instance/, exception.message
62
+ end
48
63
  end
49
64
 
50
65
  describe '#destination' do
51
66
  it 'returns a final position, using default radius unit, distance and bearing' do
52
- position1 = Navigate::Position.new(90.0, 120.0)
53
-
54
- destination = Navigate::destination(position1)
67
+ destination = Navigate::destination(@position1)
55
68
 
56
69
  assert_kind_of Navigate::Position, destination
57
70
 
@@ -60,12 +73,22 @@ describe Navigate do
60
73
  end
61
74
 
62
75
  it 'returns a final positions, passing custom radius unit, distance and bearing' do
63
- position1 = Navigate::Position.new(90.0, 120.0)
64
-
65
- destination = Navigate::destination(position1, bearing: 270, radius_unit: 'NM', distance: 200)
76
+ destination = Navigate::destination(@position1, bearing: 270, radius_unit: 'NM', distance: 200)
66
77
 
67
78
  destination.longitude.round(2).must_equal 30.0
68
79
  destination.latitude.round(2).must_equal 86.67
69
80
  end
81
+
82
+ it "raise exception when first arg isn't a Navigate::Position" do
83
+ exception = assert_raises(RuntimeError) { Navigate::destination('wrong type') }
84
+
85
+ assert_match /First arg, must be a Navigate::Position instance/, exception.message
86
+ end
87
+
88
+ it "raise exception when bearing is out of range" do
89
+ exception = assert_raises(RuntimeError) { Navigate::destination(@position1, bearing: 500) }
90
+
91
+ assert_match /Bearing must be between 0.0 and 360.0/, exception.message
92
+ end
70
93
  end
71
94
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: navigate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jônatas Rancan de Souza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda