geo_vectors 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -1,6 +1,6 @@
1
1
  h1. Geo Vectors
2
2
 
3
- Vector classes and operations for Geo calculations.
3
+ Vector classes and operations for performing various Geo calculations.
4
4
 
5
5
  h2. Install
6
6
 
@@ -24,30 +24,35 @@ A GeoVector can be any of:
24
24
  2) *direction vector* - direction (:N, :NW, :NE, :S, :SE, :SW, :E, :W) and a distance
25
25
  3) *point vector* - number of degrees due east/west (+ or -) and a distance due north/south (+ or -)
26
26
 
27
- Note that a direction vector is always converted to a bearing vector when added to a point
28
-
29
27
  A GeoVector can be applied to a GeoPoint (see geo_calc) or to another GeoVector.
30
- When multiple vectors are added together, the sum becomes a GeoVectors object.
31
- If a GeoVectors object is applied, the vectors are simply applied in turn.
28
+
29
+ h3. Multiple vectors
30
+
31
+ When multiple vectors are added (or grouped) together, the sum becomes a GeoVectors object except when PointVectors are added the result is a new PointVector.
32
+ When a GeoVectors object is applied (added or subtracted) to a GeoPoint instance, all the vectors are applied in succession to the geo point.
33
+ See the specs for more details on the API for a GeoVectors object.
32
34
 
33
35
  h2. Quick start (Usage guide)
34
36
 
35
- The following gives a quick overview for how to use the GeoVector API.
37
+ The following gives a quick overview on how to use the GeoVectors API.
36
38
 
37
- _Note: This is suggested functionality._
39
+ Note that using @[1, 2].vector@ and similar macros (core Ruby extensions), requires that you include the optional macros:
38
40
 
39
- I plan to use my recently published _geo_calc_ gem as the base for the functionality described here.
40
- I need a major cleanup up of the current code...
41
+ @require 'geo_vectors/macros'@
41
42
 
42
- h3. Addition
43
+ h3. Vector math
43
44
 
44
- Vectors can be added to form a new Vector, using the simple formula vec = v1 + v2 = (v1.x + v2.y, v1.x + v2.y)
45
+ *Vector on Vector addition*
45
46
 
46
- h3. Vector on Vector addition
47
+ If both vectors are point vectors, the result is simply a new point vector.
48
+ Point vectors can be added to form a new Point vector, using the simple formula
47
49
 
48
- If both vectors are point vectors, the result is simply a new point vector
50
+ @vec = v1 + v2 = (v1.x + v2.y, v1.x + v2.y)@
49
51
 
50
52
  <pre>
53
+ require 'geo_vectors'
54
+ require 'geo_vectors/macros'
55
+
51
56
  v1 = [1, 3].vector
52
57
  v2 = [-2, 2].vector
53
58
  vec = v1 + v2
@@ -59,7 +64,7 @@ If both vectors are point vectors, the result is simply a new point vector
59
64
  vec = v1 << v2
60
65
  </pre>
61
66
 
62
- h3. Vector subtraction
67
+ *Vector subtraction*
63
68
 
64
69
  <pre>
65
70
  v1 = [1, 3].vector
@@ -69,7 +74,7 @@ h3. Vector subtraction
69
74
  vec.lng.should == 2
70
75
  </pre>
71
76
 
72
- h3. Vector scaling
77
+ *Vector scaling*
73
78
 
74
79
  <pre>
75
80
  v1 = [1, 3].vector
@@ -78,25 +83,40 @@ h3. Vector scaling
78
83
  vec.lng.should == 6
79
84
  </pre>
80
85
 
81
- Scale a bearing vector
86
+ Other scale methods: #scale, #scale!
87
+
88
+ *Inverse scaling (reduction)*
82
89
 
83
90
  <pre>
84
- v1 = [32, 3.km].vector
91
+ v1 = [4, 2].vector
92
+ vec = v1 / 2
93
+ vec.lat.should == 2
94
+ vec.lng.should == 1
95
+ </pre>
96
+
97
+ You can also call #reduce to get the same effect
98
+
99
+ h2. Bearing vectors
100
+
101
+ *Vector scaling*
102
+
103
+ <pre>
104
+ v1 = [3.km, 32].vector
85
105
  vec = v1 * 2
86
106
  vec.bearing.should == 32
87
107
  vec.distance.should == 6.km
88
108
  </pre>
89
109
 
90
-
91
- Using division operator / for inverse scaling
110
+ *Generate random vector*
92
111
 
93
112
  <pre>
94
- v1 = [4, 2].vector
95
- vec = v1 / 2
96
- vec.lat.should == 2
97
- vec.lng.should == 1
113
+ v1 = [3.km, 32].vector
114
+ random_vec = v1.random_vector
115
+ random_vec.distance.number.should be_between(0, 3)
98
116
  </pre>
