vincenty 1.0.8 → 1.0.9
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 +5 -5
- data/History.txt +16 -0
- data/README.md +3 -3
- data/Rakefile +20 -15
- data/lib/angle.rb +127 -134
- data/lib/coordinate.rb +8 -9
- data/lib/core_extensions.rb +47 -49
- data/lib/latitude.rb +20 -22
- data/lib/longitude.rb +11 -15
- data/lib/track_and_distance.rb +31 -32
- data/lib/vincenty.rb +110 -112
- data/test/ts_all.rb +1 -1
- data/test/ts_angle.rb +46 -45
- data/test/ts_coordinate.rb +4 -3
- data/test/ts_latitude.rb +8 -5
- data/test/ts_longitude.rb +8 -5
- data/test/ts_track_and_distance.rb +9 -9
- data/test/ts_vincenty.rb +53 -53
- metadata +12 -13
data/test/ts_all.rb
CHANGED
data/test/ts_angle.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
require 'test/unit'
|
2
3
|
require_relative '../lib/vincenty.rb'
|
3
4
|
|
4
|
-
class TestAngle< Test::Unit::TestCase
|
5
|
-
#test Angle creation
|
5
|
+
class TestAngle < Test::Unit::TestCase
|
6
|
+
# test Angle creation
|
6
7
|
def test_angle
|
7
|
-
assert_equal(Angle.new
|
8
|
-
assert_equal(Angle.new("S37 01'7.5\"").to_deg,
|
9
|
-
assert_equal(Angle.new("37 01'7.5\"S").to_deg
|
10
|
-
assert_equal(Angle.new("-37 01'7.5\"").to_deg,
|
11
|
-
assert_equal(Angle.new("-37 1.125'").to_deg, -37.01875) #Decimal minutes, rather than minutes and seconds.
|
12
|
-
assert_equal(Angle.new("-37 01'.125").to_deg, -37.01875) #Nb. the minute marker ' between the minutes and fraction
|
13
|
-
assert_equal(Angle.new("S37 01'.125").to_deg, -37.01875) #Nb. the minute marker ' between the minutes and fraction
|
14
|
-
assert_equal(Angle.new("37 01'.125S").to_deg, -37.01875) #Nb. the minute marker ' between the minutes and fraction
|
15
|
-
assert_equal(Angle.new(
|
16
|
-
assert_equal(Angle.new([-37, 1, 7.5]).to_deg,
|
8
|
+
assert_equal(Angle.new, 0)
|
9
|
+
assert_equal(Angle.new("S37 01'7.5\"").to_deg, -37.01875) # Leading NSEW
|
10
|
+
assert_equal(Angle.new("37 01'7.5\"S").to_deg, -37.01875) # Trailing NSEW
|
11
|
+
assert_equal(Angle.new("-37 01'7.5\"").to_deg, -37.01875) # Use of - rather than S or W
|
12
|
+
assert_equal(Angle.new("-37 1.125'").to_deg, -37.01875) # Decimal minutes, rather than minutes and seconds.
|
13
|
+
assert_equal(Angle.new("-37 01'.125").to_deg, -37.01875) # Nb. the minute marker ' between the minutes and fraction
|
14
|
+
assert_equal(Angle.new("S37 01'.125").to_deg, -37.01875) # Nb. the minute marker ' between the minutes and fraction
|
15
|
+
assert_equal(Angle.new("37 01'.125S").to_deg, -37.01875) # Nb. the minute marker ' between the minutes and fraction
|
16
|
+
assert_equal(Angle.new('-37.01875 ').to_deg, -37.01875) # decimal degrees, rather than deg, min, sec.
|
17
|
+
assert_equal(Angle.new([ -37, 1, 7.5 ]).to_deg, -37.01875) # an array of deg,min,sec
|
17
18
|
assert_equal(Angle.new(-37.01875).to_deg, -37.01875)
|
18
19
|
assert_equal(Angle.degrees(-37.01875).to_deg, -37.01875)
|
19
20
|
assert_equal(Angle.degrees(-37.01875).to_rad.round(15), -0.646099072472651)
|
@@ -21,61 +22,61 @@ class TestAngle< Test::Unit::TestCase
|
|
21
22
|
assert_equal(Angle.new(-0.646099072472651, true).to_rad, -0.646099072472651)
|
22
23
|
assert_equal(Angle.radians(-0.646099072472651).to_deg.round(5), -37.01875)
|
23
24
|
assert_equal(Angle.radians(-0.646099072472651).value, Angle.radians(-0.646099072472651).angle)
|
24
|
-
assert_equal(Angle.decimal_deg(1,2,3,'S'), -(1.0 + 2/60.0 + 3/3600.0))
|
25
|
-
assert_equal(Angle.decimal_deg(1,2,3,'E'), (1.0 + 2/60.0 + 3/3600.0))
|
26
|
-
assert_equal(Angle.decimal_deg(1,2,4,'N'), (1.0 + 2/60.0 + 4/3600.0))
|
27
|
-
assert_equal(Angle.decimal_deg(1,5,4,'W'), -(1.0 + 5/60.0 + 4/3600.0))
|
28
|
-
assert_equal(Angle.decimal_deg_from_ary([1,5,4,'W']), -(1.0 + 5/60.0 + 4/3600.0))
|
29
|
-
assert_equal(Angle.decimal_deg_from_ary(Angle.dms( -(1.0 + 5/60.0 + 1.0/3600.0) ))
|
25
|
+
assert_equal(Angle.decimal_deg(1, 2, 3, 'S'), -(1.0 + 2 / 60.0 + 3 / 3600.0))
|
26
|
+
assert_equal(Angle.decimal_deg(1, 2, 3, 'E'), (1.0 + 2 / 60.0 + 3 / 3600.0))
|
27
|
+
assert_equal(Angle.decimal_deg(1, 2, 4, 'N'), (1.0 + 2 / 60.0 + 4 / 3600.0))
|
28
|
+
assert_equal(Angle.decimal_deg(1, 5, 4, 'W'), -(1.0 + 5 / 60.0 + 4 / 3600.0))
|
29
|
+
assert_equal(Angle.decimal_deg_from_ary([ 1, 5, 4, 'W' ]), -(1.0 + 5 / 60.0 + 4 / 3600.0))
|
30
|
+
assert_equal(Angle.decimal_deg_from_ary(Angle.dms( -(1.0 + 5 / 60.0 + 1.0 / 3600.0) )), -(1.0 + 5 / 60.0 + 1.0 / 3600.0)) # double call, rounding error always produced a failure.
|
30
31
|
end
|
31
32
|
|
32
33
|
def test_strf
|
33
34
|
a = Angle.new("S37 01'7.5\"")
|
34
|
-
assert_equal("-37 01'07.5000\"", a.strf) #default format of strf
|
35
|
+
assert_equal("-37 01'07.5000\"", a.strf) # default format of strf
|
35
36
|
assert_equal("37 01'07.50000\"S", a.strf( "%d %2m'%2.5s\"%N" ))
|
36
37
|
assert_equal("37 01'07.50000\"W", a.strf("%d %2m'%2.5s\"%E" ))
|
37
38
|
assert_equal("-37 01'07.5000\"", a.strf("%d %2m'%2.4s\"" ))
|
38
39
|
assert_equal("-37 01.1250'\n", a.strf("%d %2.4M'\n" ))
|
39
|
-
assert_equal("*** -37 01'.1250", a.strf( "*** %d %2m'%4W" )) #puting the minute ' before decimal point.
|
40
|
-
assert_equal(
|
40
|
+
assert_equal("*** -37 01'.1250", a.strf( "*** %d %2m'%4W" )) # puting the minute ' before decimal point.
|
41
|
+
assert_equal('-37.01875 ', a.strf('%0.5D ' ))
|
41
42
|
assert_equal("-0.64610 radians\n", a.strf("%0.5r radians\n" ))
|
42
43
|
|
43
|
-
assert_equal("-037 01'7.5000\"", Angle.new("-37 01'7.5\"").to_s('%3d %2m\'%1.4s"')) #testing leading 0 with -deg, no leading 0 %s
|
44
|
-
assert_equal("00 01'07.5000\"S", Angle.new("0 01'7.5\"S").to_s('%2d %2m\'%2.4s"%N')) #testing 0 degrees and leading 0 %s
|
45
|
-
assert_equal("00 -01'07.5000\"", Angle.new("0 01'7.5\"S").to_s('%2d %2m\'%2.4s"')) #testing 0 degrees and -min
|
46
|
-
assert_equal("00 -01'07.5000\"", Angle.new("0 01'7.5\"S").to_s('%2d %2m\'%2.4s"') ) #test of 0 degrees, -min, no NSEW
|
47
|
-
assert_equal("000 00'07.5000\"W", Angle.new("0 0'7.5\"W").to_s('%3d %2m\'%2.4s"%E') ) #testing E W 0 deg and 0 min and -sec
|
48
|
-
assert_equal("00 00'-07.5000\"", Angle.new("0 0'7.5\"S").to_s('%2d %2m\'%2.4s"') ) #testing 0 deg and 0 min and -sec no NSEW
|
44
|
+
assert_equal("-037 01'7.5000\"", Angle.new("-37 01'7.5\"").to_s('%3d %2m\'%1.4s"')) # testing leading 0 with -deg, no leading 0 %s
|
45
|
+
assert_equal("00 01'07.5000\"S", Angle.new("0 01'7.5\"S").to_s('%2d %2m\'%2.4s"%N')) # testing 0 degrees and leading 0 %s
|
46
|
+
assert_equal("00 -01'07.5000\"", Angle.new("0 01'7.5\"S").to_s('%2d %2m\'%2.4s"')) # testing 0 degrees and -min
|
47
|
+
assert_equal("00 -01'07.5000\"", Angle.new("0 01'7.5\"S").to_s('%2d %2m\'%2.4s"') ) # test of 0 degrees, -min, no NSEW
|
48
|
+
assert_equal("000 00'07.5000\"W", Angle.new("0 0'7.5\"W").to_s('%3d %2m\'%2.4s"%E') ) # testing E W 0 deg and 0 min and -sec
|
49
|
+
assert_equal("00 00'-07.5000\"", Angle.new("0 0'7.5\"S").to_s('%2d %2m\'%2.4s"') ) # testing 0 deg and 0 min and -sec no NSEW
|
49
50
|
end
|
50
51
|
|
51
52
|
def test_operators
|
52
|
-
#Comparable.
|
53
|
-
assert_equal(Angle.radians(-0.646099072472651), Angle.radians(-0.646099072472651))
|
54
|
-
#unary-op Angle
|
55
|
-
assert_equal(+Angle.radians(-0.646099072472651), Angle.radians(-0.646099072472651)) #unary +
|
56
|
-
assert_equal(-Angle.radians(-0.646099072472651), Angle.radians(0.646099072472651)) #unary -
|
57
|
-
#Angle op Numeric
|
58
|
-
assert_equal(5, Angle.radians(2) +
|
59
|
-
assert_equal(-1, Angle.radians(2) -
|
60
|
-
assert_equal(6, Angle.radians(2) *
|
61
|
-
assert_equal(2, Angle.radians(4) /2) # /
|
53
|
+
# Comparable.
|
54
|
+
assert_equal(Angle.radians(-0.646099072472651), Angle.radians(-0.646099072472651)) # <=>
|
55
|
+
# unary-op Angle
|
56
|
+
assert_equal(+Angle.radians(-0.646099072472651), Angle.radians(-0.646099072472651)) # unary +
|
57
|
+
assert_equal(-Angle.radians(-0.646099072472651), Angle.radians(0.646099072472651)) # unary -
|
58
|
+
# Angle op Numeric
|
59
|
+
assert_equal(5, Angle.radians(2) + 3) # +
|
60
|
+
assert_equal(-1, Angle.radians(2) - 3) # -
|
61
|
+
assert_equal(6, Angle.radians(2) * 3) # *
|
62
|
+
assert_equal(2, Angle.radians(4) / 2) # /
|
62
63
|
assert_equal(1, Angle.radians(4) % 3) # %
|
63
|
-
assert_equal(64, Angle.radians(4)
|
64
|
-
#Numeric op Angle
|
64
|
+
assert_equal(64, Angle.radians(4)**3) # **
|
65
|
+
# Numeric op Angle
|
65
66
|
assert_equal(5.1, 3.1 + Angle.radians(2) ) # +
|
66
67
|
assert_equal(2.646099072472651, 2 - Angle.radians(-0.646099072472651) ) # -
|
67
68
|
assert_equal(6, 3 * Angle.radians(2) ) # *
|
68
69
|
assert_equal(2, 4 / Angle.radians(2) ) # /
|
69
|
-
#Angle op Angle
|
70
|
-
assert_equal(Angle.radians(3.2+2.1), Angle.radians(3.2) + Angle.radians(2.1) ) # +
|
71
|
-
#Sign method.
|
70
|
+
# Angle op Angle
|
71
|
+
assert_equal(Angle.radians(3.2 + 2.1), Angle.radians(3.2) + Angle.radians(2.1) ) # +
|
72
|
+
# Sign method.
|
72
73
|
assert_equal(1, Angle.radians(3).sign)
|
73
74
|
assert_equal(-1, Angle.radians(-3).sign)
|
74
|
-
#abs
|
75
|
+
# abs
|
75
76
|
assert_equal(3, Angle.radians(-3).abs)
|
76
|
-
#reverse
|
77
|
+
# reverse
|
77
78
|
assert_equal(Angle.degrees(90), Angle.degrees(270).reverse)
|
78
|
-
#bearing
|
79
|
+
# bearing
|
79
80
|
assert_equal(Angle.degrees(340), Angle.degrees(20).to_bearing)
|
80
81
|
end
|
81
82
|
end
|
data/test/ts_coordinate.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
require 'test/unit'
|
2
3
|
require_relative '../lib/vincenty.rb'
|
3
4
|
|
4
|
-
class TestCoordinate< Test::Unit::TestCase
|
5
|
-
#test Coordinate
|
5
|
+
class TestCoordinate < Test::Unit::TestCase
|
6
|
+
# test Coordinate
|
6
7
|
def test_coordinate
|
7
|
-
c = Coordinate.new(-36.9923293459124, 174.485341187381,13.5)
|
8
|
+
c = Coordinate.new(-36.9923293459124, 174.485341187381, 13.5)
|
8
9
|
ca = c.to_ary
|
9
10
|
assert_equal(-36.9923293459124, ca[0].to_deg)
|
10
11
|
assert_equal(174.485341187381, ca[1].to_deg)
|
data/test/ts_latitude.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
require 'test/unit'
|
2
3
|
require_relative '../lib/vincenty.rb'
|
3
4
|
|
4
|
-
class TestLatitude< Test::Unit::TestCase
|
5
|
+
class TestLatitude < Test::Unit::TestCase
|
5
6
|
def test_strf
|
6
7
|
assert_equal("37 01'07.5000\"S", Latitude.new("S37 01'7.5\"").to_s)
|
7
8
|
assert_equal("37 01'07.5000\"S", Latitude.new("-37 01'7.5\"").to_s)
|
@@ -10,12 +11,14 @@ class TestLatitude< Test::Unit::TestCase
|
|
10
11
|
assert_equal("37 01'07.5000\"N", Latitude.new("37 01'7.5\"").to_s)
|
11
12
|
assert_equal("37 01'07.5000\"N", Latitude.new("37 01'7.5\"N").to_s)
|
12
13
|
end
|
14
|
+
|
13
15
|
def test_to_radians
|
14
|
-
assert_equal(Math::PI/4, Latitude.degrees(45).to_rad)
|
15
|
-
assert_equal(Math::PI/4, Latitude.degrees(135).to_rad)
|
16
|
-
assert_equal(-Math::PI/4, Latitude.degrees(225).to_rad)
|
17
|
-
assert_equal(-Math::PI/4, Latitude.degrees(315).to_rad)
|
16
|
+
assert_equal(Math::PI / 4, Latitude.degrees(45).to_rad)
|
17
|
+
assert_equal(Math::PI / 4, Latitude.degrees(135).to_rad)
|
18
|
+
assert_equal(-Math::PI / 4, Latitude.degrees(225).to_rad)
|
19
|
+
assert_equal(-Math::PI / 4, Latitude.degrees(315).to_rad)
|
18
20
|
end
|
21
|
+
|
19
22
|
def test_to_degrees
|
20
23
|
assert_equal(45, Latitude.degrees(45).to_deg)
|
21
24
|
assert_equal(45, Latitude.degrees(135).to_deg)
|
data/test/ts_longitude.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
require 'test/unit'
|
2
3
|
require_relative '../lib/vincenty.rb'
|
3
4
|
|
4
|
-
class TestLongitude< Test::Unit::TestCase
|
5
|
+
class TestLongitude < Test::Unit::TestCase
|
5
6
|
def test_strf
|
6
7
|
assert_equal("037 01'07.5000\"W", Longitude.new("W37 01'7.5\"").to_s)
|
7
8
|
assert_equal("037 01'07.5000\"W", Longitude.new("-37 01'7.5\"").to_s)
|
@@ -10,12 +11,14 @@ class TestLongitude< Test::Unit::TestCase
|
|
10
11
|
assert_equal("037 01'07.5000\"E", Longitude.new("37 01'7.5\"").to_s)
|
11
12
|
assert_equal("037 01'07.5000\"E", Longitude.new("37 01'7.5\"E").to_s)
|
12
13
|
end
|
14
|
+
|
13
15
|
def test_to_radians
|
14
|
-
assert_equal(Math::PI/4, Longitude.degrees(45).to_rad)
|
15
|
-
assert_equal(3*Math::PI/4, Longitude.degrees(135).to_rad)
|
16
|
-
assert_equal(-3*Math::PI/4, Longitude.degrees(225).to_rad)
|
17
|
-
assert_equal(-Math::PI/4, Longitude.degrees(315).to_rad)
|
16
|
+
assert_equal(Math::PI / 4, Longitude.degrees(45).to_rad)
|
17
|
+
assert_equal(3 * Math::PI / 4, Longitude.degrees(135).to_rad)
|
18
|
+
assert_equal(-3 * Math::PI / 4, Longitude.degrees(225).to_rad)
|
19
|
+
assert_equal(-Math::PI / 4, Longitude.degrees(315).to_rad)
|
18
20
|
end
|
21
|
+
|
19
22
|
def test_to_degrees
|
20
23
|
assert_equal(45, Longitude.degrees(45).to_deg)
|
21
24
|
assert_equal(135, Longitude.degrees(135).to_deg)
|
@@ -1,19 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
require 'test/unit'
|
2
3
|
require_relative '../lib/vincenty.rb'
|
3
4
|
|
4
|
-
class TestTrackAndDistance< Test::Unit::TestCase
|
5
|
-
#test TrackAndDistance
|
5
|
+
class TestTrackAndDistance < Test::Unit::TestCase
|
6
|
+
# test TrackAndDistance
|
6
7
|
def test_track_and_distance
|
7
|
-
assert_equal("140 14'10.0000\" 12.0m", TrackAndDistance.new(Angle.new(
|
8
|
-
assert_equal("215 03'00.0000\" 19.73m", TrackAndDistance.new(
|
8
|
+
assert_equal("140 14'10.0000\" 12.0m", TrackAndDistance.new(Angle.new('320,14,10').reverse, 12.0).to_s)
|
9
|
+
assert_equal("215 03'00.0000\" 19.73m", TrackAndDistance.new('215,3,0', 19.73 ).to_s)
|
9
10
|
|
10
|
-
a = TrackAndDistance.new(
|
11
|
+
a = TrackAndDistance.new('215,3,0', 19.73 ).to_ary
|
11
12
|
assert_equal("215 03'00.0000\"", a[0].strf)
|
12
|
-
assert_equal(
|
13
|
+
assert_equal('19.73', a[1].to_s)
|
13
14
|
|
14
|
-
a = TrackAndDistance.new(
|
15
|
+
a = TrackAndDistance.new('215,3,0', 19.73 ).to_hash
|
15
16
|
assert_equal("215 03'00.0000\"", a[:bearing].strf)
|
16
|
-
assert_equal(
|
17
|
-
|
17
|
+
assert_equal('19.73', a[:distance].to_s)
|
18
18
|
end
|
19
19
|
end
|
data/test/ts_vincenty.rb
CHANGED
@@ -1,86 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
require 'test/unit'
|
2
3
|
require_relative '../lib/vincenty.rb'
|
3
4
|
|
4
|
-
class TestVincenty< Test::Unit::TestCase
|
5
|
-
|
5
|
+
class TestVincenty < Test::Unit::TestCase
|
6
6
|
def initialize(x)
|
7
7
|
super(x)
|
8
8
|
|
9
|
-
@path = [ #Path starting at peg by kanaka at end of drive
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
@path = [ # Path starting at peg by kanaka at end of drive
|
10
|
+
TrackAndDistance.new('215,3,0', 19.73 ),
|
11
|
+
TrackAndDistance.new(Angle.new('320,14,10').reverse, 12.0), # Note don't need to add the radians=true argument as Angle has to_radians function
|
12
|
+
TrackAndDistance.new(Angle.new('281,44,40').reverse, 35.23 ),
|
13
|
+
TrackAndDistance.new(Angle.new('247,24,0').reverse, 40.23 ),
|
14
|
+
TrackAndDistance.new(Angle.new('218,19,0').reverse, 378.98 ),
|
15
|
+
TrackAndDistance.new(Angle.new('158,25,0').reverse, 128.39 ),
|
16
|
+
TrackAndDistance.new(Angle.new('17,7,40').reverse, 122.41 ),
|
17
|
+
TrackAndDistance.new(Angle.new('51,1,0').reverse, 288.89 ),
|
18
|
+
TrackAndDistance.new('158,47,30', 61.78 ),
|
19
|
+
TrackAndDistance.new('189,16,10', 26.26 ),
|
20
|
+
TrackAndDistance.new('217,14,0', 21.87 )
|
21
21
|
]
|
22
22
|
|
23
23
|
@waypoints = [
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
24
|
+
Vincenty.new(-36.9923293459124, 174.485341187381),
|
25
|
+
Vincenty.new(-36.992412464006, 174.485427409127),
|
26
|
+
Vincenty.new(-36.9924770796644, 174.485814875954),
|
27
|
+
Vincenty.new(-36.9923377696042, 174.486232091137),
|
28
|
+
Vincenty.new(-36.9896584018239, 174.488871503953),
|
29
|
+
Vincenty.new(-36.988582616694, 174.488340992344),
|
30
|
+
Vincenty.new(-36.9896367145752, 174.487936042043),
|
31
|
+
Vincenty.new(-36.9912743090293, 174.48541348615),
|
32
|
+
Vincenty.new(-36.9917932943506, 174.485664544705),
|
33
|
+
Vincenty.new(-36.9920268289562, 174.485617028991),
|
34
|
+
Vincenty.new(-36.9921837292671, 174.485468381511)
|
35
35
|
]
|
36
36
|
end
|
37
37
|
|
38
|
-
#The path in @path was entered from the property survey map, with distance and bearings which should form a closed loop
|
39
|
-
#verified on google map of my property by creating a KML file and loading the map over the satellite image and checking the
|
40
|
-
#coordinates in google earth, and visually checking the route created was a closed loop (it was with a tiny error).
|
38
|
+
# The path in @path was entered from the property survey map, with distance and bearings which should form a closed loop
|
39
|
+
# verified on google map of my property by creating a KML file and loading the map over the satellite image and checking the
|
40
|
+
# coordinates in google earth, and visually checking the route created was a closed loop (it was with a tiny error).
|
41
41
|
def test_vincenty_destination
|
42
42
|
start = Vincenty.new(-36.9921838030711, 174.485468469841)
|
43
43
|
|
44
44
|
next_p = start
|
45
|
-
# print "Start at coordinate #{next_p.longitude.to_deg}, #{next_p.latitude.to_deg}\n"
|
46
|
-
@path.each_with_index do |leg,i|
|
47
|
-
|
45
|
+
# print "Start at coordinate #{next_p.longitude.to_deg}, #{next_p.latitude.to_deg}\n"
|
46
|
+
@path.each_with_index do |leg, i|
|
47
|
+
spherical_ans = next_p.sphereDestination(leg)
|
48
|
+
next_p = next_p.destination( leg )
|
48
49
|
|
49
50
|
assert_equal(@waypoints[i].longitude.to_deg.round(12), next_p.longitude.to_deg.round(12))
|
50
51
|
assert_equal(@waypoints[i].latitude.to_deg.round(12), next_p.latitude.to_deg.round(12))
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
# print "Expect #{waypoints[i].longitude.to_deg.round(4)}, #{waypoints[i].latitude.to_deg.round(4)}\n"
|
53
|
+
# print "Moved #{leg.bearing.to_deg.round(4)} #{leg.distance.round(4)}m to #{next_p.longitude.to_deg.round(4)}, #{next_p.latitude.to_deg.round(4)}\n"
|
54
|
+
# print "Spherical #{leg.bearing.to_deg.round(4)} #{leg.distance.round(4)}m to #{spherical_ans.longitude.to_deg.round(4)}, #{spherical_ans.latitude.to_deg.round(4)}\n"
|
55
|
+
# puts
|
55
56
|
end
|
56
|
-
|
57
|
-
|
57
|
+
# assert_equal(0, next_p.distanceAndAngle(start).distance)
|
58
|
+
# puts "distance from end to start should be 0. Actual #{next_p.distanceAndAngle(start)}"
|
58
59
|
end
|
59
60
|
|
60
|
-
#The waypoints are the latitudes and longitudes of the corners of my property.
|
61
|
-
#The resulting bearing and distances between them should match those in @path.
|
61
|
+
# The waypoints are the latitudes and longitudes of the corners of my property.
|
62
|
+
# The resulting bearing and distances between them should match those in @path.
|
62
63
|
def test_vincenty_distance_and_angle
|
63
64
|
start = Vincenty.new(-36.9921838030711, 174.485468469841)
|
64
65
|
next_p = start
|
65
|
-
# print "\nReverse test, c\n"
|
66
|
-
# print "Start at coordinate #{next_p.longitude.to_deg}, #{next_p.latitude.to_deg}\n"
|
67
|
-
@waypoints.each_with_index do |point,i|
|
66
|
+
# print "\nReverse test, c\n"
|
67
|
+
# print "Start at coordinate #{next_p.longitude.to_deg}, #{next_p.latitude.to_deg}\n"
|
68
|
+
@waypoints.each_with_index do |point, i|
|
68
69
|
vtrack_and_bearing = next_p.distanceAndAngle( point )
|
69
|
-
|
70
|
+
# strack_and_bearing = next_p.sphericalDistanceAndAngle( point )
|
70
71
|
|
71
72
|
assert_equal(@path[i].bearing.to_deg.round(4), vtrack_and_bearing.bearing.to_deg.round(4))
|
72
73
|
assert_equal(@path[i].distance.round(4), vtrack_and_bearing.distance.round(4))
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
# print "Expected #{path[i].bearing.to_deg.round(4)}(#{((path[i].bearing.to_deg+180)%360).round(4)}), #{path[i].distance.round(4)}m\n"
|
75
|
+
# print "WGS-84 track #{vtrack_and_bearing.bearing.to_deg.round(4)} #{vtrack_and_bearing.distance.round(4)}m from #{next_p.longitude.to_deg.round(4)}, #{next_p.latitude.to_deg.round(4)} to #{point.longitude.to_deg.round(4)}, #{point.latitude.to_deg.round(4)}\n"
|
76
|
+
# print "Spherical track #{strack_and_bearing.bearing.to_deg.round(4)} #{strack_and_bearing.distance.round(4)}m from #{next_p.longitude.to_deg.round(4)}, #{next_p.latitude.to_deg.round(4)} to #{point.longitude.to_deg.round(4)}, #{point.latitude.to_deg.round(4)}\n"
|
77
|
+
# puts
|
77
78
|
next_p = point
|
78
79
|
end
|
79
|
-
|
80
|
-
|
80
|
+
# assert_equal(0, next_p.distanceAndAngle(start).distance)
|
81
|
+
# puts "distance from end to start should be 0. Actual #{next_p.distanceAndAngle(start)}\n"
|
81
82
|
end
|
82
83
|
|
83
|
-
#Edge case, when points are at same location
|
84
|
+
# Edge case, when points are at same location
|
84
85
|
def test_vincenty_distance_and_angle_when_0
|
85
86
|
start = Vincenty.new(-36.9921838030711, 174.485468469841)
|
86
87
|
vtrack_and_bearing = start.distanceAndAngle( start )
|
@@ -89,10 +90,10 @@ class TestVincenty< Test::Unit::TestCase
|
|
89
90
|
assert_equal(0, vtrack_and_bearing.distance.round(4))
|
90
91
|
end
|
91
92
|
|
92
|
-
#Run the Australian Geoscience site example.
|
93
|
+
# Run the Australian Geoscience site example.
|
93
94
|
def test_geoscience_au
|
94
95
|
flindersPeak = Vincenty.new("-37 57'3.72030″", "144 25'29.52440″" )
|
95
|
-
buninyong = Vincenty.new("-37 39 ' 10.15610 ''", "143 55 ' 35.38390 ''") #Buninyong
|
96
|
+
buninyong = Vincenty.new("-37 39 ' 10.15610 ''", "143 55 ' 35.38390 ''") # Buninyong
|
96
97
|
track_and_bearing = flindersPeak.distanceAndAngle( buninyong )
|
97
98
|
assert_equal(Angle.new("306 52 ' 5.37 ''").to_deg.round(4), track_and_bearing.bearing.to_deg.round(4))
|
98
99
|
assert_equal(54972.271, track_and_bearing.distance.round(3))
|
@@ -101,5 +102,4 @@ class TestVincenty< Test::Unit::TestCase
|
|
101
102
|
assert_equal(buninyong.latitude.to_deg.round(4), destination.latitude.to_deg.round(4))
|
102
103
|
assert_equal(buninyong.longitude.to_deg.round(4), destination.longitude.to_deg.round(4))
|
103
104
|
end
|
104
|
-
|
105
105
|
end
|
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.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Burrowes
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hoe-yard
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.3
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: hoe
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.23'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.23'
|
41
41
|
description: "* Vincenty wrote an algorithm for calculating the bearing and distance
|
42
42
|
between two coordinates on the earth\n and an algorithm for finding a second coordinate,
|
43
43
|
given a starting coordinate, bearing and destination.\n The algorithms model the
|
@@ -88,17 +88,17 @@ files:
|
|
88
88
|
- test/ts_longitude.rb
|
89
89
|
- test/ts_track_and_distance.rb
|
90
90
|
- test/ts_vincenty.rb
|
91
|
-
homepage: http://rbur004.github.
|
91
|
+
homepage: http://rbur004.github.io/vincenty/
|
92
92
|
licenses:
|
93
93
|
- MIT
|
94
94
|
metadata: {}
|
95
|
-
post_install_message:
|
95
|
+
post_install_message:
|
96
96
|
rdoc_options:
|
97
97
|
- "--markup"
|
98
98
|
- markdown
|
99
99
|
- "--protected"
|
100
100
|
- "--title"
|
101
|
-
-
|
101
|
+
- vincenty
|
102
102
|
- "--quiet"
|
103
103
|
require_paths:
|
104
104
|
- lib
|
@@ -113,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
|
-
|
117
|
-
|
118
|
-
signing_key:
|
116
|
+
rubygems_version: 3.2.22
|
117
|
+
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
summary: "* Vincenty wrote an algorithm for calculating the bearing and distance between
|
121
120
|
two coordinates on the earth and an algorithm for finding a second coordinate, given
|