class Numeric

Numeric extensions for graphics

Public Instance Methods

close_to?(n, delta = 0.01) click to toggle source

Is M close to N within a certain delta?

# File lib/graphics/extensions.rb, line 20
def close_to? n, delta = 0.01
  (self - n).abs < delta
end
degrees() click to toggle source

Normalize a number to be within 0…360

# File lib/graphics/extensions.rb, line 27
def degrees
  self % 360
end
relative_angle(n, max) click to toggle source

I am honestly befuddled by this code, and I wrote it.

I should probably remove it and start over.

Consider this method private, even tho it is in use by the demos.

# File lib/graphics/extensions.rb, line 38
def relative_angle n, max
  delta_cw = (self - n).degrees
  delta_cc = (n - self).degrees

  return if delta_cc < 0.1 || delta_cw < 0.1

  if delta_cc.abs < max then
    delta_cc
  elsif delta_cw.close_to? 180 then
    [-max, max].sample
  elsif delta_cw < delta_cc then
    -max
  else
    max
  end
end