File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3428,7 +3428,10 @@ class Alt
34283428
34293429 # Regular expression LOC Alt must match.
34303430
3431- Regex = /^([+-]*\d +\. *\d *)[m]$/
3431+ Regex = /\A ([+-]?0*\d {1,8}(?:\. \d +)?)m\z /
3432+
3433+ # Bias to a base of 100,000m below the WGS 84 reference spheroid.
3434+ Bias = 100_000_00
34323435
34333436 ##
34343437 # Creates a new LOC::Alt from +arg+ which may be:
@@ -3444,8 +3447,11 @@ def self.create(arg)
34443447 unless Regex =~ arg
34453448 raise ArgumentError . new ( "not a properly formed Alt string: " + arg )
34463449 end
3447- altitude = [ ( $1. to_f *( 1e2 ) ) +( 1e7 ) ] . pack ( "N" )
3448- return Alt . new ( altitude )
3450+ altitude = ( $1. to_f * 100 ) . to_i + Bias
3451+ unless ( 0 ...0x1_0000_0000 ) === altitude
3452+ raise ArgumentError . new ( "out of raise as Alt: #{ arg } " )
3453+ end
3454+ return new ( [ altitude ] . pack ( "N" ) )
34493455 else
34503456 raise ArgumentError . new ( "cannot interpret as Alt: #{ arg . inspect } " )
34513457 end
Original file line number Diff line number Diff line change @@ -75,6 +75,27 @@ def test_coord
7575 assert_equal ( [ coordinate ] . pack ( "N" ) , coord . coordinates )
7676 assert_equal ( coord , Resolv ::LOC ::Coord . create ( coord . to_s ) )
7777 end
78+
79+ def test_alt
80+ assert_alt ( "0.0m" , 0 )
81+ assert_alt ( "+0.0m" , 0 )
82+ assert_alt ( "-0.0m" , 0 )
83+ assert_alt ( "+0.01m" , 1 )
84+ assert_alt ( "1.0m" , 100 )
85+ assert_alt ( "+1.0m" , 100 )
86+ assert_alt ( "100000.0m" , +10000000 )
87+ assert_alt ( "+100000.0m" , +10000000 )
88+ assert_alt ( "-100000.0m" , -10000000 )
89+ assert_alt ( "+42849672.95m" , 0xffff_ffff -100_000_00 )
90+ assert_raise ( ArgumentError ) { Resolv ::LOC ::Alt . create ( "-100000.01m" ) }
91+ assert_raise ( ArgumentError ) { Resolv ::LOC ::Alt . create ( "+42849672.96m" ) }
92+ end
93+
94+ private def assert_alt ( input , altitude )
95+ alt = Resolv ::LOC ::Alt . create ( input )
96+
97+ assert_equal ( [ altitude + 1e7 ] . pack ( "N" ) , alt . altitude )
98+ end
7899end
79100
80101class TestResolvResourceCAA < Test ::Unit ::TestCase
You can’t perform that action at this time.
0 commit comments