Class: CTioga2::Graphics::Types::Bijection
- Inherits:
-
Object
- Object
- CTioga2::Graphics::Types::Bijection
- Defined in:
- lib/ctioga2/graphics/types/bijection.rb
Overview
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.
Instance Attribute Summary collapse
-
#from ⇒ Object
A Block converting from the target coordinates.
-
#to ⇒ Object
A Block converting to the target coordinates.
Class Method Summary collapse
-
.from_text(spec) ⇒ Object
Creates a Bijection from a text representation.
Instance Method Summary collapse
-
#convert_from(vect) ⇒ Object
Converts a vector from the target coordinates.
-
#convert_to(vect) ⇒ Object
Converts a vector to the target coordinates.
-
#initialize(from, to = nil) ⇒ Bijection
constructor
Creates a new Bijection with the given blocks.
Constructor Details
#initialize(from, to = nil) ⇒ Bijection
Creates a new Bijection with the given blocks.
39 40 41 42 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 39 def initialize(from, to = nil) @from = from @to = to || @from end |
Instance Attribute Details
#from ⇒ Object
A Block converting from the target coordinates
33 34 35 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 33 def from @from end |
#to ⇒ Object
A Block converting to the target coordinates
36 37 38 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 36 def to @to end |
Class Method Details
.from_text(spec) ⇒ Object
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 ?
68 69 70 71 72 73 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 68 def self.from_text(spec) blocks = spec.split(/::/).map do |code| eval("proc do |x|\n#{code}\nend") end return Bijection.new(*blocks) end |
Instance Method Details
#convert_from(vect) ⇒ Object
Converts a vector from the target coordinates
52 53 54 55 56 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 52 def convert_from(vect) return vect.map do |x| self.from.call(x) end end |
#convert_to(vect) ⇒ Object
Converts a vector to the target coordinates
45 46 47 48 49 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 45 def convert_to(vect) return vect.map do |x| self.to.call(x) end end |