vincenty 1.0.6 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/lib/angle.rb CHANGED
@@ -1,263 +1,259 @@
1
- require 'core_extensions.rb'
1
+ require_relative 'core_extensions.rb'
2
2
 
3
- #Class Angle is a utility class that allows
3
+ # Class Angle is a utility class that allows
4
4
  # * Angle arithmetic ( +,-,*,/,**,% and unary +,-)
5
5
  # * Angle comparison ( <=>, hence, <, >, >=, <=, == )
6
6
  # * Conversion to and from degrees and radians
7
7
  # * Conversion to string as radians or DMS format
8
-
9
8
  class Angle
10
9
  include Comparable
11
-
10
+
12
11
  # @return [Float] stored in radians
13
- attr_accessor :angle
14
- alias :value :angle #Older version of angle used volue rather than angle
15
- alias :value= :angle= #Older version of angle used volue rather than angle
16
-
17
- # @param [#to_f,#to_radians] angle may be anything that has a to_f and to_radians.
12
+ attr_accessor :angle
13
+ alias value angle # Older version of angle used volue rather than angle
14
+ alias value= angle= # Older version of angle used volue rather than angle
15
+
16
+ # @param [#to_f,#to_radians] angle may be anything that has a to_f and to_radians.
18
17
  # @param [true,false, :radians] radians Angle is in degrees unless radians == true (or set to :radians).
19
- def initialize(angle=0, radians=false)
20
- #assumes that we are getting an angle in degrees.
21
- if radians == true || radians == :radians
22
- @angle = angle.to_f #works for String, Fixed, other Angles and for Float.
23
- else
24
- if angle.class == Array
25
- @angle = self.class.decimal_deg(*angle).to_radians #Wild assumption that the array is deg,min,sec.
26
- else
27
- @angle = angle.to_radians #we have a String and Numeric class version of this. Another Angle will work too.
28
- end
29
- end
18
+ def initialize(angle = 0, radians = false)
19
+ # assumes that we are getting an angle in degrees.
20
+ @angle = if radians == true || radians == :radians
21
+ angle.to_f # works for String, Fixed, other Angles and for Float.
22
+ elsif angle.instance_of?(Array)
23
+ self.class.decimal_deg(*angle).to_radians
24
+ else
25
+ angle.to_radians # we have a String and Numeric class version of this. Another Angle will work too.
26
+ end
30
27
  end
31
-
32
-
33
- #Class level function that converts 4 arguments into decimal degrees.
28
+
29
+ # Class level function that converts 4 arguments into decimal degrees.
34
30
  # @return [Float] signed decimal degrees.
35
31
  # @param [Numeric] degrees
36
32
  # @param [Numeric] minutes
37
33
  # @param [Numeric] seconds
38
34
  # @param ['N', 'S', 'E', 'W'] direction Optional, as the direction might be specified by a negative value for degrees
39
- def self.decimal_deg(degrees=0, minutes=0, seconds=0, direction='N')
40
- s = { 'N'=>1, 'S'=>-1, 'E'=>1, 'W'=>-1, 'n'=>1, 's'=>-1, 'e'=>1, 'w'=>-1 }
35
+ def self.decimal_deg(degrees = 0, minutes = 0, seconds = 0, direction = 'N')
36
+ s = { 'N' => 1, 'S' => -1, 'E' => 1, 'W' => -1, 'n' => 1, 's' => -1, 'e' => 1, 'w' => -1 }
41
37
  sign = s[direction]
42
- sign = sign == nil ? 1 : sign #Assume 'N' or 'E' if the direction is not set.
43
- #Shouldn't have a negative value for degrees if the direction is specified.
44
- #I am defaulting to the degrees sign if it is set, otherwise the direction given
45
- sign = degrees.sign == -1 || (degrees == 0 && (minutes < 0 || (minutes == 0 && seconds < 0))) ? -1 : sign
46
- sign * (degrees.abs + minutes/60.0 + seconds/3600.0)
38
+ sign = 1 if sign.nil? # Assume 'N' or 'E' if the direction is not set.
39
+ # Shouldn't have a negative value for degrees if the direction is specified.
40
+ # I am defaulting to the degrees sign if it is set, otherwise the direction given
41
+ sign = -1 if degrees.sign == -1 || (degrees == 0 && (minutes < 0 || (minutes == 0 && seconds < 0)))
42
+ return sign * (degrees.abs + (minutes / 60.0) + (seconds / 3600.0))
47
43
  end
