haversine 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5257398613d740fce304d12c6c23032fb6bd7c1d
4
+ data.tar.gz: 7ffdad76a515dc827e2f24c18efdedf29f57f3b0
5
+ SHA512:
6
+ metadata.gz: d00df6e6d32290977c4adc24e7f8e8845ffc064ffeb618bf89d35ebb5c792029ab26563d30bf6512671e12b8766f28551ce83f612d67bf869312b6a2c4ea69a1
7
+ data.tar.gz: 3adc943366ed143d5f7a6450292797404c2c29e0eee5fe3ef38d064c9b2597c8be4e4e81536dcae1999674cd67e9a376e8bf08acf2218f7836bd77935c7bb417
data/Gemfile CHANGED
@@ -6,8 +6,7 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
- gem "rspec", ">= 2.3.0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
9
+ gem "rspec", ">= 2.14.0"
10
+ gem "bundler", ">= 1.3.0"
11
+ gem "jeweler", ">= 1.8.6"
13
12
  end
@@ -18,6 +18,7 @@ distance.to_miles => 6032.71091869803
18
18
  distance.to_kilometers => 9715.47049115903
19
19
  distance.to_meters => 9715470.49115903
20
20
  distance.to_feet => 31852713.6507256
21
+ distance.to_nautical_miles => 5242.2799481204265
21
22
  </pre>
22
23
 
23
24
  Convenience aliases for the measurements exist:
@@ -26,20 +27,11 @@ distance.to_kilometers == distance.to_km
26
27
  distance.to_meters == distance.to_m
27
28
  distance.to_miles == distance.to_mi
28
29
  distance.to_feet == distance.to_ft
30
+ distance.to_nautical_miles == distance.to_nm
29
31
  </pre>
30
32
 
31
33
  Note that @to_m@ is the distance in meters, not miles.
32
34
 
33
- puts "#{dist[:feet]}"
34
- puts "#{dist.meters}"
35
- puts "#{dist[:km]}"
36
- puts "#{dist[:miles]}"
37
- puts "#{dist.to_mi}"
38
- puts "#{dist.to_miles_}"
39
- dist[:km].to_s.should match(/7\.376*/)
40
- dist.to_km.to_s.should match(/7\.376*/)
41
- end
42
-
43
35
  If you have lat/lon pairs stored in an array, you can alternately provide two arrays when calling @Haversine.distance@:
44
36
 
45
37
  <pre>
@@ -64,4 +56,4 @@ h2. Contributing to haversine
64
56
  h2. Copyright
65
57
 
66
58
  Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
67
- further details.
59
+ further details.
data/Rakefile CHANGED
@@ -34,14 +34,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
34
34
  spec.pattern = FileList['spec/**/*_spec.rb']
35
35
  end
36
36
 
37
- RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ RSpec::Core::RakeTask.new(:coverage) do |spec|
38
38
  spec.pattern = 'spec/**/*_spec.rb'
39
- spec.rcov = true
39
+ ENV['COVERAGE'] = 'true'
40
40
  end
41
41
 
42
42
  task :default => :spec
43
43
 
44
- require 'rake/rdoctask'
44
+ require 'rdoc/task'
45
45
  Rake::RDocTask.new do |rdoc|
46
46
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
47
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -2,17 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: haversine 0.3.1 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
- s.name = %q{haversine}
8
- s.version = "0.3.0"
8
+ s.name = "haversine".freeze
9
+ s.version = "0.3.1"
9
10
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Kristian Mandrup}, %q{Ryan Greenberg}]
12
- s.date = %q{2011-06-05}
13
- s.description = %q{Calculates the haversine distance between two locations using longitude and latitude.
14
- This is done using Math formulas without resorting to Active Record or SQL DB functionality}
15
- s.email = %q{kmandrup@gmail.com}
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Kristian Mandrup".freeze, "Ryan Greenberg".freeze]
14
+ s.date = "2016-06-23"
15
+ s.description = "Calculates the haversine distance between two locations using longitude and latitude. \nThis is done using Math formulas without resorting to Active Record or SQL DB functionality".freeze
16
+ s.email = "kmandrup@gmail.com".freeze
16
17
  s.extra_rdoc_files = [
17
18
  "LICENSE.txt",
18
19
  "README.textile"
@@ -21,7 +22,6 @@ This is done using Math formulas without resorting to Active Record or SQL DB fu
21
22
  ".document",
22
23
  ".rspec",
23
24
  "Gemfile",
24
- "Gemfile.lock",
25
25
  "LICENSE.txt",
26
26
  "README.textile",
27
27
  "Rakefile",
@@ -33,36 +33,27 @@ This is done using Math formulas without resorting to Active Record or SQL DB fu
33
33
  "spec/haversine_spec.rb",
34
34
  "spec/spec_helper.rb"
35
35
  ]
