Class: Longitude

Inherits:
Angle show all
Defined in:
lib/longitude.rb

Overview

Subclass of Angle to add in special treatment of to_d, to_r and to_s Longitude degrees are between -2PI and 2PI, West to East (+/- 180 degrees)

Instance Attribute Summary

Attributes inherited from Angle

#angle

Instance Method Summary collapse

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_degreesFloat Also known as: to_deg

Returns angle as degrees in range -180 and 180.

Returns:

  • (Float)

    angle as degrees in range -180 and 180



7
8
9
10
11
12
13
# File 'lib/longitude.rb', line 7

def to_degrees
  degrees = super
  if degrees > 180 then degrees - 360
  else
    degrees
  end
end

#to_radiansFloat Also known as: to_r, to_rad

Returns angle as degrees in range -2PI and 2PI.

Returns:

  • (Float)

    angle as degrees in range -2PI and 2PI



16
17
18
19
20
21
# File 'lib/longitude.rb', line 16

def to_radians
  if @angle > Math::PI then @angle - 2 * Math::PI
  else
    @angle
  end
end

#to_s(fmt = "%3d %2m'%2.4s\"%E") ⇒ String

A West angle is negative, East is Positive.

Parameters:

  • fmt (String) (defaults to: "%3d %2m'%2.4s\"%E")

    Optional format string passed to Angle#to_s

Returns:

  • (String)

    angle as string in degrees minutes seconds direction.



26
27
28
# File 'lib/longitude.rb', line 26

def to_s(fmt = "%3d %2m'%2.4s\"%E")
  super(fmt)
end