Module: Sevgi::Graphics::Mixtures::Transform
- Defined in:
- lib/sevgi/graphics/mixtures/transform.rb
Overview
DSL helpers for SVG transform attributes.
Instance Method Summary collapse
-
#Align(position, inner:, outer:) ⇒ Sevgi::Graphics::Element
Aligns an inner box inside an outer box.
-
#Flip ⇒ Sevgi::Graphics::Element
Appends a scale(-1, -1) transform.
-
#FlipX ⇒ Sevgi::Graphics::Element
Appends a horizontal flip transform.
-
#FlipY ⇒ Sevgi::Graphics::Element
Appends a vertical flip transform.
-
#Matrix(*values) ⇒ Sevgi::Graphics::Element
Appends a six-value SVG matrix transform.
-
#Rotate(a, *origin) ⇒ Sevgi::Graphics::Element
Appends an SVG rotate transform.
-
#RotateLeft(*origin) ⇒ Sevgi::Graphics::Element
Appends a -90-degree SVG rotate transform.
-
#RotateRight(*origin) ⇒ Sevgi::Graphics::Element
Appends a 90-degree SVG rotate transform.
-
#Scale(x, y = nil) ⇒ Sevgi::Graphics::Element
Appends an SVG scale transform.
-
#Skew(ax, ay) ⇒ Sevgi::Graphics::Element
Appends a skew transform through an SVG matrix.
-
#SkewX(a) ⇒ Sevgi::Graphics::Element
Appends an SVG skewX transform.
-
#SkewY(a) ⇒ Sevgi::Graphics::Element
Appends an SVG skewY transform.
-
#Translate(x, y = nil) ⇒ Sevgi::Graphics::Element
Appends an SVG translate transform.
Instance Method Details
#Align(position, inner:, outer:) ⇒ Sevgi::Graphics::Element
Aligns an inner box inside an outer box.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 14 def Align(position, inner:, outer:) return self unless position && inner && outer case position.to_sym when :center Translate((outer.width - inner.width) / 2.0, (outer.height - inner.height) / 2.0) else ArgumentError.("Unsupported alignment: #{position}") end end |
#Flip ⇒ Sevgi::Graphics::Element
Appends a scale(-1, -1) transform.
27 28 29 30 31 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 27 def Flip tap do attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(-1, -1)" end end |
#FlipX ⇒ Sevgi::Graphics::Element
Appends a horizontal flip transform.
35 36 37 38 39 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 35 def FlipX tap do attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(-1, 1)" end end |
#FlipY ⇒ Sevgi::Graphics::Element
Appends a vertical flip transform.
43 44 45 46 47 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 43 def FlipY tap do attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(1, -1)" end end |
#Matrix(*values) ⇒ Sevgi::Graphics::Element
Appends a six-value SVG matrix transform.
53 54 55 56 57 58 59 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 53 def Matrix(*values) tap do ArgumentError.("Incorrect transform matrix (six values required): #{values}") if values.size != 6 attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "matrix(#{values.join(" ")})" end end |
#Rotate(a, *origin) ⇒ Sevgi::Graphics::Element
Appends an SVG rotate transform.
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 66 def Rotate(a, *origin) tap do if !origin.empty? && origin.size != 2 ArgumentError.("Incorrect origin (two coordinates required): #{origin}") end next if a.to_f == 0.0 attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "rotate(#{[a, *origin].join(", ")})" end end |
#RotateLeft(*origin) ⇒ Sevgi::Graphics::Element
88 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 88 def RotateLeft(...) = Rotate(-90, ...) |
#RotateRight(*origin) ⇒ Sevgi::Graphics::Element
82 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 82 def RotateRight(...) = Rotate(90, ...) |
#Scale(x, y = nil) ⇒ Sevgi::Graphics::Element
Appends an SVG scale transform.
94 95 96 97 98 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 94 def Scale(x, y = nil) tap do attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(#{(y ? [x, y] : [x]).join(", ")})" end end |
#Skew(ax, ay) ⇒ Sevgi::Graphics::Element
Appends a skew transform through an SVG matrix.
104 105 106 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 104 def Skew(ax, ay) Matrix(1.0, ::Math.tan(ay / 180.0 * ::Math::PI), ::Math.tan(ax / 180.0 * ::Math::PI), 1.0, 0.0, 0.0) end |
#SkewX(a) ⇒ Sevgi::Graphics::Element
Appends an SVG skewX transform.
111 112 113 114 115 116 117 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 111 def SkewX(a) tap do next if a.to_f == 0.0 attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "skewX(#{a})" end end |
#SkewY(a) ⇒ Sevgi::Graphics::Element
Appends an SVG skewY transform.
122 123 124 125 126 127 128 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 122 def SkewY(a) tap do next if a.to_f == 0.0 attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "skewY(#{a})" end end |
#Translate(x, y = nil) ⇒ Sevgi::Graphics::Element
Appends an SVG translate transform.
134 135 136 137 138 139 140 |
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 134 def Translate(x, y = nil) tap do next if x.to_f == 0.0 && (y.nil? || y.to_f == 0.0) attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "translate(#{(y ? [x, y] : [x]).join(" ")})" end end |