vincenty 1.0.9 → 1.0.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8c6ea3c3470ff15da8327c1d3a0094a3f3c4b1c8d0796a38b9fd6218a61673c
4
- data.tar.gz: 9a648f496428a4c1cf42ae6fcf2d3fdf595c40da7db73bea862e147998d8eded
3
+ metadata.gz: d8da3071ee96be2492c012b7cadd49fa3138b83fc94082a8884fd802daae1812
4
+ data.tar.gz: dd77a978fc6e6c48f68e5f502521b70e34433e923d67b7efa7d133102a0ffc8f
5
5
  SHA512:
6
- metadata.gz: c9839e6de4ac0d516d29577d6bd0d4594c8967bb793bc19e202c75ee03fd5c1e50e543888ad32e3915324307c11d01e8c7ade41793c811e2e3c99bf48fab519e
7
- data.tar.gz: f6ba931e58dc2835d24a8f1a604fac8c14d70c409f4d8667fd0c5ce16b47a9a138f45b816cbb337a0294de0e07a6a763af9f79d646a72d01e854a5c34270b7e1
6
+ metadata.gz: 3f3a482610d9613ba8223fe40faae17bca233dad29d1c44586a1f42e40a9f413881015c988228d4cac7d1ed0e6453acacf81861b68a15b428d77f86b30d849d0
7
+ data.tar.gz: 0fc65c74e71f91c4be148c6c2bde7ae01ba3f45cc00b0fcb64a5e9d5f96c3850dc9d6d1754e0ba18af38c1f54ed3184f88e1c9129cf72daa75ff4883b93df874
data/History.txt CHANGED
@@ -1,3 +1,17 @@
1
+ robertburrowes Thu Oct 14 15:09:23 2021 +1300
2
+ bumped version
3
+ robertburrowes Thu Oct 14 15:06:18 2021 +1300
4
+ Bump version.
5
+ robertburrowes Thu Oct 14 14:43:00 2021 +1300
6
+ Bearing 0 and 180 edgecase for spherical test method resulted in negative sqrt
7
+ robertburrowes Sun Oct 10 12:09:10 2021 +1300
8
+ #{PROJECT} release 1.0.10
9
+ robertburrowes Sun Oct 10 12:07:45 2021 +1300
10
+ Inc version
11
+ robertburrowes Sun Oct 10 12:05:54 2021 +1300
12
+ removed Float.round, as ruby now does this. removed to_r, as it is now defined in the core ruby libraries, with a different meaning
13
+ robertburrowes Sun Oct 10 11:44:09 2021 +1300
14
+ Chmod, adding world readable
1
15
  robertburrowes Sun Oct 10 11:39:21 2021 +1300
2
16
  Bump Version, after removing stray '.'
3
17
  robertburrowes Fri Oct 8 16:32:19 2021 +1300
data/lib/angle.rb CHANGED
@@ -141,26 +141,26 @@ class Angle
141
141
  # @return [Angle,self]
142
142
  # @param [Angle,Numeric] angle
143
143
  def **(other)
144
- self.class.radians(@angle**other)
144
+ return self.class.radians(@angle**other)
145
145
  end
146
146
 
147
147
  # Binary division operator. Can add angles and numbers, or two angles.
148
148
  # @return [Angle,self]
149
149
  # @param [Angle,Numeric] angle
150
150
  def /(other)
151
- self.class.radians(@angle / other)
151
+ return self.class.radians(@angle / other)
152
152
  end
153
153
 
154
154
  # Binary mod operator. Can add angles and numbers, or two angles.
155
155
  # @return [Angle,self]
156
156
  # @param [Angle,Numeric] angle
157
157
  def %(other)
158
- self.class.radians(@angle % other)
158
+ return self.class.radians(@angle % other)
159
159
  end
160
160
 
161
161
  # @return [Float] angle in degrees
162
162
  def to_degrees
163
- @angle.to_degrees
163
+ return @angle.to_degrees
164
164
  end
165
165
 
166
166
  # @return [Float] angle in degrees
@@ -169,7 +169,7 @@ class Angle
169
169
 
170
170
  # @return [Float] angle in radians
171
171
  def to_radians
172
- @angle
172
+ return @angle
173
173
  end
174
174
 
175
175
  alias to_rad to_radians
@@ -205,7 +205,7 @@ class Angle
205
205
 
206
206
  # @return [Fixnum] the angle truncated to an integer, in radians.
207
207
  def to_i
