class Vissen::Parameterized::Value::Vec
Vector type values are stored internally as arrays of floats.
Usage¶ ↑
vec = Vec[1, 0.2] vec.value # => [1.0, 0.2]
Constants
- DEFAULT
@return [Array<Float>] the default value that will be used when `.new`
is called without arguments, or with nil.
Public Class Methods
[](a, b)
click to toggle source
@param a [#to_f] the first vector component. @param b [#to_f] the second vector component. @return [Vec] a new Vec
instance.
# File lib/vissen/parameterized/value/vec.rb, line 49 def [](a, b) new [a, b] end
new(initial_value = nil)
click to toggle source
@param initial_value [Array<#to_f>] the initial value to use.
# File lib/vissen/parameterized/value/vec.rb, line 21 def initialize(initial_value = nil) @value = DEFAULT.dup taint! write initial_value if initial_value end
Public Instance Methods
write(new_value)
click to toggle source
@raise [TypeError] if the given value does not respond to `#[]`. @raise [TypeError] if the elements of the given value does not cannot
be coerced into floats.
@param new_value [Array<#to_f>] the new values to write. @return [true] if the value was changed. @return [false] otherwise.
# File lib/vissen/parameterized/value/vec.rb, line 35 def write(new_value) return if @value == new_value @value[0] = Float(new_value[0]) @value[1] = Float(new_value[1]) taint! rescue NoMethodError raise TypeError, 'The given object must support #[]' end