99
117
 
118
+ This can be used to generate a random point within a circle (i.e radius of a point).
119
+
100
120
  h3. GeoVectors
101
121
 
102
122
  Adding a point Vector to a bearing Vector
@@ -125,9 +145,9 @@ containing both vectors. A GeoVectors is a composite vector.
125
145
  p2 = p1 + vec # Add GeoVectors to the point
126
146
  </pre>
127
147
 
128
- h3. Vector on Point addition
148
+ h3. GeoPoint addition
129
149
 
130
- Add a point Vector to a GeoPoint
150
+ Add a Vector to a GeoPoint
131
151
 
132
152
  <pre>
133
153
  p1 = [1, 3].geo_point
@@ -137,7 +157,18 @@ Add a point Vector to a GeoPoint
137
157
  p2.lng.should == 5
138
158
  </pre>
139
159
 
140
- Add an inverse point Vector (subtract) to a GeoPoint
160
+ Other subtract methods: #add, #add!
161
+
162
+ <pre>
163
+ p1 = [1, 3].geo_point
164
+ p1.add!(-2, 2)
165
+ p1.lat.should == -1
166
+ p1.lng.should == 5
167
+ </pre>
168
+
169
+ h3. GeoPoint subtraction
170
+
171
+ Subtract a Vector from a GeoPoint
141
172
 
142
173
  <pre>
143
174
  p1 = [1, 3].geo_point
@@ -147,21 +178,26 @@ Add an inverse point Vector (subtract) to a GeoPoint
147
178
  p2.lng.should == 2
148
179
  </pre>
149
180
 
150
- Add a bearing Vector to a GeoPoint
181
+ Subtract a bearing Vector from a GeoPoint
151
182
 
152
183
  <pre>
153
184
  p1 = [1, 3].geo_point
154
185
 
155
186
  # 32 deg bearing, 2.km
156
187
  vec = [32, 2.km].vector
157
-
158
- # use #destination_point from 'geo_calc' project
159
- p2 = p1 + vec
188
+ p2 = p1 - vec
160
189
  </pre>
161
190
 
162
- Note: You can also subtract (add with inverse bearing direction)
191
+ Other subtract methods: #sub, #sub!
192
+
193
+ <pre>
194
+ p1 = [1, 3].geo_point
195
+ p1.sub!(2.km, 32)
196
+ p1.lat.should == -1
197
+ p1.lng.should == 5
198
+ </pre>
163
199
 
164
- h2. Contributing to geo_vectors
200
+ h2. Contributing to Geo Vectors
165
201
 
166
202
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
167
203
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
data/geo_vectors.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{geo_vectors}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
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}]
12
- s.date = %q{2011-05-23}
12
+ s.date = %q{2011-05-24}
13
13
  s.description = %q{Works with geo_calc and other geo libraries}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/geo_vectors/geo_point.rb",
34
34
  "lib/geo_vectors/geo_vector.rb",
35
35
  "lib/geo_vectors/geo_vectors.rb",
36
+ "lib/geo_vectors/macros.rb",
36
37
  "lib/geo_vectors/point_vector.rb",
37
38
  "lib/geo_vectors/point_vector/point_ops.rb",
38
39
  "lib/geo_vectors/point_vector/vector_ops.rb",
@@ -40,23 +41,27 @@ Gem::Specification.new do |s|
40
41
  "lib/geo_vectors/util/calc.rb",
41
42
  "lib/geo_vectors/util/geo_direction.rb",
42
43
  "lib/geo_vectors/util/geo_distance.rb",
44
+ "lib/geo_vectors/util/geo_distance/units.rb",
43
45
  "lib/geo_vectors/util/geo_units.rb",
44
46
  "lib/geo_vectors/vector_parser.rb",
45
- "spec/geo_vectors/API proposal guide.txt",
46
47
  "spec/geo_vectors/bearing_vector/add_vector_spec.rb",
48
+ "spec/geo_vectors/bearing_vector/point_add_spec.rb",
47
49
  "spec/geo_vectors/bearing_vector/random_spec.rb",
50
+ "spec/geo_vectors/bearing_vector/scale_spec.rb",
48
51
  "spec/geo_vectors/bearing_vector_spec.rb",
49
52
  "spec/geo_vectors/direction_vector/add_vector_spec.rb",
50
53
  "spec/geo_vectors/direction_vector/point_add_spec.rb",
51
54
  "spec/geo_vectors/direction_vector/random_spec.rb",
55
+ "spec/geo_vectors/direction_vector/scale_spec.rb",
52
56
  "spec/geo_vectors/direction_vector/subtract_vector_spec.rb",
53
57
  "spec/geo_vectors/direction_vector_spec.rb",