48
-
49
- #Class level function that takes an array of [degress,minutes, seconds, direction] or [degrees,minutes,seconds]
44
+
45
+ # Class level function that takes an array of [degress,minutes, seconds, direction] or [degrees,minutes,seconds]
50
46
  # @return [Float] signed decimal degrees.
51
47
  # @param [Array] a Array is expanded and passed as degrees,minutes,seconds,direction to Angle#decimal_deg
52
48
  def self.decimal_deg_from_ary(a)
53
- self.decimal_deg(*a)
49
+ return self.decimal_deg(*a)
54
50
  end
55
-
56
- #Class level utility function to return the angle as deg,min,sec
57
- #Assumes decimal degress unless radians == true .
51
+
52
+ # Class level utility function to return the angle as deg,min,sec
53
+ # Assumes decimal degress unless radians == true .
58
54
  # @return [Array] of signed deg, min, sec.
59
- #Nb. * That min will be negative if the angle is negative and deg == 0
55
+ # Nb. * That min will be negative if the angle is negative and deg == 0
60
56
  # * That sec will be negative if the angle is negative and deg == 0 && min == 0
61
- # @param [#to_f,#to_degrees] angle may be anything that has a to_f and to_radians.
57
+ # @param [#to_f,#to_degrees] angle may be anything that has a to_f and to_radians.
62
58
  # @param [true,false, :radians] radians Angle is in degrees unless radians == true (or set to :radians).
63
59
  def self.dms(angle, radians = false)
64
- ongle = angle.to_f #means Strings, Numeric, and anything accepting a #to_f will work.
60
+ angle = angle.to_f # means Strings, Numeric, and anything accepting a #to_f will work.
65
61
  angle = angle.to_degrees if radians == true || radians == :radians
66
62
  v = angle.abs
67
63
  deg = v.floor
68
- min = ((v-deg)*60.0).floor
69
- sec = ((v-deg-min/60.0)*3600.0)
70
-
64
+ min = ((v - deg) * 60.0).floor
65
+ sec = ((v - deg - (min / 60.0)) * 3600.0)
66
+
71
67
  if angle < 0
72
68
  if deg == 0
73
69
  if min == 0
74
70
  sec = -sec
75
71
  else
76
- min = -min
72
+ min = -min
77
73
  end
78
74
  else
79
75
  deg = -deg
80
76
  end
81
77
  end
82
78
 
83
- return deg,min,sec
79
+ return deg, min, sec
84
80
  end
85
-
86
- #Class level function equivalent to Angle.new(r, true)
81
+
82
+ # Class level function equivalent to Angle.new(r, true)
87
83
  # @return [Angle]
88
84
  # @param [#to_f] r Value in radians to create the new Angle class with.
89
- def self.radians(r=0) #passed in radians.
90
- self.new(r.to_f, true) #Nb. self is Angle, be we don't Angle.new, as we want subclasses to return their class, not Angle.
85
+ def self.radians(r = 0)
86
+ return self.new(r.to_f, true) # Nb. self is Angle, be we don't Angle.new, as we want subclasses to return their class, not Angle.
91
87
  end
92
-
93
- #Class level function equivalent to Angle.new(d, false) or just Angle.new(d)
88
+
89
+ # Class level function equivalent to Angle.new(d, false) or just Angle.new(d)
94
90
  # @return [Angle]
95
- # @param [#to_radians] d Angle to convert to radians, to create new Angle object from.
96
- def self.degrees(d=0) #passed in degrees.
97
- self.new(d.to_radians, true)
91
+ # @param [#to_radians] d Angle in degrees, to convert to radians, to create new Angle object from.
92
+ def self.degrees(d = 0)
93
+ return self.new(d.to_radians, true)
98
94
  end
