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.
37 38 39 40 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 37 def initialize(from, to = nil) @from = from @to = to || @from end |
Instance Attribute Details
#from ⇒ Object
A Block converting from the target coordinates
31 32 33 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 31 def from @from end |
#to ⇒ Object
A Block converting to the target coordinates
34 35 36 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 34 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 ?
66 67 68 69 70 71 |
# 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 |
Instance Method Details
#convert_from(vect) ⇒ Object
Converts a vector from the target coordinates
50 51 52 53 54 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 50 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
43 44 45 46 47 |
# File 'lib/ctioga2/graphics/types/bijection.rb', line 43 def convert_to(vect) return vect.map do |x| self.to.call(x) end end |