54
58
  "spec/geo_vectors/geo_vectors_spec.rb",
59
+ "spec/geo_vectors/macros_spec.rb",
55
60
  "spec/geo_vectors/point_vector/add_vector_spec.rb",
56
61
  "spec/geo_vectors/point_vector/initializer_spec.rb",
57
62
  "spec/geo_vectors/point_vector/point_add_spec.rb",
58
63
  "spec/geo_vectors/point_vector/random_spec.rb",
59
- "spec/geo_vectors/point_vector/scale_vector_spec.rb",
64
+ "spec/geo_vectors/point_vector/scale_spec.rb",
60
65
  "spec/geo_vectors/point_vector/subtract_vector_spec.rb",
61
66
  "spec/geo_vectors/point_vector_spec.rb",
62
67
  "spec/geo_vectors/util/geo_direction_spec.rb",
@@ -67,7 +72,7 @@ Gem::Specification.new do |s|
67
72
  s.homepage = %q{http://github.com/kristianmandrup/geo_vectors}
68
73
  s.licenses = [%q{MIT}]
69
74
  s.require_paths = [%q{lib}]
70
- s.rubygems_version = %q{1.8.0}
75
+ s.rubygems_version = %q{1.8.3}
71
76
  s.summary = %q{Geo vector library for applying vectors to GeoPoints and for basic vector math}
72
77
 
73
78
  if s.respond_to? :specification_version then
@@ -39,6 +39,7 @@ class BearingVector < GeoVector
39
39
 
40
40
  # normalize to within 0-360 degrees
41
41
  def bearing= brng
42
+ raise ArgumentError, "Not a valid bearing: #{brng}. Did you expect a DirectionVector?" if brng.kind_of? Symbol
42
43
  @bearing = brng.normalize_degrees
43
44
  end
44
45
 
@@ -8,47 +8,3 @@ class Float
8
8
  include GeoDistance::Unit
9
9
  end
10
10
 
11
- class GeoVector
12
- module Macros
13
- def point_vector
14
- PointVector.new self.geo_point
15
- end
16
- alias_method :vector, :point_vector
17
- alias_method :geo_vector, :point_vector
18
- alias_method :p_vector, :point_vector
19
- end
20
- end
21
-
22
- class GeoPoint
23
- include ::GeoVector::Macros
24
- end
25
-
26
- class Hash
27
- include GeoVector::Macros
28
- end
29
-
30
- class String
31
- include GeoVector::Macros
32
- end
33
-
34
- class Array
35
- include GeoVector::Macros
36
-
37
- def b_vector
38
- raise ArgumentException, "To create a BearingVector, the Array must contain at least 2 elements, one for bearing and oen for distance" if !(size >= 2)
39
- BearingVector.new self[0], self[1]
40
- end
41
- alias_method :bearing_vector, :b_vector
42
-
43
- def d_vector
44
- raise ArgumentException, "To create a DirectionVector, the Array must contain at least 2 elements, one for bearing and oen for distance" if !(size >= 2)
45
- raise ArgumentException, "The second element in the Array must be a Symbol defining the direction of the vector" if !self[1].kind_of?(Symbol)
46
- DirectionVector.new self[0], self[1]
47
- end
48
- alias_method :direction_vector, :d_vector
49
-
50
- def to_point
51
- geo_point
52
- end
53
- end
54
-
@@ -46,8 +46,6 @@ class GeoVector
46
46
  self.dup.scale! scalar
47
47
  end
48
48
  alias_method :*, :scale
49
- alias_method :enhance, :*
50
- alias_method :grow_by, :*
51
49
 
52
50
  def / scalar
53
51
  scale (1.0 / scalar)
@@ -0,0 +1,34 @@
1
+ class GeoVector
2
+ module Macros
3
+ def point_vector
4
+ PointVector.new self.geo_point
5
+ end
6
+ alias_method :geo_vector, :point_vector
7
+ alias_method :p_vector, :point_vector
8
+
9
+ def vector
10
+ GeoVector::Parser.create_vector *self
11
+ end
12
+ end
13
+ end
14
+
15
+ class GeoPoint
16
+ include ::GeoVector::Macros
17
+ end
18
+
19
+ class Hash
20
+ include GeoVector::Macros
21
+ end
22
+
23
+ class String
24
+ include GeoVector::Macros
25
+ end
26
+
27
+ class Array
28
+ include GeoVector::Macros
29
+
30
+ def to_point
31
+ geo_point
32
+ end
33
+ end
34
+
@@ -21,6 +21,10 @@ class PointVector < GeoVector
21
21
  end
22
22
  end
23
23
 
24
+ def self.origin
25
+ [0, 0].geo_point
26
+ end
27
+
24
28
  def direction
25
29
  brng = bearing
26
30
  begin
@@ -79,7 +83,7 @@ class PointVector < GeoVector
79
83
  end
80
84
 
81
85
  def origin
82
- [0, 0].geo_point
86
+ PointVector.origin
83
87
  end
84
88
  end
85
89
 
@@ -0,0 +1,29 @@
1
+ require 'active_support/inflector'
2
+
3
+ class GeoDistance
4
+ # used to extend Fixnum and Float
5
+ module Unit
6
+ extend GeoUnits
7
+ extend GeoUnits::UnitMaps
8
+
9
+ # from GeoUnits
10
+ valid_units.map(&:to_s).each do |unit|
11
+ one = unit.singularize
12
+ many = unit.pluralize
13
+ class_eval %{
14
+ def #{one}
15
+ GeoDistance.new self, :#{unit}
16
+ end
17
+ alias_method :to_#{unit}, :#{one}
18
+ alias_method :in_#{unit}, :#{one}
19
+ alias_method :as_#{unit}, :#{one}
20
+ alias_method :#{many}, :#{one}
21
+ }
22
+ end
23
+
24
+ def [] key
25
+ raise ArgumentError, "Invalid unit key #{key}" if !respond_to? key
26
+ earth_radius[key] * self
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  require 'geo_vectors/util/geo_units'
2
- require 'active_support/inflector'
2
+ require 'geo_vectors/util/geo_distance/units'
3
3
 
4
4
  class GeoDistance
5
5
  include NumericCheckExt
@@ -93,31 +93,6 @@ class GeoDistance
93
93
  is_numeric?(dist) ? dist.send(unit) : dist
94
94
  end
95
95
 
96
- # used to extend Fixnum and Float
97
- module Unit
98
- extend GeoUnits
99
- extend GeoUnits::UnitMaps
100
-
101
- # from GeoUnits
102
- valid_units.map(&:to_s).each do |unit|
103
- one_unit = unit.singularize
104
- class_eval %{
105
- def #{one_unit}
106
- GeoDistance.new self, :#{unit}
107
- end
108
- alias_method :to_#{unit}, :#{one_unit}
109
- alias_method :in_#{unit}, :#{one_unit}
110
- alias_method :as_#{unit}, :#{one_unit}
111
- alias_method :#{unit.pluralize}, :#{one_unit}
112
- }
113
- end
114
-
115
- def [] key
116
- raise ArgumentError, "Invalid unit key #{key}" if !respond_to? key
117
- earth_radius[key] * self
118
- end
119
- end
120
-
121
96
  module Extract
122
97
  def extract_distance dist
123
98
  case dist
@@ -49,5 +49,5 @@ module GeoUnits
49
49
  :radians => 111170
50
50
  }
