geo_vectors 0.5.0
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.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Distance calc notes.txt +64 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.textile +178 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/geo_vectors.gemspec +115 -0
- data/lib/geo_vectors.rb +7 -0
- data/lib/geo_vectors/bearing_vector.rb +87 -0
- data/lib/geo_vectors/core_ext.rb +54 -0
- data/lib/geo_vectors/direction_vector.rb +59 -0
- data/lib/geo_vectors/geo_point.rb +33 -0
- data/lib/geo_vectors/geo_vector.rb +56 -0
- data/lib/geo_vectors/geo_vectors.rb +92 -0
- data/lib/geo_vectors/point_vector.rb +85 -0
- data/lib/geo_vectors/point_vector/point_ops.rb +23 -0
- data/lib/geo_vectors/point_vector/vector_ops.rb +38 -0
- data/lib/geo_vectors/util.rb +3 -0
- data/lib/geo_vectors/util/calc.rb +89 -0
- data/lib/geo_vectors/util/geo_direction.rb +101 -0
- data/lib/geo_vectors/util/geo_distance.rb +135 -0
- data/lib/geo_vectors/util/geo_units.rb +53 -0
- data/lib/geo_vectors/vector_parser.rb +54 -0
- data/spec/geo_vectors/API proposal guide.txt +142 -0
- data/spec/geo_vectors/bearing_vector/add_vector_spec.rb +30 -0
- data/spec/geo_vectors/bearing_vector/random_spec.rb +18 -0
- data/spec/geo_vectors/bearing_vector_spec.rb +34 -0
- data/spec/geo_vectors/direction_vector/add_vector_spec.rb +30 -0
- data/spec/geo_vectors/direction_vector/point_add_spec.rb +0 -0
- data/spec/geo_vectors/direction_vector/random_spec.rb +16 -0
- data/spec/geo_vectors/direction_vector/subtract_vector_spec.rb +0 -0
- data/spec/geo_vectors/direction_vector_spec.rb +27 -0
- data/spec/geo_vectors/geo_vectors_spec.rb +108 -0
- data/spec/geo_vectors/point_vector/add_vector_spec.rb +135 -0
- data/spec/geo_vectors/point_vector/initializer_spec.rb +82 -0
- data/spec/geo_vectors/point_vector/point_add_spec.rb +45 -0
- data/spec/geo_vectors/point_vector/random_spec.rb +17 -0
- data/spec/geo_vectors/point_vector/scale_vector_spec.rb +52 -0
- data/spec/geo_vectors/point_vector/subtract_vector_spec.rb +80 -0
- data/spec/geo_vectors/point_vector_spec.rb +111 -0
- data/spec/geo_vectors/util/geo_direction_spec.rb +74 -0
- data/spec/geo_vectors/util/geo_distance_spec.rb +70 -0
- data/spec/geo_vectors/util/geo_units_spec.rb +23 -0
- data/spec/spec_helper.rb +7 -0
- metadata +218 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class GeoDirectionClass
|
4
|
+
extend GeoDirection
|
5
|
+
end
|
6
|
+
|
7
|
+
class Fixnum
|
8
|
+
def kms
|
9
|
+
self * 1000
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe GeoDirection do
|
14
|
+
describe 'module methods' do
|
15
|
+
before do
|
16
|
+
@gd = GeoDirectionClass
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#valid_directions?' do
|
20
|
+
it 'should list valid directions' do
|
21
|
+
@gd.valid_directions.should include(:N, :south)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should be that :km is a valid direction' do
|
25
|
+
@gd.valid_direction? :km
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#dir_to_bearing' do
|
29
|
+
it 'should convert North to 90 deg' do
|
30
|
+
@gd.dir_to_bearing(:N).should == 90
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise error on invalid direction' do
|
34
|
+
lambda { @gd.dir_to_bearing(:Sud) }.should raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#bearing_to_dir' do
|
39
|
+
it 'should convert 90 deg to North' do
|
40
|
+
@gd.bearing_to_dir(90).should == :N
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should raise error bearing that has no direction symbol' do
|
44
|
+
lambda { @gd.bearing_to_dir(100) }.should raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#to_bearing_vector' do
|
49
|
+
it 'should direction and distance to a bearing vector' do
|
50
|
+
bvec = @gd.to_bearing_vector(:N, 2.km)
|
51
|
+
bvec.should be_a(BearingVector)
|
52
|
+
bvec.bearing.should == 90
|
53
|
+
bvec.distance.unit == :kms
|
54
|
+
bvec.distance.in_meters.should == 2000
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#to_bearing_vector' do
|
59
|
+
it 'should direction and distance to a bearing vector' do
|
60
|
+
pvec = @gd.to_point_vector(:E, 2.kms)
|
61
|
+
pvec.should be_a(PointVector)
|
62
|
+
pvec.lng.should > 0
|
63
|
+
pvec.lat.should == 0 # y
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#get_valid_dir' do
|
68
|
+
it 'should convert :north to :N' do
|
69
|
+
@gd.get_valid_direction(:north).should == :N
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'geo_vectors'
|
3
|
+
|
4
|
+
describe GeoDistance do
|
5
|
+
describe 'Unit' do
|
6
|
+
it 'should NOT convert 5.blips into a GeoDistance obj' do
|
7
|
+
lambda {5.blips}.should raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should convert 5.km into a GeoDistance obj' do
|
11
|
+
dist = 5.km
|
12
|
+
dist.should be_a GeoDistance
|
13
|
+
dist.unit.should == :kms
|
14
|
+
dist.number.should == 5
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'Distance' do
|
19
|
+
describe '#* multiply operator' do
|
20
|
+
it "should multiply and return a new distance" do
|
21
|
+
dist = 5.km
|
22
|
+
new_dist = dist * 2
|
23
|
+
new_dist.number.should == 5 * 2
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#/ divide operator' do
|
28
|
+
it "should divide and return a new distance" do
|
29
|
+
dist = 10.km
|
30
|
+
new_dist = dist / 2
|
31
|
+
new_dist.number.should == 5
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#> gte operator' do
|
36
|
+
it "should be that twice the distance is greater than original distance" do
|
37
|
+
20.km.should > 10.km
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should be that half the distance is smaller than original distance" do
|
41
|
+
5.km.should < 10.km
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should be that 1000 m is same distance as 1 km" do
|
45
|
+
(1000.meters == 1.km).should be_true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#in_meters' do
|
50
|
+
it "should be that 5.km in meters is 5000" do
|
51
|
+
5.km.in_meters.should == 5000
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#random' do
|
56
|
+
it "should be that a 5.km random distance is between 0 - 5000 meters" do
|
57
|
+
rand_dist = 5.km.random
|
58
|
+
rand_dist.in_meters.should be_between(0, 5000)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#in_kms' do
|
63
|
+
it "should be that 5000 meters in kms is 5" do
|
64
|
+
dist = 5000.meters
|
65
|
+
dist.should be_a GeoDistance
|
66
|
+
dist.in_kms.should == 5
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class GeoUnitClass
|
4
|
+
extend GeoUnits
|
5
|
+
end
|
6
|
+
|
7
|
+
describe GeoUnits do
|
8
|
+
describe 'module methods' do
|
9
|
+
before do
|
10
|
+
@gu = GeoUnitClass
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#valid_units?' do
|
14
|
+
it 'should list valid units' do
|
15
|
+
@gu.valid_units.should include(:kms, :meters)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should be that :km is a valid unit' do
|
19
|
+
@gu.valid_unit? :km
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geo_vectors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kristian Mandrup
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-05-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: geo_calc
|
16
|
+
requirement: &2160970420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.5.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2160970420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: proxy_party
|
27
|
+
requirement: &2160969740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.2.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2160969740
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sugar-high
|
38
|
+
requirement: &2160969120 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.4.1
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2160969120
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2160968300 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.3.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2160968300
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: bundler
|
60
|
+
requirement: &2160967640 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.0.0
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2160967640
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: &2160967000 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.6.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2160967000
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rcov
|
82
|
+
requirement: &2160966300 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2160966300
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: proxy_party
|
93
|
+
requirement: &2160964320 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.2.1
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2160964320
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: sugar-high
|
104
|
+
requirement: &2160963720 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.4.1
|
110
|
+
type: :runtime
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *2160963720
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: geo_calc
|
115
|
+
requirement: &2160963160 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ! '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 0.5.4
|
121
|
+
type: :runtime
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *2160963160
|
124
|
+
- !ruby/object:Gem::Dependency
|
125
|
+
name: rspec
|
126
|
+
requirement: &2160962600 !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.5.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: *2160962600
|
135
|
+
description: Works with geo_calc and other geo libraries
|
136
|
+
email: kmandrup@gmail.com
|
137
|
+
executables: []
|
138
|
+
extensions: []
|
139
|
+
extra_rdoc_files:
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.textile
|
142
|
+
files:
|
143
|
+
- .document
|
144
|
+
- .rspec
|
145
|
+
- Distance calc notes.txt
|
146
|
+
- Gemfile
|
147
|
+
- LICENSE.txt
|
148
|
+
- README.textile
|
149
|
+
- Rakefile
|
150
|
+
- VERSION
|
151
|
+
- geo_vectors.gemspec
|
152
|
+
- lib/geo_vectors.rb
|
153
|
+
- lib/geo_vectors/bearing_vector.rb
|
154
|
+
- lib/geo_vectors/core_ext.rb
|
155
|
+
- lib/geo_vectors/direction_vector.rb
|
156
|
+
- lib/geo_vectors/geo_point.rb
|
157
|
+
- lib/geo_vectors/geo_vector.rb
|
158
|
+
- lib/geo_vectors/geo_vectors.rb
|
159
|
+
- lib/geo_vectors/point_vector.rb
|
160
|
+
- lib/geo_vectors/point_vector/point_ops.rb
|
161
|
+
- lib/geo_vectors/point_vector/vector_ops.rb
|
162
|
+
- lib/geo_vectors/util.rb
|
163
|
+
- lib/geo_vectors/util/calc.rb
|
164
|
+
- lib/geo_vectors/util/geo_direction.rb
|
165
|
+
- lib/geo_vectors/util/geo_distance.rb
|
166
|
+
- lib/geo_vectors/util/geo_units.rb
|
167
|
+
- lib/geo_vectors/vector_parser.rb
|
168
|
+
- spec/geo_vectors/API proposal guide.txt
|
169
|
+
- spec/geo_vectors/bearing_vector/add_vector_spec.rb
|
170
|
+
- spec/geo_vectors/bearing_vector/random_spec.rb
|
171
|
+
- spec/geo_vectors/bearing_vector_spec.rb
|
172
|
+
- spec/geo_vectors/direction_vector/add_vector_spec.rb
|
173
|
+
- spec/geo_vectors/direction_vector/point_add_spec.rb
|
174
|
+
- spec/geo_vectors/direction_vector/random_spec.rb
|
175
|
+
- spec/geo_vectors/direction_vector/subtract_vector_spec.rb
|
176
|
+
- spec/geo_vectors/direction_vector_spec.rb
|
177
|
+
- spec/geo_vectors/geo_vectors_spec.rb
|
178
|
+
- spec/geo_vectors/point_vector/add_vector_spec.rb
|
179
|
+
- spec/geo_vectors/point_vector/initializer_spec.rb
|
180
|
+
- spec/geo_vectors/point_vector/point_add_spec.rb
|
181
|
+
- spec/geo_vectors/point_vector/random_spec.rb
|
182
|
+
- spec/geo_vectors/point_vector/scale_vector_spec.rb
|
183
|
+
- spec/geo_vectors/point_vector/subtract_vector_spec.rb
|
184
|
+
- spec/geo_vectors/point_vector_spec.rb
|
185
|
+
- spec/geo_vectors/util/geo_direction_spec.rb
|
186
|
+
- spec/geo_vectors/util/geo_distance_spec.rb
|
187
|
+
- spec/geo_vectors/util/geo_units_spec.rb
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
homepage: http://github.com/kristianmandrup/geo_vectors
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
post_install_message:
|
193
|
+
rdoc_options: []
|
194
|
+
require_paths:
|
195
|
+
- lib
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
197
|
+
none: false
|
198
|
+
requirements:
|
199
|
+
- - ! '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
segments:
|
203
|
+
- 0
|
204
|
+
hash: 893832234360665790
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
|
+
none: false
|
207
|
+
requirements:
|
208
|
+
- - ! '>='
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0'
|
211
|
+
requirements: []
|
212
|
+
rubyforge_project:
|
213
|
+
rubygems_version: 1.8.0
|
214
|
+
signing_key:
|
215
|
+
specification_version: 3
|
216
|
+
summary: Geo vector library for applying vectors to GeoPoints and for basic vector
|
217
|
+
math
|
218
|
+
test_files: []
|