99
-
100
- #Provides test for Module Comparable, giving us <,>,<=,>=,== between angles
95
+
96
+ # Provides test for Module Comparable, giving us <,>,<=,>=,== between angles
101
97
  # @return [true,false]
102
98
  # @param [Angle,Float] angle Can be another Angle, or a Numeric value to compare @angle with.
103
- def <=>(angle)
104
- if angle.class == Angle
105
- @angle <=> angle.angle
106
- else
107
- @angle <=> angle
108
- end
99
+ def <=>(other)
100
+ @angle <=> if other.instance_of?(Angle)
101
+ other.angle
102
+ else
103
+ other
104
+ end
109
105
  end
110
106
 
111
- #unary +
107
+ # unary +
112
108
  # @return [Angle,self] equivalent to @angle
113
109
  def +@
114
- self.class.radians(@angle) #Nb. Not Angle.new, as we want subclasses to return their class, not Angle.
110
+ return self.class.radians(@angle) # Nb. Not Angle.new, as we want subclasses to return their class, not Angle.
115
111
  end
116
-
117
- #Unary -
112
+
113
+ # Unary -
118
114
  # @return [Angle,self] -@angle
119
115
  def -@
120
- self.class.radians(-@angle)
116
+ return self.class.radians(-@angle)
121
117
  end
122
-
118
+
123
119
  # Binary addition operator. Can add angles and numbers, or two angles.
124
120
  # @return [Angle,self]
125
121
  # @param [Angle,Numeric] angle
126
- def +(angle)
127
- self.class.radians(@angle + angle)
122
+ def +(other)
123
+ return self.class.radians(@angle + other)
128
124
  end
129
-
125
+
130
126
  # Binary subtraction operator. Can add angles and numbers, or two angles.
131
127
  # @return [Angle,self]
132
128
  # @param [Angle,Numeric] angle
133
- def -(angle)
134
- self.class.radians(@angle - angle)
129
+ def -(other)
130
+ return self.class.radians(@angle - other)
135
131
  end
136
-
132
+
137
133
  # Binary multiply operator. Can add angles and numbers, or two angles.
138
134
  # @return [Angle,self]
139
135
  # @param [Angle,Numeric] angle
140
- def *(angle)
141
- self.class.radians(@angle * angle)
136
+ def *(other)
137
+ self.class.radians(@angle * other)
142
138
  end
143
-
139
+
144
140
  # Binary power of operator. Can add angles and numbers, or two angles.
145
141
  # @return [Angle,self]
146
142
  # @param [Angle,Numeric] angle
147
- def **(angle)
148
- self.class.radians(@angle ** angle)
143
+ def **(other)
144
+ return self.class.radians(@angle**other)
149
145
  end
150
-
146
+
151
147
  # Binary division operator. Can add angles and numbers, or two angles.
152
148
  # @return [Angle,self]
153
149
  # @param [Angle,Numeric] angle
154
- def /(angle)
155
- self.class.radians(@angle / angle)
150
+ def /(other)
151
+ return self.class.radians(@angle / other)
156
152
  end
157
-
153
+
158
154
  # Binary mod operator. Can add angles and numbers, or two angles.
159
155
  # @return [Angle,self]
160
156
  # @param [Angle,Numeric] angle
161
- def %(angle)
162
- self.class.radians(@angle % angle)
157
+ def %(other)
158
+ return self.class.radians(@angle % other)
163
159
  end
164
-
160
+
165
161
  # @return [Float] angle in degrees
166
162
  def to_degrees
167
- @angle.to_degrees
163
+ return @angle.to_degrees
168
164
  end
169
-
165
+
170
166
  # @return [Float] angle in degrees
171
- #alias to_d to_degrees
167
+ # alias to_deg to_degrees
172
168
  alias to_deg to_degrees
173
-
169
+
174
170
  # @return [Float] angle in radians
175
171
  def to_radians