51
51
  end
52
- end
52
+ end
53
53
  end
File without changes
@@ -4,7 +4,7 @@ describe GeoVector do
4
4
  describe 'Random module' do
5
5
  context 'Bearing vector 4.km at 52 deg' do
6
6
  describe '#random_vector' do
7
- let (:vec) { vec = [4.km, 52].b_vector }
7
+ let (:vec) { vec = [4.km, 52].vector }
8
8
 
9
9
  it 'should return a random vector of up to 4.kms with any bearing' do
10
10
  rvec = vec.random_vector
File without changes
@@ -1,10 +1,11 @@
1
1
  require 'spec_helper'
2
+ require 'geo_vectors/macros'
2
3
 
3
4
  describe GeoVector do
4
5
  describe 'Random module' do
5
6
  context 'Direction vector 4.km North' do
6
7
  describe '#random_vector' do
7
- let (:vec) { vec = [4.km, :north].d_vector }
8
+ let (:vec) { vec = [4.km, :north].vector }
8
9
 
9
10
  it 'should return a random vector of up to 4.kms in any direction' do
10
11
  rvec = vec.random_vector
File without changes
@@ -1,9 +1,10 @@
1
1
  require 'spec_helper'
2
+ require 'geo_vectors/macros'
2
3
 
3
4
  describe GeoVectors do
4
5
  context 'an GeoVectors containing a PointVector v1, and a BearingVector v2' do
5
6
  let (:v1) { [1, 2].vector }
6
- let (:v2) { [30, 4.km].b_vector }
7
+ let (:v2) { [30, 4.km].vector }
7
8
  let (:vecs) { GeoVectors.new v1, v2 }
8
9
  let (:point) { [3, 4].geo_point }
