Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-ui-geometry/float.rb

Constant Summary collapse

EPSILON =
0.00001

Instance Method Summary collapse

Instance Method Details

#=~(other) ⇒ Object



34
35
36
# File 'lib/motion-ui-geometry/float.rb', line 34

def =~(other)
  roughly_equal?(other)
end

#clamp(min, max) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/motion-ui-geometry/float.rb', line 5

def clamp(min, max)
  max = 0 + max
  min = 0 + min

  min, max = max, min if min > max

  if self > max
    max
  elsif self < min
    min
  else
    self
  end
end

#roughly_equal?(other, epsilon = EPSILON) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/motion-ui-geometry/float.rb', line 30

def roughly_equal?(other, epsilon = EPSILON)
  (self - other).abs <= epsilon
end

#to_degreesObject Also known as: to_deg



25
26
27
# File 'lib/motion-ui-geometry/float.rb', line 25

def to_degrees
  self * 180.0 / Math::PI
end

#to_radiansObject Also known as: to_rad



20
21
22
# File 'lib/motion-ui-geometry/float.rb', line 20

def to_radians
  self * Math::PI / 180.0
end

#to_valueObject



38
39
40
# File 'lib/motion-ui-geometry/float.rb', line 38

def to_value
  NSNumber.numberWithFloat self
end