Module: GeoUnits::Numeric::Normalizer
- Extended by:
- Normalizer
- Included in:
- Normalizer, Numeric
- Defined in:
- lib/geo_units/numeric/normalizer.rb
Instance Method Summary collapse
- #normalize_deg(shift = 0) ⇒ Object (also: #normalize_degrees)
-
#normalize_lat ⇒ Object
all degrees between -90 and 90.
-
#normalize_lng ⇒ Object
all degrees between -180 and 180.
Instance Method Details
#normalize_deg(shift = 0) ⇒ Object Also known as: normalize_degrees
54 55 56 |
# File 'lib/geo_units/numeric/normalizer.rb', line 54 def normalize_deg shift = 0 (self + shift) % 360 end |
#normalize_lat ⇒ Object
all degrees between -90 and 90
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/geo_units/numeric/normalizer.rb', line 25 def normalize_lat case self when -360, 0, 360 0 when -180, 180 0 when -360..-270 self % 90 when -270..-180 90 - (self % 90) when -180..-90 - (self % 90) when -90..0 -90 + (self % 90) when 0..90 self when 90..180 self % 90 when 180..270 - (self % 90) when 270..360 - 90 + (self % 90) else return (self % 360).normalize_lat if self > 360 return (360 - (self % 360)).normalize_lat if self < -360 raise ArgumentError, "Degrees #{self} out of range" end end |
#normalize_lng ⇒ Object
all degrees between -180 and 180
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/geo_units/numeric/normalizer.rb', line 5 def normalize_lng case self when -360, 0, 360 0 when -360..-180 self % 180 when -180..0 -180 + (self % 180) when 0..180 self when 180..360 self % 180 else return (self % 360).normalize_lng if self > 360 return (360 - (self % 360)).normalize_lng if self < -360 raise ArgumentError, "Degrees #{self} out of range" end end |