Class: Kamelopard::Functions::Function
- Inherits:
-
Object
- Object
- Kamelopard::Functions::Function
- Defined in:
- lib/kamelopard/function.rb
Overview
Abstract class representing a one-dimensional function
Direct Known Subclasses
Instance Attribute Summary collapse
-
#append ⇒ Object
readonly
Another function this one is composed with, or appended to the end of this one.
-
#compose ⇒ Object
Another function this one is composed with, or appended to the end of this one.
-
#end ⇒ Object
readonly
min and max describe the function’s domain.
-
#max ⇒ Object
min and max describe the function’s domain.
-
#min ⇒ Object
min and max describe the function’s domain.
-
#start ⇒ Object
readonly
min and max describe the function’s domain.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
- #get_value(x) ⇒ Object
-
#initialize(min = 0, max = 1) ⇒ Function
constructor
A new instance of Function.
-
#run_function(x) ⇒ Object
def append(f) raise “Can only append another one-dimensional function” unless f.kind_of? Function or f.nil? print STDERR “WARNING: append() isn’t actually implemented” unless f.nil? # XXX # Gotta implement this.
Constructor Details
#initialize(min = 0, max = 1) ⇒ Function
Returns a new instance of Function.
29 30 31 32 33 |
# File 'lib/kamelopard/function.rb', line 29 def initialize(min = 0, max = 1) @min = min @max = max @verbose = false end |
Instance Attribute Details
#append ⇒ Object (readonly)
Another function this one is composed with, or appended to the end of this one
25 26 27 |
# File 'lib/kamelopard/function.rb', line 25 def append @append end |
#compose ⇒ Object
Another function this one is composed with, or appended to the end of this one
25 26 27 |
# File 'lib/kamelopard/function.rb', line 25 def compose @compose end |
#end ⇒ Object (readonly)
min and max describe the function’s domain. Values passed to get_value will only range from 0 to 1; the actual value calculated will be mapped to a percentage of that domain.
22 23 24 |
# File 'lib/kamelopard/function.rb', line 22 def end @end end |
#max ⇒ Object
min and max describe the function’s domain. Values passed to get_value will only range from 0 to 1; the actual value calculated will be mapped to a percentage of that domain.
22 23 24 |
# File 'lib/kamelopard/function.rb', line 22 def max @max end |
#min ⇒ Object
min and max describe the function’s domain. Values passed to get_value will only range from 0 to 1; the actual value calculated will be mapped to a percentage of that domain.
22 23 24 |
# File 'lib/kamelopard/function.rb', line 22 def min @min end |
#start ⇒ Object (readonly)
min and max describe the function’s domain. Values passed to get_value will only range from 0 to 1; the actual value calculated will be mapped to a percentage of that domain.
22 23 24 |
# File 'lib/kamelopard/function.rb', line 22 def start @start end |
#verbose ⇒ Object
Returns the value of attribute verbose.
27 28 29 |
# File 'lib/kamelopard/function.rb', line 27 def verbose @verbose end |
Class Method Details
.interpolate(a, b) ⇒ Object
77 78 79 80 |
# File 'lib/kamelopard/function.rb', line 77 def self.interpolate(a, b) # Creates a new Function object between points A and B raise "Override this method before calling it, please" end |
Instance Method Details
#get_value(x) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/kamelopard/function.rb', line 50 def get_value(x) raise "Value #{x} must be between 0 and 1" if (x.to_f > 1 or x.to_f < 0) val = x * (max - min) + min if @compose.nil? then return run_function(val) else return run_function(@compose.get_value(val)) end end |
#run_function(x) ⇒ Object
def append(f)
raise "Can only append another one-dimensional function" unless f.kind_of? Function or f.nil?
print STDERR "WARNING: append() isn't actually implemented" unless f.nil?
# XXX
# Gotta implement this. The idea is to have one function for the first
# part of a domain, and another for the next. The domain of the second
# function will begin with the end of the last function.
# Perhaps allow two methods. One just appends the two; the second
# smooths things somewhat by adding to the result of the second the
# value of the first at the end of its domain.
@append = f
end
73 74 75 |
# File 'lib/kamelopard/function.rb', line 73 def run_function(x) raise "Override this method before calling it, please" end |