Class: Latitude

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

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

#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 -90 and 90.

Returns:

  • (Float)

    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_radiansFloat Also known as: to_r, to_rad

Returns angle as degrees in range -PI and PI.

Returns:

  • (Float)

    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.

Parameters:

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

    Optional format string passed to Angle#to_s

Returns:

  • (String)

    angle as string in degrees minutes seconds direction.



34
35
36
# File 'lib/latitude.rb', line 34

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