class CTioga2::Graphics::Types::Bijection
This class represents a reversible arbitrary coordinate transformation, such as the ones that could be desirable for alternative axes. Characterized by two Block objects, from
and to
, that converts respectively from and to the target coordinates.
Attributes
A Block converting from the target coordinates
A Block converting to the target coordinates
Public Class Methods
Creates a Bijection
from a text representation.
Takes functions of x. Takes two blocks from to
- separated by
-
– or only one block in the case of an
involution (very common, actually, all 1/x transforms).
todo few things around here to change… in particular, I should try to find a way to include Math
…
todo add very common cases ?
# File lib/ctioga2/graphics/types/bijection.rb, line 66 def self.from_text(spec) blocks = spec.split(/::/).map do |code| eval("proc do |x|\n#{code}\nend") end return Bijection.new(*blocks) end
Creates a new Bijection
with the given blocks.
# File lib/ctioga2/graphics/types/bijection.rb, line 37 def initialize(from, to = nil) @from = from @to = to || @from end
Public Instance Methods
Converts a vector from the target coordinates
# File lib/ctioga2/graphics/types/bijection.rb, line 50 def convert_from(vect) return vect.map do |x| self.from.call(x) end end
Converts a vector to the target coordinates
# File lib/ctioga2/graphics/types/bijection.rb, line 43 def convert_to(vect) return vect.map do |x| self.to.call(x) end end