176
- @angle
172
+ return @angle
177
173
  end
178
174
 
179
175
  alias to_rad to_radians
180
176
  alias to_r to_radians
181
-
177
+
182
178
  # Returns @angle as decimal_degrees
183
179
  # @return [Array] of signed Floats: degrees,minutes,seconds
184
- #Nb. * That min will be negative if the angle is negative and deg == 0
180
+ # Nb. * That min will be negative if the angle is negative and deg == 0
185
181
  # * That sec will be negative if the angle is negative and deg == 0 && min == 0
186
- def to_dms
182
+ def to_dms
187
183
  d = to_degrees.abs
188
184
  deg = d.floor
189
- min = ((d-deg)*60).floor
190
- sec = ((d-deg-min/60.0)*3600.0)
191
-
185
+ min = ((d - deg) * 60).floor
186
+ sec = ((d - deg - (min / 60.0)) * 3600.0)
187
+
192
188
  if @angle < 0
193
189
  if deg == 0
194
190
  if min == 0
195
191
  sec = -sec
196
192
  else
197
- min = -min
193
+ min = -min
198
194
  end
199
195
  else
200
196
  deg = -deg
201
197
  end
202
198
  end
203
-
199
+
204
200
  return deg, min, sec
205
201
  end
206
-
202
+
207
203
  # @return [Float] the angle in radians as a float (equivalent to to_radians)
208
204
  alias to_f to_radians
209
-
205
+
210
206
  # @return [Fixnum] the angle truncated to an integer, in radians.
211
207
  def to_i
212
- to_radians.to_i
208
+ return to_radians.to_i
213
209
  end
214
-
210
+
215
211
  # @return [Fixnum] the angle truncated to an integer, in radians.
216
212
  alias to_int to_i
217
-
213
+
218
214
  # @return [Array] the angle parameter as a Float and the @angle parameter from this class.
219
215
  # @param [Numeric] angle
220
216
  def coerce(angle)
221
- [Float(angle), @angle]
217
+ return [ Float(angle), @angle ]
222
218
  end
223
-
219
+
224
220
  # @return [Fixnum] the sign of the angle. 1 for positive, -1 for negative.
225
221
  def sign
226
- @angle.sign
222
+ return @angle.sign
227
223
  end
228
-
224
+
229
225
  # @return [Float] the absolute angle of the angle in radians
230
226
  def abs
231
- @angle.abs
227
+ return @angle.abs
232
228
  end
233
-
229
+
234
230
  # @return [Float] angle as compass bearing in radians.
235
- #Compass bearings are clockwise, Math angles are counter clockwise.
231
+ # Compass bearings are clockwise, Math angles are counter clockwise.
236
232
  def to_bearing
237
- self.class.new(Math::PI * 2 - @angle,true)
233
+ return self.class.new((Math::PI * 2) - @angle, true)
238
234
  end
239
-
235
+
240
236
  # @return [Float] the reverse angle in radians. i.e. angle + PI (or angle + 180 degrees)
241
237
  def reverse
242
238
  if (angle = @angle + Math::PI) > Math::PI * 2
243
239
  angle -= Math::PI * 2
244
240
  end
245
- return self.class.new(angle,true)
241
+ return self.class.new(angle, true)
246
242
  end
247
-
248
-
243
+
249
244
  # @return [String] angle in radians as a string.
250
245
  # @param [String] fmt Optional format string passed to Angle#strf
251
246
  def to_s(fmt = nil)
252
- return to_radians.to_s if(fmt == nil)
247
+ return to_radians.to_s if fmt.nil?
248
+
253
249
  return strf(fmt)
254
250
  end
255
-
256
- #formated output of the angle.
251
+
252
+ # formated output of the angle.
257
253
  # @param [String] fmt The default format is a signed deg minutes'seconds" with leading 0's in the minutes and seconds and 4 decimal places for seconds.
258
- #formats are:
254
+ # formats are:
259
255
  # * %wd output the degrees as an integer.