9
10
 
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+ require 'geo_vectors/macros'
3
+
4
+ describe 'Macros' do
5
+ describe 'Array macros' do
6
+ describe '#vector' do
7
+ it 'should create Point Vector from lat and lng' do
8
+ v = [2, 32].vector
9
+ v.should be_a PointVector
10
+ v.lat.should == 2
11
+ v.lng.should == 32
12
+ end
13
+ end
14
+
15
+ describe '#vector' do
16
+ it 'should create Direction Vector from distance and direction' do
17
+ v = [2.km, :north].vector
18
+ v.should be_a DirectionVector
19
+ v.distance.should == 2.km
20
+ v.direction.should == :N
21
+ end
22
+
23
+ it 'should create Bearing Vector from distance and degrees' do
24
+ v = [2.km, 32].vector
25
+ v.should be_a BearingVector
26
+ v.distance.should == 2.km
27
+ v.bearing.should == 32
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'Hash macros' do
33
+ describe '#point_vector' do
34
+ it 'should create Point Vector from lat and lng' do
35
+ v = {:lat => 2, :lng => 32}.point_vector
36
+ v.should be_a PointVector
37
+ v.lat.should == 2
38
+ v.lng.should == 32
39
+ end
40
+ end
41
+ end
42
+
43
+ describe 'String macros' do
44
+ describe '#point_vector' do
45
+ it 'should create Point Vector from lat and lng in String' do
46
+ v = "2, 32".point_vector
47
+ v.should be_a PointVector
48
+ v.lat.should == 2
49
+ v.lng.should == 32
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'GeoPoint macros' do
55
+ describe '#point_vector' do
56
+ it 'should create Point Vector from a GeoPoint' do
57
+ v = "2, 32".geo_point.point_vector
58
+ v.should be_a PointVector
59
+ v.lat.should == 2
60
+ v.lng.should == 32
61
+ end
62
+ end
63
+ end
64
+ end
@@ -44,52 +44,52 @@ describe PointVector do
44
44
  describe 'Vector on Vector Addition' do
45
45
  context 'Point vector (4, 2)' do
46
46
  describe '#+ operator' do
47
- let (:vec) { vec = [4, 2].vector }
47
+ let (:vec) { vec = PointVector.new 4, 2 }
48
48
 
49
49
  it 'should Add one geo vector' do
50
- v2 = vec + [1, 2].vector
50
+ v2 = vec + PointVector.new(1, 2)
51
51
  v2.lat.should == 5
52
52
  v2.lng.should == 4
53
53
  end
54
54
  end #+
55
55
 
56
- # describe '#add! operator' do
57
- # let (:vec) { vec = [4, 2].vector }
58
- #
59
- # it 'should Add one geo vector' do
60
- # vec.add!([1,2].vector)
61
- # vec.lng.should == 4
62
- # vec.lat.should == 5
63
- # end
64
- #
65
- # describe 'converting args to vector' do
66
- # let (:vec) { vec = [4, 2].vector }
67
- #
68
- # it 'should Add after converting number args to geo vector' do
69
- # vec.add!(1,2)
70
- # vec.lat.should == 5
71
- # vec.lng.should == 4
72
- # end
73
- #
74
- # it 'should Add one geo vector' do
75
- # vec.add!("1,2")
76
- # vec.lat.should == 5
77
- # vec.lng.should == 4
78
- # end
79
- # end # add!
80
- # end # point vector
56
+ describe '#add! operator' do
57
+ let (:vec) { vec = PointVector.new [4, 2] }
58
+
59
+ it 'should Add one geo vector' do
60
+ vec.add!( PointVector.new(1, 2))
61
+ vec.lng.should == 4
62
+ vec.lat.should == 5
63
+ end
64
+
65
+ describe 'converting args to vector' do
66
+ let (:vec) { vec = PointVector.new [4, 2] }
67
+
68
+ it 'should Add after converting number args to geo vector' do
69
+ vec.add!(1,2)
70
+ vec.lat.should == 5
71
+ vec.lng.should == 4
72
+ end
73
+
74
+ it 'should Add one geo vector' do
75
+ vec.add!("1,2")
76
+ vec.lat.should == 5
77
+ vec.lng.should == 4
78
+ end
79
+ end # add!
80
+ end # point vector
81
81
 
82
82
  describe '#add operator' do
83
- let (:vec) { vec = [4, 2].vector }
83
+ let (:vec) { vec = PointVector.new [4, 2] }
84
84
 
85
85
  it 'should Add one geo vector' do
86
- v2 = vec.add([1,2].vector)
86
+ v2 = vec.add(PointVector.new 1, 2)
87
87
  v2.lng.should == 4
88
88
  v2.lat.should == 5
89
89
  end
90
90
 
91
91
  describe 'converting args to vector' do
92
- let (:vec) { vec = [4, 2].vector }
92
+ let (:vec) { vec = PointVector.new [4, 2] }
93
93
 
94
94
  it 'should Add after converting number args to geo vector' do
95
95
  v2 = vec.add(1,2)
@@ -104,32 +104,31 @@ describe PointVector do
104
104
  end
105
105
  end # add!
106
106
  end # point vector