36
- s.homepage = %q{http://github.com/kristianmandrup/haversine}
37
- s.licenses = [%q{MIT}]
38
- s.require_paths = [%q{lib}]
39
- s.rubygems_version = %q{1.8.5}
40
- s.summary = %q{Calculates the haversine distance between two locations using longitude and latitude}
41
- s.test_files = [
42
- "spec/distance_spec.rb",
43
- "spec/haversine_spec.rb",
44
- "spec/spec_helper.rb"
45
- ]
36
+ s.homepage = "http://github.com/kristianmandrup/haversine".freeze
37
+ s.licenses = ["MIT".freeze]
38
+ s.rubygems_version = "2.6.2".freeze
39
+ s.summary = "Calculates the haversine distance between two locations using longitude and latitude".freeze
46
40
 
47
41
  if s.respond_to? :specification_version then
48
- s.specification_version = 3
42
+ s.specification_version = 4
49
43
 
50
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- s.add_development_dependency(%q<rspec>, [">= 2.3.0"])
52
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
- s.add_development_dependency(%q<rcov>, [">= 0"])
45
+ s.add_development_dependency(%q<rspec>.freeze, [">= 2.14.0"])
46
+ s.add_development_dependency(%q<bundler>.freeze, [">= 1.3.0"])
47
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 1.8.6"])
55
48
  else
56
- s.add_dependency(%q<rspec>, [">= 2.3.0"])
57
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
59
- s.add_dependency(%q<rcov>, [">= 0"])
49
+ s.add_dependency(%q<rspec>.freeze, [">= 2.14.0"])
50
+ s.add_dependency(%q<bundler>.freeze, [">= 1.3.0"])
51
+ s.add_dependency(%q<jeweler>.freeze, [">= 1.8.6"])
60
52
  end
61
53
  else
62
- s.add_dependency(%q<rspec>, [">= 2.3.0"])
63
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
- s.add_dependency(%q<rcov>, [">= 0"])
54
+ s.add_dependency(%q<rspec>.freeze, [">= 2.14.0"])
55
+ s.add_dependency(%q<bundler>.freeze, [">= 1.3.0"])
56
+ s.add_dependency(%q<jeweler>.freeze, [">= 1.8.6"])
66
57
  end
67
58
  end
68
59
 
@@ -1,28 +1,9 @@
1
1
  #
2
- # haversine formula to compute the great circle distance between two points given their latitude and longitudes
3
- #
4
- # Copyright (C) 2008, 360VL, Inc
5
- # Copyright (C) 2008, Landon Cox
6
- #
7
- # http://www.esawdust.com (Landon Cox)
8
- # contact:
9
- # http://www.esawdust.com/blog/businesscard/businesscard.html
10
- #
11
- # LICENSE: GNU Affero GPL v3
12
- # The ruby implementation of the Haversine formula is free software: you can redistribute it and/or modify
13
- # it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation.
14
- #
15
- # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
16
- # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
17
- # License version 3 for more details. http://www.gnu.org/licenses/
18
- #
19
- # Landon Cox - 9/25/08
2
+ # Haversine formula to compute the great circle distance between two points given their latitude and longitudes
20
3
  #
21
4
  # Notes:
22
5
  #
23
6
  # translated into Ruby based on information contained in:
24
- # http://mathforum.org/library/drmath/view/51879.html Doctors Rick and Peterson - 4/20/99
25
- # http://www.movable-type.co.uk/scripts/latlong.html
26
7
  # http://en.wikipedia.org/wiki/Haversine_formula
27
8
  #
28
9
  # This formula can compute accurate distances between two points given latitude and longitude, even for
@@ -1,40 +1,46 @@
1
1
  module Haversine
2
2
  class Distance
3
3
  include Comparable
4
-
4
+
5
5
  GREAT_CIRCLE_RADIUS_MILES = 3956
6
6
  GREAT_CIRCLE_RADIUS_KILOMETERS = 6371 # some algorithms use 6367
7
7
  GREAT_CIRCLE_RADIUS_FEET = GREAT_CIRCLE_RADIUS_MILES * 5280
8
8
  GREAT_CIRCLE_RADIUS_METERS = GREAT_CIRCLE_RADIUS_KILOMETERS * 1000
9
+ GREAT_CIRCLE_RADIUS_NAUTICAL_MILES = GREAT_CIRCLE_RADIUS_MILES / 1.15078
9
10
 
10
11
  attr_reader :great_circle_distance
11
12
 
12
13
  def initialize(great_circle_distance)
13
14
  @great_circle_distance = great_circle_distance
14
15
  end
15
-
16
+
16
17
  def to_miles
17
18
  @great_circle_distance * GREAT_CIRCLE_RADIUS_MILES
18
19
  end
19
20
  alias_method :to_mi, :to_miles
20
-
21
+
21
22
  def to_kilometers
22
23
  @great_circle_distance * GREAT_CIRCLE_RADIUS_KILOMETERS
23
24
  end
24
25
  alias_method :to_km, :to_kilometers
25
-
26
+
26
27
  def to_meters
27
28
  @great_circle_distance * GREAT_CIRCLE_RADIUS_METERS
28
29
  end
29
30
  alias_method :to_m, :to_meters
30
-
31
+
31
32
  def to_feet
32
33
  @great_circle_distance * GREAT_CIRCLE_RADIUS_FEET
33
34
  end
34
35
  alias_method :to_ft, :to_feet
35
-
36
+
37
+ def to_nautical_miles
38
+ @great_circle_distance * GREAT_CIRCLE_RADIUS_NAUTICAL_MILES
39
+ end
40
+ alias_method :to_nm, :to_nautical_miles
41
+
36
42
  def <=>(other)
37
43
  great_circle_distance <=> other.great_circle_distance
38
44
  end
39
45
  end
40
- end
46
+ end
@@ -16,7 +16,15 @@ describe Haversine do
16
16
  array_dist.should be_a(Haversine::Distance)
17
17
  point_dist.to_m.should == array_dist.to_m
18
18
  end
19
-
19
+
20
+ it "computes nautical mile distances correctly" do
21
+ new_york_city = [40.71427, -74.00597]
22
+ santiago_chile = [-33.42628, -70.56656]
23
+ dist = Haversine.distance(new_york_city, santiago_chile)
24
+ dist.to_miles.should eq(5123.736179853891)
25
+ dist.to_nautical_miles.should eq(4452.402874445064)
26
+ end
27
+
20
28
  it "calculates the distance between the provided lat/lon pairs" do
21
29
  Haversine.distance(0,0,0,0).to_miles.should == 0
22
30
  round_to(6, Haversine.distance(0,0,0,360).to_miles).should == 0
@@ -28,4 +36,4 @@ describe Haversine do
28
36
  def round_to(precision, num)
29
37
  (num * 10**precision).round.to_f / 10**precision
30
38
  end
31
- end
39
+ end
@@ -2,7 +2,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'haversine'
5
-
5
+ require 'simplecov'
6
+ SimpleCov.start if ENV["COVERAGE"]
6
7
  # Requires supporting files with custom matchers and macros, etc,
7
8
  # in ./support/ and its subdirectories.
8
9
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haversine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.3.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kristian Mandrup
@@ -10,53 +9,51 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2011-06-05 00:00:00.000000000Z
12
+ date: 2016-06-23 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
- requirement: &2154359680 !ruby/object:Gem::Requirement
18
- none: false
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  requirements:
20
- - - ! '>='
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
- version: 2.3.0
20
+ version: 2.14.0
23
21
  type: :development
24
22
  prerelease: false
25
- version_requirements: *2154359680
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 2.14.0
26
28
  - !ruby/object:Gem::Dependency
27
29
  name: bundler
28
- requirement: &2154359180 !ruby/object:Gem::Requirement
29
- none: false
30
+ requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ~>
32
+ - - ">="
32
33
  - !ruby/object:Gem::Version
33
- version: 1.0.0
34
+ version: 1.3.0
34
35
  type: :development
35
36
  prerelease: false
36
- version_requirements: *2154359180
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 1.3.0
37
42
  - !ruby/object:Gem::Dependency
38
43
  name: jeweler
39
- requirement: &2154358680 !ruby/object:Gem::Requirement
40
- none: false
44
+ requirement: !ruby/object:Gem::Requirement
41
45
  requirements:
42
- - - ~>
46
+ - - ">="
43
47
  - !ruby/object:Gem::Version
44
- version: 1.5.2
48
+ version: 1.8.6
45
49
  type: :development
46
50
  prerelease: false
47
- version_requirements: *2154358680
48
- - !ruby/object:Gem::Dependency
49
- name: rcov
50
- requirement: &2154358200 !ruby/object:Gem::Requirement
51
- none: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ! '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
56
- type: :development
57
- prerelease: false
58
- version_requirements: *2154358200
59
- description: ! "Calculates the haversine distance between two locations using longitude
55
+ version: 1.8.6
56
+ description: "Calculates the haversine distance between two locations using longitude
60
57
  and latitude. \nThis is done using Math formulas without resorting to Active Record
61
58
  or SQL DB functionality"
62
59
  email: kmandrup@gmail.com
@@ -66,10 +63,9 @@ extra_rdoc_files:
66
63
  - LICENSE.txt
67
64
  - README.textile
68
65
  files:
69
- - .document
70
- - .rspec
66
+ - ".document"
67
+ - ".rspec"
71
68
  - Gemfile
72
- - Gemfile.lock
73
69
  - LICENSE.txt
74
70
  - README.textile
75
71
  - Rakefile
@@ -83,33 +79,26 @@ files:
83
79
  homepage: http://github.com/kristianmandrup/haversine
84
80
  licenses:
85
81
  - MIT
82
+ metadata: {}
86
83
  post_install_message:
87
84
  rdoc_options: []
88
85
  require_paths:
89
86
  - lib
90
87
  required_ruby_version: !ruby/object:Gem::Requirement
91
- none: false
92
88
  requirements:
93
- - - ! '>='
89
+ - - ">="
94
90
  - !ruby/object:Gem::Version
95
91
  version: '0'
96
- segments:
97
- - 0
98
- hash: -2758069868473656390
99
92
  required_rubygems_version: !ruby/object:Gem::Requirement
100
- none: false
101
93
  requirements:
102
- - - ! '>='
94
+ - - ">="
103
95
  - !ruby/object:Gem::Version
104
96
  version: '0'
105
97
  requirements: []
106
98
  rubyforge_project:
107
- rubygems_version: 1.8.5
99
+ rubygems_version: 2.6.2
108
100
  signing_key:
109
- specification_version: 3
101
+ specification_version: 4
110
102
  summary: Calculates the haversine distance between two locations using longitude and
111
103
  latitude
112
- test_files:
113
- - spec/distance_spec.rb
114
- - spec/haversine_spec.rb
115
- - spec/spec_helper.rb
104
+ test_files: []
@@ -1,28 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.5.2)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- rake (0.9.0)
11
- rcov (0.9.9)
12
- rspec (2.4.0)
13
- rspec-core (~> 2.4.0)
14
- rspec-expectations (~> 2.4.0)
15
- rspec-mocks (~> 2.4.0)
16
- rspec-core (2.4.0)
17
- rspec-expectations (2.4.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.4.0)
20
-
21
- PLATFORMS
22
- ruby
23
-
24
- DEPENDENCIES
25
- bundler (~> 1.0.0)
26
- jeweler (~> 1.5.2)
27
- rcov
28
- rspec (>= 2.3.0)