260
- # ** where w is 0, 1, 2 or 3 and represents the field width.
256
+ # ** where w is 0, 1, 2 or 3 and represents the field width.
261
257
  # *** 1 is the default, which indicates that at least 1 digit is displayed
262
258
  # *** 2 indicates that at least 2 digits are displayed. 1 to 9 will be displayed as 01 0 to 09 0
263
259
  # *** 3 indicates that at least 4 digits are displayed. 10 to 99 will be displayed as 010 0 to 099 0
@@ -271,8 +267,8 @@ class Angle
271
267
  # * %w.pM outputs minutes as a float .e.g. 01.125'.
272
268
  # * p is the number of decimal places.
273
269
  #
274
- # * %wW outputs secs/60 as a float without the leading '0.'.
275
- # Used with %m like this %2m'%4W , to get minute marker before the decimal places.
270
+ # * %wW outputs secs/60 as a float without the leading '0.'.
271
+ # Used with %m like this %2m'%4W , to get minute marker before the decimal places.
276
272
  # e.g. -37 001'.1167 rather than -37 001.1167'
277
273
  # * p is the number of decimal places.
278
274
  #
@@ -289,144 +285,132 @@ class Angle
289
285
  #
290
286
  # Other strings in the format are printed as is.
291
287
  # @return [String]
292
- def strf(fmt="%d %2m'%2.4s\"")
293
- tokens = fmt.scan(/%[0-9\.]*[%dmsDMNErW]|[^%]*/)
288
+ def strf(fmt = "%d %2m'%2.4s\"")
289
+ tokens = fmt.scan(/%[0-9.]*[%dmsDMNErW]|[^%]*/)
294
290
  have_dir = have_dms = false
295
291
  tokens.collect! do |t|
296
- if t[0,1] == '%' #format
292
+ if t[0, 1] == '%' # format
297
293
  had_dot = false
298
294
  decimals = -1
299
295
  width = -1
300
296
  format = nil
301
297
  t[1..-1].scan(/[0-9]+|\.|[0-9]+|[%dmsDMNErW]/) do |t2|
302
298
  case t2
303
- when /[0-9]+/
304
- if had_dot
305
- decimals = t2.to_i
306
- else
307
- width = t2.to_i
308
- end
309
- when '%'
310
- format = t2
311
- when /[dmsMwW]/
312
- have_dms = true
313
- format = t2
314
- when /[NE]/
315
- have_dir = true
316
- format = t2
317
- when '.'
318
- had_dot = true
319
- when /[Dr]/
320
- format = t2
299
+ when /[0-9]+/
300
+ if had_dot
301
+ decimals = t2.to_i
321
302
  else
322
- raise "unknown format character '#{t2}'" #shouldn't be able to get here.
303
+ width = t2.to_i
304
+ end
305
+ when '%', /[Dr]/
306
+ format = t2
307
+ when /[dmsMwW]/
308
+ have_dms = true
309
+ format = t2
310
+ when /[NE]/
311
+ have_dir = true
312
+ format = t2
313
+ when '.'
314
+ had_dot = true
315
+ else
316
+ raise "unknown format character '#{t2}'" # shouldn't be able to get here.
323
317
  end
324
318
  end
325
- [:format, width, decimals, format]
319
+ [ :format, width, decimals, format ]
326
320
  else
327
- [:filler, t]
321
+ [ :filler, t ]
328
322
  end
329
323
  end
330
324
 
331
- deg,min,sec = to_dms if have_dms
325
+ deg, min, sec = to_dms if have_dms
332
326
 
333
- s = ""
327
+ s = ''
334
328
  tokens.each do |t|
335
- if(t[0] == :format)
329
+ if t[0] == :format
336
330
  case t[3]
337
331
  when '%'
338
332
  s += '%'
339
333
  when 'd'
340
334
  s += s_int(deg, t[1], have_dir)
341
335
  when 'D'
342
- s += s_float(@angle.to_d, t[1], t[2], have_dir)
336
+ s += s_float(@angle.to_deg, t[1], t[2], have_dir)
343
337
  when 'm'
