Class: Latitude
Overview
Subclass of Angle to add in special treatment of to_d, to_r , to_s Latitude degrees are between -PI and PI, South to North (+/- 90 degrees)
Instance Attribute Summary
Attributes inherited from Angle
Instance Method Summary collapse
-
#to_degrees ⇒ Float
(also: #to_deg)
Angle as degrees in range -90 and 90.
-
#to_radians ⇒ Float
(also: #to_r, #to_rad)
Angle as degrees in range -PI and PI.
-
#to_s(fmt = "%2d %2m'%2.4s\"%N") ⇒ String
A South angle is negative, North is Positive.
Methods inherited from Angle
#%, #*, #**, #+, #+@, #-, #-@, #/, #<=>, #abs, #coerce, decimal_deg, decimal_deg_from_ary, degrees, dms, #initialize, radians, #reverse, #sign, #strf, #to_bearing, #to_dms, #to_i
Constructor Details
This class inherits a constructor from Angle
Instance Method Details
#to_degrees ⇒ Float Also known as: to_deg
Returns angle as degrees in range -90 and 90.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/latitude.rb', line 7 def to_degrees degrees = super if degrees > 270 -(360 - degrees) elsif degrees > 180 || degrees > 90 || degrees < -90 180 - degrees else degrees end end |
#to_radians ⇒ Float Also known as: to_r, to_rad
Returns angle as degrees in range -PI and PI.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/latitude.rb', line 19 def to_radians if @angle > 3 * Math::PI / 2 @angle - Math::PI * 2 elsif @angle > Math::PI || @angle > Math::PI / 2 Math::PI - @angle elsif @angle < -Math::PI / 2 -Math::PI - @angle else @angle end end |
#to_s(fmt = "%2d %2m'%2.4s\"%N") ⇒ String
A South angle is negative, North is Positive.
34 35 36 |
# File 'lib/latitude.rb', line 34 def to_s(fmt = "%2d %2m'%2.4s\"%N") super(fmt) end |