208
- to_radians.to_i
208
+ return to_radians.to_i
209
209
  end
210
210
 
211
211
  # @return [Fixnum] the angle truncated to an integer, in radians.
@@ -214,23 +214,23 @@ class Angle
214
214
  # @return [Array] the angle parameter as a Float and the @angle parameter from this class.
215
215
  # @param [Numeric] angle
216
216
  def coerce(angle)
217
- [ Float(angle), @angle ]
217
+ return [ Float(angle), @angle ]
218
218
  end
219
219
 
220
220
  # @return [Fixnum] the sign of the angle. 1 for positive, -1 for negative.
221
221
  def sign
222
- @angle.sign
222
+ return @angle.sign
223
223
  end
224
224
 
225
225
  # @return [Float] the absolute angle of the angle in radians
226
226
  def abs
227
- @angle.abs
227
+ return @angle.abs
228
228
  end
229
229
 
230
230
  # @return [Float] angle as compass bearing in radians.
231
231
  # Compass bearings are clockwise, Math angles are counter clockwise.
232
232
  def to_bearing
233
- self.class.new((Math::PI * 2) - @angle, true)
233
+ return self.class.new((Math::PI * 2) - @angle, true)
234
234
  end
235
235
 
236
236
  # @return [Float] the reverse angle in radians. i.e. angle + PI (or angle + 180 degrees)
data/lib/coordinate.rb CHANGED
@@ -33,4 +33,7 @@ class Coordinate
33
33
  def to_hash
34
34
  { latitude: @latitude, longitude: @longitude, altitude: @altitude }
35
35
  end
36
+
37
+ alias deconstruct_keys to_hash
38
+ alias deconstruct to_ary
36
39
  end
@@ -25,7 +25,6 @@ class Numeric
25
25
  end
26
26
  end
27
27
 
28
- alias to_r to_radians
29
28
  alias to_rad to_radians
30
29
  alias to_deg to_degrees
31
30
 
@@ -35,25 +34,6 @@ class Numeric
35
34
  end
36
35
  end
37
36
 
38
- # Alters round method to have an optional number of decimal places.
39
- class Float
40
- # Replace default round, so we can reference it later.
41
- # @return [Float]
42
- alias round0 round
43
-
44
- # Compatible Replacement for Float.round
45
- # @return [Float] float rounded to n decimal places.
46
- # @param [Numeric] n Optional argument n is the number of decimal places to round to.
47
- def round(n = 0)
48
- if n == 0
49
- self.round0 # This is to preserve the default behaviour, which is to return a Fixnum, not a float.
50
- else
51
- m = 10.0**n
52
- (self * m).round0 / m
53
- end
54
- end
55
- end
56
-
57
37
  # Extends String to to_dec_degrees, add to_r and to_d
58
38
  class String
59
39
  # string expected to be degrees, returns decimal degrees.
@@ -93,6 +73,5 @@ class String
93
73
  end
94
74
 
95
75
  alias to_rad to_radians
96
- alias to_r to_radians
97
76
  alias to_deg to_degrees
98
77
  end
@@ -37,4 +37,7 @@ class TrackAndDistance
37
37
  def to_hash
38
38
  return { bearing: @bearing, distance: @distance }
39
39
  end
40
+
41
+ alias deconstruct_keys to_hash
42
+ alias deconstruct to_ary
40
43
  end
data/lib/vincenty.rb CHANGED
@@ -12,7 +12,7 @@ require_relative 'coordinate.rb'
12
12
  # Modified to incorporate corrections to formulae as found in script on http://www.movable-type.co.uk/scripts/LatLongVincenty.html
13
13
  # Added my Modification of the distanceAndAngle formulae to correct the compass bearing.
14
14
  class Vincenty < Coordinate
15
- VERSION = '1.0.9'
15
+ VERSION = '1.0.12'
16
16
 
17
17
  # @return [String] constant VERSION
18
18
  def version
@@ -30,13 +30,11 @@ class Vincenty < Coordinate
30
30
  # @param [Coordinate] p2 is target coordinate that we want the bearing to.
31
31
  # @return [TrackAndDistance] with the compass bearing and distance in meters to P2
32
32
  def sphericalDistanceAndAngle( p2, equatorial_radius = WGS84_ER, inverse_flattening = WGS84_IF )
