Class: Svgcode::SVG::Transform
- Inherits:
-
Object
- Object
- Svgcode::SVG::Transform
- Defined in:
- lib/svgcode/svg/transform.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#c ⇒ Object
readonly
Returns the value of attribute c.
-
#d ⇒ Object
readonly
Returns the value of attribute d.
-
#e ⇒ Object
readonly
Returns the value of attribute e.
-
#f ⇒ Object
readonly
Returns the value of attribute f.
Instance Method Summary collapse
- #apply(point) ⇒ Object
-
#initialize(str_or_a, b = nil, c = nil, d = nil, e = nil, f = nil) ⇒ Transform
constructor
A new instance of Transform.
- #to_matrix ⇒ Object
Constructor Details
#initialize(str_or_a, b = nil, c = nil, d = nil, e = nil, f = nil) ⇒ Transform
Returns a new instance of Transform.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/svgcode/svg/transform.rb', line 10 def initialize(str_or_a, b = nil, c = nil, d = nil, e = nil, f = nil) if str_or_a.is_a?(String) raise ArgumentException.new unless str_or_a.start_with?('matrix') nums = str_or_a.gsub(/.+\(/, '').gsub(/\)/, '').split(/\s*,\s*/) nums.each_with_index do |n, i| case i when 0 @a = Svgcode::Utility.x_to_f(n) when 1 @b = Svgcode::Utility.x_to_f(n) when 2 @c = Svgcode::Utility.x_to_f(n) when 3 @d = Svgcode::Utility.x_to_f(n) when 4 @e = Svgcode::Utility.x_to_f(n) when 5 @f = Svgcode::Utility.x_to_f(n) end end else @a = Svgcode::Utility.x_to_f(str_or_a) @b = Svgcode::Utility.x_to_f(b) @c = Svgcode::Utility.x_to_f(c) @d = Svgcode::Utility.x_to_f(d) @e = Svgcode::Utility.x_to_f(e) @f = Svgcode::Utility.x_to_f(f) end end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
8 9 10 |
# File 'lib/svgcode/svg/transform.rb', line 8 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
8 9 10 |
# File 'lib/svgcode/svg/transform.rb', line 8 def b @b end |
#c ⇒ Object (readonly)
Returns the value of attribute c.
8 9 10 |
# File 'lib/svgcode/svg/transform.rb', line 8 def c @c end |
#d ⇒ Object (readonly)
Returns the value of attribute d.
8 9 10 |
# File 'lib/svgcode/svg/transform.rb', line 8 def d @d end |
#e ⇒ Object (readonly)
Returns the value of attribute e.
8 9 10 |
# File 'lib/svgcode/svg/transform.rb', line 8 def e @e end |
#f ⇒ Object (readonly)
Returns the value of attribute f.
8 9 10 |
# File 'lib/svgcode/svg/transform.rb', line 8 def f @f end |
Instance Method Details
#apply(point) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/svgcode/svg/transform.rb', line 45 def apply(point) point_m = Matrix[[point.x], [point.y], [1]] transform_m = to_matrix result = transform_m * point_m Point.new(result[0, 0], result[1, 0]) end |
#to_matrix ⇒ Object
41 42 43 |
# File 'lib/svgcode/svg/transform.rb', line 41 def to_matrix Matrix[[@a, @c, @e], [@b, @d, @f], [0, 0, 1]] end |