Class: Numeric

Inherits:
Object show all
Defined in:
lib/moon/packages/std/core_ext/numeric.rb,
lib/moon/packages/micro_json/core_ext/numeric.rb

Instance Method Summary collapse

Instance Method Details

#clamp(mn, mx) ⇒ Numeric

Parameters:

Returns:


71
72
73
74
75
76
77
78
79
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 71

def clamp(mn, mx)
  if self < mn
    mn
  elsif self > mx
    mx
  else
    self
  end
end

#lerp(target, d) ⇒ Numeric

Linear interpolation between self and target

Parameters:

Returns:


7
8
9
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 7

def lerp(target, d)
  self + (target - self) * d
end

#max(n) ⇒ Numeric

Parameters:

Returns:


48
49
50
51
52
53
54
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 48

def max(n)
  if n > self
    n
  else
    self
  end
end

#min(n) ⇒ Numeric

Parameters:

Returns:


59
60
61
62
63
64
65
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 59

def min(n)
  if n < self
    n
  else
    self
  end
end

#to_degreesFloat

Converts the number to a degree from radians

Returns:


14
15
16
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 14

def to_degrees
  (57.2957795 * self).round
end

#to_jsonString

Dumps the Numeric as a JSON string.

Returns:


5
6
7
# File 'lib/moon/packages/micro_json/core_ext/numeric.rb', line 5

def to_json
  JSON.dump(self)
end

#to_radiansFloat

Converts the number to a radian from degrees

Returns:


21
22
23
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 21

def to_radians
  self / 57.2957795
end

#to_vec1Moon::Vector1

Returns:


26
27
28
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 26

def to_vec1
  Moon::Vector1.new self
end

#to_vec2Moon::Vector2

Returns:


31
32
33
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 31

def to_vec2
  Moon::Vector2.new self, self
end

#to_vec3Moon::Vector3

Returns:


36
37
38
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 36

def to_vec3
  Moon::Vector3.new self, self, self
end

#to_vec4Moon::Vector4

Returns:


41
42
43
# File 'lib/moon/packages/std/core_ext/numeric.rb', line 41

def to_vec4
  Moon::Vector4.new self, self, self, self
end