107
-
108
107
 
109
- # context 'Bearing vector (60, 2.km)' do
110
- # let(:vec) { vec = [4, 2].vector }
111
- # let(:brng_vec) { BearingVector.new 60, 2.km }
112
- #
113
- # describe '#add!' do
114
- # it 'should raise error when applying bearing vector directly on a point vector' do
115
- # lambda {vec.apply!(brng_vec)}.should raise_error
116
- # end
117
- # end
118
- #
119
- # describe '#+ (add)' do
120
- # it 'should add the vector and create a new PointVectors from result' do
121
- # vectors = vec + brng_vec
122
- # vectors.should be_a GeoVectors
123
- # end
124
- # end
125
- #
126
- # describe '#<< (push)' do
127
- # it 'should add the vector and create a new point from result' do
128
- # vectors = vec << brng_vec
129
- # vectors.should be_a GeoVectors
130
- # end
131
- # end
132
- # end
108
+ context 'Bearing vector (60, 2.km)' do
109
+ let(:vec) { vec = PointVector.new [4, 2] }
110
+ let(:brng_vec) { BearingVector.new 60, 2.km }
111
+
112
+ describe '#add!' do
113
+ it 'should raise error when applying bearing vector directly on a point vector' do
114
+ lambda {vec.apply!(brng_vec)}.should raise_error
115
+ end
116
+ end
117
+
118
+ describe '#+ (add)' do
119
+ it 'should add the vector and create a new PointVectors from result' do
120
+ vectors = vec + brng_vec
121
+ vectors.should be_a GeoVectors
122
+ end
123
+ end
124
+
125
+ describe '#<< (push)' do
126
+ it 'should add the vector and create a new point from result' do
127
+ vectors = vec << brng_vec
128
+ vectors.should be_a GeoVectors
129
+ end
130
+ end
131
+ end
133
132
  end
134
133
  end
135
134
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'geo_vectors/macros'
2
3
 
3
4
  describe PointVector do
4
5
  describe '#initialize' do
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'geo_vectors/macros'
2
3
 
3
4
  describe GeoVector do
4
5
  describe 'Random module' do
@@ -8,6 +8,7 @@
8
8
  # </pre>
9
9
 
10
10
  require 'spec_helper'
11
+ require 'geo_vectors/macros'
11
12
 
12
13
  describe PointVector do
13
14
  describe 'Scaling' do
@@ -25,6 +25,7 @@
25
25
  # </pre>
26
26
 
27
27
  require 'spec_helper'
28
+ require 'geo_vectors/macros'
28
29
 
29
30
  describe GeoVector do
30
31
  describe 'Vector on Vector Subtraction' do
@@ -1,14 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PointVector do
4
- describe '#initialize' do
5
- it 'should initialize from an Array' do
6
- vec = [1, 2].point_vector
7
- vec.should be_a PointVector
8
- end
9
-
4
+ describe '#initialize' do
10
5
  it 'should set origin at 0,0' do
11
- origin = [0, 0].geo_point
6
+ origin = PointVector.origin
12
7
  origin.lat.should == 0
13
8
  origin.lng.should == 0
14
9
  end
@@ -72,7 +67,7 @@ describe PointVector do
72
67
  end
73
68
 
74
69
  context 'Simple vector at (1, 2) - GeoPoint arg' do
75
- let(:vector) { PointVector.new [1, 2].to_point }
70
+ let(:vector) { PointVector.new [1, 2] }
76
71
 
77
72
  describe '#length' do
78
73
  it 'should have a distance between 240 - 250 km' do
@@ -91,7 +86,7 @@ describe PointVector do
91
86
 
92
87
  describe '#point=' do
93
88
  before do
94
- @vec = PointVector.new [1, 2].to_point
89
+ @vec = PointVector.new [1, 2]
95
90
  end
96
91
 
97
92
  it 'should set a new vector point of 2,3' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_vectors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-05-23 00:00:00.000000000Z
