vincenty 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37c0c0922bddbfdd5dcef8f791bfabdaa154392b34b87ae9a12211c2e3d97de6
4
- data.tar.gz: 3cf931671b138ab6552b90aafc9d483fce1fbe8329a46f4573526a1bd6c1d750
3
+ metadata.gz: d378b30cc2863c4fbdb032cf44473d75c2a5e479eb226e3e24d956a0c9a77e66
4
+ data.tar.gz: b3b552e6a59501707b76c848aa7e1fae795a2430d91d1f180c177b16a23bc604
5
5
  SHA512:
6
- metadata.gz: 416ffed90caaa6f501b3114585934fa406e212782075b3cabd38acebf9b7d15414dd05d17ce1d2032469c497ca8107d1c3238022a714f016801595ced91b9307
7
- data.tar.gz: d5f2ca7b476ffafc99da3a517e849ce3d6ccb05448c7565f586d6d2e92684c8c8ac7ed91241ce06b293abeb1566777af4f95c9c62be1abb0721a10102a096a4e
6
+ metadata.gz: 201e6694807048f2029f6b8779f70c9a068aace73ff8495fb29ee6cfda76de7e941bed8ca1e861e970d4e5c8ce67818554f4254ea5a4bb3aff86d2867afa86e0
7
+ data.tar.gz: f0770e50a4225648bd054bbfeb4bab51024452536456bb9b69c6244b516514be0c93ee9d80cb4960997464c036c073208413ceac0e1d8f4e9930942274121d9a
data/History.txt CHANGED
@@ -1,3 +1,11 @@
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
1
9
  robertburrowes Sun Oct 10 12:07:45 2021 +1300
2
10
  Inc version
3
11
  robertburrowes Sun Oct 10 12:05:54 2021 +1300
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.10'
15
+ VERSION = '1.0.11'
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.10
4
+ version: 1.0.11
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: 2021-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hoe-yard