344
338
  s += s_int(min, t[1], have_dir)
345
339
  when 'M'
346
- s += s_float(min + sec/60, t[1], t[2], have_dir)
340
+ s += s_float(min + (sec / 60), t[1], t[2], have_dir)
347
341
  when 'W'
348
- s += s_only_places(sec/60, t[1])
342
+ s += s_only_places(sec / 60, t[1])
349
343
  when 's'
350
344
  s += s_float(sec, t[1], t[2], have_dir)
351
345
  when 'r'
352
346
  s += s_float(@angle, t[1], t[2], have_dir)
353
347
  when 'N'
354
- s += (@angle < 0 ? 'S' : 'N')
348
+ s += (@angle < 0 ? 'S' : 'N')
355
349
  when 'E'
356
350
  s += (@angle < 0 ? 'W' : 'E')
357
351
  end
358
352
  else
359
- s += t[1] #the fillers.
353
+ s += t[1] # the fillers.
360
354
  end
361
355
  end
362
-
356
+
363
357
  return s
364
358
  end
365
-
366
- private
367
- #Output angle_dec as a string to the number of decimal places specified by places.
368
- #Assumes the angle is 0 <= angle_dec < 1
369
- #No leading '0' is output. The string starts with a '.' if places is non-zero.
370
- #If ploces is -1, then all decimal places are returned.
359
+
360
+ # Output angle_dec as a string to the number of decimal places specified by places.
361
+ # Assumes the angle is 0 <= angle_dec < 1
362
+ # No leading '0' is output. The string starts with a '.' if places is non-zero.
363
+ # If ploces is -1, then all decimal places are returned.
371
364
  # @return [String]
372
365
  # @param [Float] angle_dec Angle's fractional part
373
366
  # @param [Fixnum] places Number of decimal places to output
374
- def s_places(angle_dec, places)
375
- if places != -1
376
- places > 0 ? ".%0#{places}d" % (angle_dec * 10 ** places).round : ''
367
+ private def s_places(angle_dec, places)
368
+ if places == -1
369
+ angle_dec.to_s[1..-1] # Output all decimal places stripping the leading 0
377
370
  else
378
- angle_dec.to_s[1..-1] #Output all decimal places stripping the leading 0
371
+ places > 0 ? ".%0#{places}d" % (angle_dec * (10**places)).round : ''
379
372
  end
380
373
  end
381
374
 
382
- #return the angle as a string with fixed width decimal portion with leading 0s
383
- #to get at least the width specified
384
- #Prints the number of places after the decimal point rounded to places places.
375
+ # return the angle as a string with fixed width decimal portion with leading 0s
376
+ # to get at least the width specified
377
+ # Prints the number of places after the decimal point rounded to places places.
385
378
  #-1 width means no width format
386
379
  #-1 places means print all decimal places.
387
- #abs means print the absolute value.
380
+ # abs means print the absolute value.
388
381
  # @return [String]
389
382
  # @param [Float] angle In radians
390
383
  # @param [Fixnum] width Output field width, padded with leading 0's
391
384
  # @param [Fixnum] places Number of decimal places to output
392
385
  # @param [true,false] abs Output absolute value.
393
- def s_float(angle, width, places, abs)
394
- angle_int, angle_dec = angle.abs.divmod(1)
386
+ private def s_float(angle, width, places, abs)
387
+ _angle_int, angle_dec = angle.abs.divmod(1)
395
388
  f = "%0#{width > 0 ? width : ''}d"
396
- s = (abs == false && angle.sign == -1) ? '-' : '' #catch the case of -0
397
- s += f % angle.abs + s_places(angle_dec, places)
389
+ s = abs == false && angle.sign == -1 ? '-' : '' # catch the case of -0
390
+ return s + (f % angle.abs) + s_places(angle_dec, places)
398
391
  end
399
392
 
400
- #Return the integer part of angle as a string of fixed width
401
- #If abs == true, then return the absolute value.
393
+ # Return the integer part of angle as a string of fixed width
394
+ # If abs == true, then return the absolute value.
402
395
  # @return [Fixnum]