12
+ date: 2011-05-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: geo_calc
16
- requirement: &2160970420 !ruby/object:Gem::Requirement
16
+ requirement: &2155680100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.5.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2160970420
24
+ version_requirements: *2155680100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: proxy_party
27
- requirement: &2160969740 !ruby/object:Gem::Requirement
27
+ requirement: &2155679500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.2.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2160969740
35
+ version_requirements: *2155679500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sugar-high
38
- requirement: &2160969120 !ruby/object:Gem::Requirement
38
+ requirement: &2155678960 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.4.1
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2160969120
46
+ version_requirements: *2155678960
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2160968300 !ruby/object:Gem::Requirement
49
+ requirement: &2155667900 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.3.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2160968300
57
+ version_requirements: *2155667900
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &2160967640 !ruby/object:Gem::Requirement
60
+ requirement: &2155667380 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2160967640
68
+ version_requirements: *2155667380
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
- requirement: &2160967000 !ruby/object:Gem::Requirement
71
+ requirement: &2155666860 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.6.0
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2160967000
79
+ version_requirements: *2155666860
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rcov
82
- requirement: &2160966300 !ruby/object:Gem::Requirement
82
+ requirement: &2155666380 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2160966300
90
+ version_requirements: *2155666380
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: proxy_party
93
- requirement: &2160964320 !ruby/object:Gem::Requirement
93
+ requirement: &2155665900 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 0.2.1
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2160964320
101
+ version_requirements: *2155665900
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: sugar-high
104
- requirement: &2160963720 !ruby/object:Gem::Requirement
104
+ requirement: &2155665380 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 0.4.1
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2160963720
112
+ version_requirements: *2155665380
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: geo_calc
115
- requirement: &2160963160 !ruby/object:Gem::Requirement
115
+ requirement: &2155664900 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 0.5.4
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *2160963160
123
+ version_requirements: *2155664900
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rspec
126
- requirement: &2160962600 !ruby/object:Gem::Requirement
126
+ requirement: &2155664400 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,7 +131,7 @@ dependencies:
131
131
  version: 2.5.0
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2160962600
134
+ version_requirements: *2155664400
135
135
  description: Works with geo_calc and other geo libraries
136
136
  email: kmandrup@gmail.com
137
137
  executables: []
@@ -156,6 +156,7 @@ files:
156
156
  - lib/geo_vectors/geo_point.rb
157
157
  - lib/geo_vectors/geo_vector.rb
158
158
  - lib/geo_vectors/geo_vectors.rb
159
+ - lib/geo_vectors/macros.rb
159
160
  - lib/geo_vectors/point_vector.rb
160
161
  - lib/geo_vectors/point_vector/point_ops.rb
161
162
  - lib/geo_vectors/point_vector/vector_ops.rb
@@ -163,23 +164,27 @@ files:
163
164
  - lib/geo_vectors/util/calc.rb
164
165
  - lib/geo_vectors/util/geo_direction.rb
165
166
  - lib/geo_vectors/util/geo_distance.rb
167
+ - lib/geo_vectors/util/geo_distance/units.rb
166
168
  - lib/geo_vectors/util/geo_units.rb
167
169
  - lib/geo_vectors/vector_parser.rb
168
- - spec/geo_vectors/API proposal guide.txt
169
170
  - spec/geo_vectors/bearing_vector/add_vector_spec.rb
171
+ - spec/geo_vectors/bearing_vector/point_add_spec.rb
170
172
  - spec/geo_vectors/bearing_vector/random_spec.rb
173
+ - spec/geo_vectors/bearing_vector/scale_spec.rb
171
174
  - spec/geo_vectors/bearing_vector_spec.rb
172
175
  - spec/geo_vectors/direction_vector/add_vector_spec.rb
173
176
  - spec/geo_vectors/direction_vector/point_add_spec.rb
174
177
  - spec/geo_vectors/direction_vector/random_spec.rb
178
+ - spec/geo_vectors/direction_vector/scale_spec.rb
175
179
  - spec/geo_vectors/direction_vector/subtract_vector_spec.rb
176
180
  - spec/geo_vectors/direction_vector_spec.rb
177
181
  - spec/geo_vectors/geo_vectors_spec.rb
182
+ - spec/geo_vectors/macros_spec.rb
178
183
  - spec/geo_vectors/point_vector/add_vector_spec.rb
179
184
  - spec/geo_vectors/point_vector/initializer_spec.rb
180
185
  - spec/geo_vectors/point_vector/point_add_spec.rb
181
186
  - spec/geo_vectors/point_vector/random_spec.rb
182
- - spec/geo_vectors/point_vector/scale_vector_spec.rb
187
+ - spec/geo_vectors/point_vector/scale_spec.rb
183
188
  - spec/geo_vectors/point_vector/subtract_vector_spec.rb
184
189
  - spec/geo_vectors/point_vector_spec.rb
185
190
  - spec/geo_vectors/util/geo_direction_spec.rb
@@ -201,7 +206,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
206
  version: '0'
202
207
  segments:
203
208
  - 0
204
- hash: 893832234360665790
209
+ hash: 1380233325144833401
205
210
  required_rubygems_version: !ruby/object:Gem::Requirement
206
211
  none: false
207
212
  requirements:
@@ -210,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
215
  version: '0'
211
216
  requirements: []
212
217
  rubyforge_project:
213
- rubygems_version: 1.8.0
218
+ rubygems_version: 1.8.3
214
219
  signing_key:
215
220
  specification_version: 3
216
221
  summary: Geo vector library for applying vectors to GeoPoints and for basic vector
