Class: Kamelopard::Functions::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/kamelopard/function.rb

Overview

Abstract class representing a one-dimensional function

Direct Known Subclasses

Function1D, FunctionMultiDim

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#appendObject (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

#composeObject

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

#endObject (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

#maxObject

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

#minObject

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

#startObject (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

#verboseObject

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