Module: Sevgi::Graphics::Mixtures::Transform::InstanceMethods
- Defined in:
- lib/sevgi/graphics/mixtures/transform.rb
Instance Method Summary collapse
- #Align(position, inner:, outer:) ⇒ Object
- #Matrix(*values) ⇒ Object
- #Rotate(a, *origin) ⇒ Object
- #Scale(x, y = nil) ⇒ Object
- #Scale! ⇒ Object
- #Skew(ax, ay) ⇒ Object
- #SkewX(a) ⇒ Object
- #SkewY(a) ⇒ Object
- #Translate(x, y = nil) ⇒ Object
Instance Method Details
#Align(position, inner:, outer:) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 8 def Align(position, inner:, outer:) return self unless position && inner && outer case position.to_sym when :center then Translate((outer.width - inner.width) / 2.0, (outer.height - inner.height) / 2.0) else ArgumentError.("Unsupported alignment: #{position}") end end |
#Matrix(*values) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 17 def Matrix(*values) tap do ArgumentError.("Incorrect transform matrix (six values required): #{values}") if values.size != 6 next if values.map(&:to_f).all? { _1 == 0.0 } attributes[:"transform+"] = "matrix(#{values.join(" ")})" end end |
#Rotate(a, *origin) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 27 def Rotate(a, *origin) tap do ArgumentError.("Incorrect origin (two coordinates required): #{origin}") if !origin.empty? && origin.size != 2 next if a.to_f == 0.0 attributes[:"transform+"] = "rotate(#{[ a, *origin ].join(", ")})" end end |
#Scale(x, y = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 37 def Scale(x, y = nil) tap do next if x.to_f == 0.0 && (y.nil? || y.to_f == 0.0) attributes[:"transform+"] = "scale(#{(y ? [ x, y ] : [ x ]).join(", ")})" end end |
#Scale! ⇒ Object
45 46 47 48 49 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 45 def Scale!(...) Scale(...).tap do attributes[:"vector-effect"] = "non-scaling-stroke" unless attributes[:"vector-effect"] end end |
#Skew(ax, ay) ⇒ Object
51 52 53 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 51 def Skew(ax, ay) Matrix(1.0, F.approx(F.tan(ay)), F.approx(F.tan(ax)), 1.0, 0.0, 0.0) # TODO: xxx end |
#SkewX(a) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 55 def SkewX(a) tap do next if a.to_f == 0.0 attributes[:"transform+"] = "skewX(#{a})" end end |
#SkewY(a) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 63 def SkewY(a) tap do next if a.to_f == 0.0 attributes[:"transform+"] = "skewY(#{a})" end end |
#Translate(x, y = nil) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 71 def Translate(x, y = nil) tap do next if x.to_f == 0.0 && (y.nil? || y.to_f == 0.0) attributes[:"transform+"] = "translate(#{(y ? [ x, y ] : [ x ]).join(" ")})" end end |