@@ -1,142 +0,0 @@
1
- h2. Intro
2
-
3
- A GeoVector can be any of:
4
-
5
- 1) *bearing vector* - bearing (direction in degrees) and a distance
6
- 2) *direction vector* - direction (:N, :NW, :NE, :S, :SE, :SW, :E, :W) and a distance
7
- 3) *point vector* - number of degrees due east/west (+ or -) and a distance due north/south (+ or -)
8
-
9
- Note that a direction vector is always converted to a bearing vector when added to a point
10
-
11
- A GeoVector can be applied to a GeoPoint (see geo_calc) or to another GeoVector.
12
- When multiple vectors are added together, the sum becomes a GeoVectors object.
13
- If a GeoVectors object is applied, the vectors are simply applied in turn.
14
-
15
- h2. Quick start (Usage guide)
16
-
17
- The following gives a quick overview for how to use the GeoVector API.
18
-
19
- _Note: This is suggested functionality._
20
-
21
- I plan to use my recently published _geo_calc_ gem as the base for the functionality described here.
22
- I need a major cleanup up of the current code...
23
-
24
- h3. Addition
25
-
26
- Vectors can be added to form a new Vector, using the simple formula vec = v1 + v2 = (v1.x + v2.y, v1.x + v2.y)
27
-
28
- h3. Vector on Vector addition
29
-
30
- If both vectors are point vectors, the result is simply a new point vector
31
-
32
- <pre>
33
- v1 = [1, 3].vector
34
- v2 = [-2, 2].vector
35
- vec = v1 + v2
36
- vec.unit.should == :degrees
37
- vec.lat.should == -1
38
- vec.lng.should == 5
39
-
40
- # alternative addition operators
41
- vec = v1 << v2
42
- </pre>
43
-
44
- h3. Vector subtraction
45
-
46
- <pre>
47
- v1 = [1, 3].vector
48
- v2 = [2, 1].vector
49
- vec = v1 - v2 # here v2 inversed (scaled by -1) and then added
50
- vec.lat.should == -1
51
- vec.lng.should == 2
52
- </pre>
53
-
54
- h3. Vector scaling
55
-
56
- <pre>
57
- v1 = [1, 3].vector
58
- vec = v1 * 2
59
- vec.lat.should == 2
60
- vec.lng.should == 6
61
- </pre>
62
-
63
- Scale a bearing vector
64
-
65
- <pre>
66
- v1 = [32, 3.km].vector
67
- vec = v1 * 2
68
- vec.bearing.should == 32
69
- vec.distance.should == 6.km
70
- </pre>
71
-
72
-
73
- Using division operator / for inverse scaling
74
-
75
- <pre>
76
- v1 = [4, 2].vector
77
- vec = v1 / 2
78
- vec.lat.should == 2
79
- vec.lng.should == 1
80
- </pre>
81
-
82
- h3. GeoVectors
83
-
84
- Adding a point Vector to a bearing Vector
85
-
86
- If the vectors are of different type, a GeoVectors object is created
87
- containing both vectors. A GeoVectors is a composite vector.
88
-
89
- <pre>
90
- p1 = [1, -1]
91
-
92
- v1 = [1, 3].vector # point Vector
93
-
94
- # 32 deg bearing, 2.km
95
- v2 = [32, 2.km].vector # bearing Vector
96
- v2.bearing.should == 32
97
- v2.distance.should == 2.km
98
-
99
- vec = v1 + v2 # create a GeoVectors object
100
- vec.should be_a(GeoVectors)
101
- vec.vectors.size.should == 2 # should contain 2 vectors
102
-
103
- # Adding more vectors to the GeoVectors object
104
- vec.vectors << v3
105
- vec << v4
106
-
107
- p2 = p1 + vec # Add GeoVectors to the point
108
- </pre>
109
-
110
- h3. Vector on Point addition
111
-
112
- Add a point Vector to a GeoPoint
113
-
114
- <pre>
115
- p1 = [1, 3].geo_point
116
- vec = [-2, 2].vector
117
- p2 = p1 + vec
118
- p2.lat.should == -1
119
- p2.lng.should == 5
120
- </pre>
121
-
122
- Add an inverse point Vector (subtract) to a GeoPoint
123
-
124
- <pre>
125
- p1 = [1, 3].geo_point
126
- vec = [2, 1].vector
127
- p2 = p1 - vec
128
- p2.lat.should == -1
129
- p2.lng.should == 2
130
- </pre>
131
-
132
- Add a bearing Vector to a GeoPoint
133
-
134
- <pre>
135
- p1 = [1, 3].geo_point
136
-
137
- # 32 deg bearing, 2.km
138
- vec = [32, 2.km].vector
139
-
140
- # use #destination_point from 'geo_calc' project
141
- p2 = p1 + vec
142
- </pre>