33
- if self.latitude == p2.latitude && self.longitude == p2.longitude
34
- return TrackAndDistance.new(0, 0, true) # No calculations necessary
35
- end
33
+ # No calculations necessary, if these are the same point.
34
+ return TrackAndDistance.new(0, 0, true) if @latitude == p2.latitude && @longitude == p2.longitude
36
35
 
37
36
  a = equatorial_radius # equatorial radius in meters (+/-2 m)
38
- f = inverse_flattening
39
- b = a - a / f # WGS84 = 6356752.314245179 polar radius in meters
37
+ b = a - a / inverse_flattening # WGS84 = 6356752.314245179 polar radius in meters
40
38
  r = (a + b) / 2 # average diametre as a rough estimate for our tests.
41
39
 
42
40
  sin_lat1 = Math.sin(@latitude.to_rad)
@@ -45,9 +43,11 @@ class Vincenty < Coordinate
45
43
  atan1_2 = Math.atan(1) * 2
46
44
  t1 = cos_lat1 * Math.cos(p2.latitude.to_rad) * Math.cos(@longitude.to_rad - p2.longitude.to_rad) + sin_lat1 * sin_lat2
47
45
  angular_distance = Math.atan(-t1 / Math.sqrt(-t1 * t1 + 1)) + atan1_2 # central angle in radians so we can calculate the arc length.
48
-
49
46
  t2 = (sin_lat2 - sin_lat1 * Math.cos(angular_distance)) / (cos_lat1 * Math.sin(angular_distance))
50
- bearing = if Math.sin(p2.longitude.to_rad - @longitude.to_rad) < 0
47
+
48
+ bearing = if @longitude == p2.longitude
49
+ @latitude > p2.latitude ? Math::PI : 0
50
+ elsif Math.sin(p2.longitude.to_rad - @longitude.to_rad) < 0
51
51
  2 * Math::PI - (Math.atan(-t2 / Math.sqrt(-t2 * t2 + 1)) + atan1_2) # Compass Bearing in radians (clockwise)
52
52
  else
53
53
  Math.atan(-t2 / Math.sqrt(-t2 * t2 + 1)) + atan1_2 # Compass Bearing in radians (clockwise)
data/test/ts_vincenty.rb CHANGED
@@ -90,6 +90,36 @@ class TestVincenty < Test::Unit::TestCase
90
90
  assert_equal(0, vtrack_and_bearing.distance.round(4))
91
91
  end
92
92
 
93
+ # Edge case, when points are close, and 180 degrees
94
+ def test_vincenty_angle_when_180
95
+ start_track = Vincenty.new(-36.98684848301985, 174.4873448681314)
96
+ end_track = Vincenty.new(-36.989952870042174, 174.4873448681314)
97
+
98
+ vtrack_and_bearing = start_track.distanceAndAngle( end_track )
99
+ assert_equal(180.0, vtrack_and_bearing.bearing.to_deg.round(4))
100
+
101
+ vtrack_and_bearing = end_track.distanceAndAngle( start_track )
102
+ assert_equal(0.0, vtrack_and_bearing.bearing.to_deg.round(4))
103
+ end
104
+
105
+ # Edge case, when points are close, and 180 degrees
106
+ def test_spherical_angle_when_180
107
+ start_track = Vincenty.new(-36.98684848301985, 174.4873448681314)
108
+ end_track = Vincenty.new(-36.989952870042174, 174.4873448681314)
109
+
110
+ vtrack_and_bearing = start_track.sphericalDistanceAndAngle( end_track )
111
+ assert_equal(180.0, vtrack_and_bearing.bearing.to_deg.round(4))
112
+ end
113
+
114
+ #Edgecase when points are close and 0 degress
115
+ def test_spherical_angle_when_0
116
+ start_track = Vincenty.new(-36.98684848301985, 174.4873448681314)
117
+ end_track = Vincenty.new(-36.989952870042174, 174.4873448681314)
118
+
119
+ vtrack_and_bearing = end_track.sphericalDistanceAndAngle( start_track )
120
+ assert_equal(0.0, vtrack_and_bearing.bearing.to_deg.round(4))
121
+ end
122
+
93
123
  # Run the Australian Geoscience site example.
94
124
  def test_geoscience_au
95
125
  flindersPeak = Vincenty.new("-37 57'3.72030″", "144 25'29.52440″" )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vincenty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Burrowes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-09 00:00:00.000000000 Z
11
+ date: 2022-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hoe-yard
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.2.22
116
+ rubygems_version: 3.3.7
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: "* Vincenty wrote an algorithm for calculating the bearing and distance between