geo-distance2 0.2.1

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.
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe "GeoDistance core extensions" do
4
+
5
+ describe 'unit_to(other)' do
6
+ describe '#radians_to' do
7
+ it 'should convert radians to kms' do
8
+ 5.radians_to(:kms).should be_within(2).of 556
9
+ end
10
+ end
11
+
12
+ describe '#kms_to' do
13
+ it 'should convert radians to kms' do
14
+ 5.kms_to(:feet).should be_within(1000).of 16000
15
+ end
16
+ end
17
+ end
18
+
19
+ describe '#radians' do
20
+ it 'should convert Fixnum to GeoDistance' do
21
+ 5.radians.should be_a GeoDistance
22
+ 5.radians.distance.should == 5
23
+ 5.radians.unit.should == :radians
24
+ 5.radians.as_kms.should be_within(2).of 556
25
+ end
26
+ end
27
+
28
+ describe '#kms' do
29
+ it 'should convert Fixnum to GeoDistance' do
30
+ 5.kms.should be_a GeoDistance
31
+ 5.kms.distance.should == 5
32
+ 5.kms.unit.should == :kms
33
+ end
34
+ end
35
+
36
+ describe '#kms' do
37
+ it 'should convert Float to GeoDistance' do
38
+ 5.2.kms.should be_a GeoDistance
39
+ 5.2.kms.distance.should == 5.2
40
+ 5.2.kms.unit.should == :kms
41
+ end
42
+ end
43
+
44
+ describe '#meters' do
45
+ it 'should convert Float to GeoDistance' do
46
+ 5.2.meters.should be_a GeoDistance
47
+ 5.2.meters.distance.should == 5.2
48
+ 5.2.meters.unit.should == :meters
49
+ end
50
+ end
51
+
52
+ describe '#meter' do
53
+ it 'should convert Float to GeoDistance' do
54
+ 2.meter.should be_a GeoDistance
55
+ 5.2.meter.distance.should == 5.2
56
+ 5.2.meter.unit.should == :meters
57
+ end
58
+ end
59
+
60
+ describe '#to_radians' do
61
+ it 'should convert degrees to radians' do
62
+ 180.to_radians.should be_within(0.1).of 3.14159274
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoDistance do
4
+
5
+ describe 'initialize' do
6
+ describe 'Numeric macro' do
7
+ it 'should create distance from number' do
8
+ 500.kms.should be_a(GeoDistance)
9
+ 500.kms.unit.should == :kms
10
+ 500.kms.units.should == :kms
11
+ 500.kms.distance.should == 500
12
+ end
13
+ end
14
+ end
15
+
16
+ context '500 kms' do
17
+ let(:distance) { 500.kms }
18
+
19
+ describe 'comparable' do
20
+ it '52 kms is less than 52500 meters' do
21
+ 52.kms.should < (52.thousand + 500.hundred).meters
22
+ end
23
+ end
24
+
25
+ describe '#meters' do
26
+ it 'should be in meters' do
27
+ distance.meters.should == 500.thousand
28
+ end
29
+ end
30
+
31
+ describe '#in_meters' do
32
+ it 'should be in meters' do
33
+ distance.in_meters.should == 500.thousand
34
+ end
35
+ end
36
+
37
+ describe '#as_meters' do
38
+ it 'should be in meters' do
39
+ distance.as_meters.should == 500.thousand
40
+ end
41
+ end
42
+
43
+ describe '#as_meters!' do
44
+ it 'should be in meters' do
45
+ dist = distance.as_meters!
46
+ dist.should == distance
47
+ dist.distance.should == 500.thousand
48
+ end
49
+ end
50
+
51
+ describe '#to_meters!' do
52
+ it 'should be in meters' do
53
+ dist = distance.to_meters!
54
+ dist.should == distance
55
+ dist.distance.should == 500.thousand
56
+ end
57
+ end
58
+
59
+ describe '#feet' do
60
+ it 'should be in feet' do
61
+ distance.feet.should be_within(10.thousand).of(500.thousand * 3.3)
62
+ end
63
+ end
64
+
65
+ describe '#to_feet' do
66
+ it 'should return new GeoDistance converted to feet' do
67
+ new_dist = distance.to_feet
68
+ new_dist.should_not == distance
69
+
70
+ new_dist.distance.should be_within(10.thousand).of(500.thousand * 3.3)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoDistance::Flat do
4
+ let(:from) do
5
+ [45, 10].geo_point
6
+ end
7
+
8
+ let(:to) do
9
+ b = [42, 11].geo_point
10
+ end
11
+
12
+ describe '#distance' do
13
+ it "should calculate flat distance as Float" do
14
+ dist = GeoDistance::Flat.distance(from, to, :units => :kms)
15
+ dist.should be_a(Float)
16
+
17
+ puts "the distance from #{from} to #{to} is: #{dist.kms_to(:meters)} meters"
18
+ dist.should be_within(10).of 340
19
+ end
20
+ end
21
+
22
+ describe '#geo_distance' do
23
+ it "should calculate haversine distance as GeoDistance" do
24
+ dist = GeoDistance::Flat.geo_distance(from, to)
25
+ dist.should be_a(GeoDistance)
26
+
27
+ # puts "the distance from #{from} to #{to} is: #{dist.meters} meters"
28
+ dist.kms.should be_within(10).of 340
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoDistance::Haversine do
4
+ let(:from) do
5
+ [45, 10].geo_point
6
+ end
7
+
8
+ let(:to) do
9
+ b = [42, 11].geo_point
10
+ end
11
+
12
+ describe '#distance' do
13
+ it "should calculate haversine distance as Float" do
14
+ dist = GeoDistance::Haversine.distance(from, to)
15
+
16
+ dist.should be_a(Float)
17
+
18
+ puts "the distance from #{from} to #{to} is: #{dist.kms_to(:meters)} meters"
19
+ dist.should be_within(20).of 340
20
+ end
21
+ end
22
+
23
+ describe '#geo_distance' do
24
+ it "should calculate haversine distance as GeoDistance" do
25
+ dist = GeoDistance::Haversine.geo_distance(from, to)
26
+ dist.should be_a(GeoDistance)
27
+
28
+ puts "the distance from #{from} to #{to} is: #{dist.meters} meters"
29
+
30
+ dist.kms.should be_within(20).of 340
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoDistance::NVector do
4
+ let(:from) do
5
+ [45, 10].geo_point
6
+ end
7
+
8
+ let(:to) do
9
+ b = [42, 11].geo_point
10
+ end
11
+
12
+ describe '#distance' do
13
+ it "should calculate N-vector distance as Float" do
14
+ dist = GeoDistance::NVector.distance(from, to)
15
+
16
+ dist.should be_a(Float)
17
+
18
+ puts "the distance from #{from} to #{to} is: #{dist.kms_to(:meters)} meters"
19
+ dist.should be_within(20).of 340
20
+ end
21
+ end
22
+
23
+ describe '#geo_distance' do
24
+ it "should calculate N-vector distance as GeoDistance" do
25
+ dist = GeoDistance::NVector.geo_distance(from, to)
26
+ dist.should be_a(GeoDistance)
27
+
28
+ puts "the distance from #{from} to #{to} is: #{dist.meters} meters"
29
+
30
+ dist.kms.should be_within(20).of 340
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoDistance::Spherical do
4
+ let(:from) do
5
+ [45, 10].geo_point
6
+ end
7
+
8
+ let(:to) do
9
+ b = [42, 11].geo_point
10
+ end
11
+
12
+ describe '#distance' do
13
+ it "should calculate spherical distance as Float" do
14
+ dist = GeoDistance::Spherical.distance(from, to)
15
+
16
+ dist.should be_a(Float)
17
+
18
+ puts "the distance from #{from} to #{to} is: #{dist.kms_to(:meters)} meters"
19
+ dist.should be_within(20).of 340
20
+ end
21
+ end
22
+
23
+ describe '#geo_distance' do
24
+ it "should calculate spherical distance as GeoDistance" do
25
+ dist = GeoDistance::Spherical.geo_distance(from, to)
26
+ dist.should be_a(GeoDistance)
27
+
28
+ puts "the distance from #{from} to #{to} is: #{dist.meters} meters"
29
+
30
+ dist.kms.should be_within(20).of 340
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe GeoDistance::Vincenty do
4
+ let(:from) do
5
+ [45, 10].geo_point
6
+ end
7
+
8
+ let(:to) do
9
+ b = [42, 11].geo_point
10
+ end
11
+
12
+ describe '#distance' do
13
+ it "should calculate vincenty distance as Float" do
14
+ dist = GeoDistance::Vincenty.distance(from, to)
15
+
16
+ dist.should be_a(Float)
17
+
18
+ puts "the distance from #{from} to #{to} is: #{dist.kms_to(:meters)} meters"
19
+ dist.should be_within(20).of 340
20
+ end
21
+ end
22
+
23
+ describe '#geo_distance' do
24
+ it "should calculate vincenty distance as GeoDistance" do
25
+ dist = GeoDistance::Vincenty.geo_distance(from, to)
26
+ dist.should be_a(GeoDistance)
27
+
28
+ puts "the distance from #{from} to #{to} is: #{dist.meters} meters"
29
+
30
+ dist.kms.should be_within(20).of 340
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec'
2
+ require 'geo-distance'
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geo-distance2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Francois Oligny-Lemieux
8
+ - Kristian Mandrup
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: geo_point
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.2.5
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.2.5
28
+ - !ruby/object:Gem::Dependency
29
+ name: geo_units
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.2.4.1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.2.4.1
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 2.6.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.6.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.10
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.10
70
+ - !ruby/object:Gem::Dependency
71
+ name: jeweler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.6.2
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 1.6.2
84
+ - !ruby/object:Gem::Dependency
85
+ name: rcov
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: "Calculates the geo distance between two locations using longitude and
99
+ latitude using Haversine, Speherical or Vincenty formula. \nThis is done using Math
100
+ formulas without resorting to Active Record or SQL DB functionality"
101
+ email: frank.quebec@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files:
105
+ - LICENSE.txt
106
+ - README.textile
107
+ files:
108
+ - ".document"
109
+ - ".rspec"
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.textile
114
+ - Rakefile
115
+ - VERSION
116
+ - geo-distance.gemspec
117
+ - lib/geo-distance.rb
118
+ - lib/geo-distance/class_methods.rb
119
+ - lib/geo-distance/conversion.rb
120
+ - lib/geo-distance/conversion/meters.rb
121
+ - lib/geo-distance/conversion/radians.rb
122
+ - lib/geo-distance/core_ext.rb
123
+ - lib/geo-distance/distance.rb
124
+ - lib/geo-distance/formula.rb
125
+ - lib/geo-distance/formula/flat.rb
126
+ - lib/geo-distance/formula/haversine.rb
127
+ - lib/geo-distance/formula/n_vector.rb
128
+ - lib/geo-distance/formula/spherical.rb
129
+ - lib/geo-distance/formula/vincenty.rb
130
+ - lib/geo-distance/scale.rb
131
+ - spec/geo_distance/class_methods_spec.rb
132
+ - spec/geo_distance/core_ext_spec.rb
133
+ - spec/geo_distance/distance_spec.rb
134
+ - spec/geo_distance/formula/flat_spec.rb
135
+ - spec/geo_distance/formula/haversine_spec.rb
136
+ - spec/geo_distance/formula/n_vector.rb
137
+ - spec/geo_distance/formula/spherical_spec.rb
138
+ - spec/geo_distance/formula/vincenty_spec.rb
139
+ - spec/spec_helper.rb
140
+ homepage: http://github.com/olignyf/geo-distance2
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.4.5
161
+ signing_key:
162
+ specification_version: 3
163
+ summary: Calculates the geo distance between two locations using longitude and latitude,
164
+ using Haversine, Speherical or Vincenty formula
165
+ test_files: []