403
396
  # @param [Float] angle In radians
404
397
  # @param [Fixnum] width Output field width, padded with leading 0's
405
398
  # @param [true,false] abs Output absolute value.
406
- def s_int(angle, width, abs)
399
+ private def s_int(angle, width, abs)
407
400
  f = "%0#{width > 0 ? width : ''}d"
408
- s = (abs == false && angle.sign == -1) ? '-' : '' #catch the case of -0
409
- s += f % angle.abs
401
+ s = abs == false && angle.sign == -1 ? '-' : '' # catch the case of -0
402
+ return s + (f % angle.abs)
410
403
  end
411
-
412
- #Return the fractional part of angle as a string,
413
- #to the number of decimal places specified by 'places'.
414
- #No leading '0' is output. The string starts with a '.'
415
- #If ploces is -1, then all decimal places are returned.
404
+
405
+ # Return the fractional part of angle as a string,
406
+ # to the number of decimal places specified by 'places'.
407
+ # No leading '0' is output. The string starts with a '.'
408
+ # If ploces is -1, then all decimal places are returned.
416
409
  # @return [String]
417
410
  # @param [Float] angle In radians
418
411
  # @param [Fixnum] places Number of decimal places to output
419
- def s_only_places(angle, places)
420
- angle_int, angle_dec = angle.abs.divmod(1)
412
+ private def s_only_places(angle, places)
413
+ _angle_int, angle_dec = angle.abs.divmod(1)
421
414
  s_places(angle_dec, places)
422
415
  end
423
416
  end
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
data/lib/coordinate.rb CHANGED
@@ -1,37 +1,36 @@
1
+ require_relative 'angle.rb'
1
2
 
2
- require 'angle.rb'
3
-
4
- #Holds the latitude, longitude, and the altitude for the coordinate
3
+ # Holds the latitude, longitude, and the altitude for the coordinate
5
4
  class Coordinate
6
5
  # @return [Latitude]
7
- attr_accessor :latitude
6
+ attr_accessor :latitude
8
7
  # @return [Longitude]
9
- attr_accessor :longitude
8
+ attr_accessor :longitude
10
9
  # @return [Numeric]
11
- attr_accessor :altitude
12
-
13
- #latitude and longitude can be Strings or Numeric, or anything else with to_radians and to_f
14
- #latitude and longitude are in degrees unless radians == true (or set to :radians)
15
- def initialize(latitude=0, longitude=0, altitude=0, radians = false)
16
- @latitude = Latitude.new(latitude,radians)
17
- @longitude = Longitude.new(longitude,radians)
10
+ attr_accessor :altitude
11
+
12
+ # latitude and longitude can be Strings or Numeric, or anything else with to_radians and to_f
13
+ # latitude and longitude are in degrees unless radians == true (or set to :radians)
14
+ def initialize(latitude = 0, longitude = 0, altitude = 0, radians = false)
15
+ @latitude = Latitude.new(latitude, radians)
16
+ @longitude = Longitude.new(longitude, radians)
18
17
  @altitude = altitude.to_f
19
18
  end
20
-
19
+
21
20
  # @return [String] Latitude longitude and altitude as a single space separated string.
22
21
  def to_s
23
- "#{@latitude.to_s } #{@longitude.to_s} #{@altitude}m"
22
+ "#{@latitude} #{@longitude} #{@altitude}m"
24
23
  end
25
-
24
+
26
25
  # @return [Latitude, Longitude, Float] with members, latitude, longitude and altitude
27
26
  def to_ary
28
27
  [ @latitude, @longitude, @altitude ]
29
28
  end
30
-
29
+
31
30
  alias to_a to_ary
32
-
31
+
33
32
  # @return [Hash] with keys :latitude, :longitude, and :altitude
34
33
  def to_hash
35
- { :latitude => @latitude, :longitude => @longitude, :altitude => @altitude }
34
+ { latitude: @latitude, longitude: @longitude, altitude: @altitude }
36
35
  end
37
- end
36
+ end