Module: Sevgi::Graphics::Mixtures::Transform

Defined in:
lib/sevgi/graphics/mixtures/transform.rb

Instance Method Summary collapse

Instance Method Details

#Align(position, inner:, outer:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 7

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

#FlipObject



18
19
20
21
22
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 18

def Flip
  tap do
    attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(-1, 1) scale(1, 1)"
  end
end

#FlipXObject



24
25
26
27
28
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 24

def FlipX
  tap do
    attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(-1, 1)"
  end
end

#FlipYObject



30
31
32
33
34
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 30

def FlipY
  tap do
    attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(1, -11)"
  end
end

#Matrix(*values) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 36

def Matrix(*values)
  tap do
    ArgumentError.("Incorrect transform matrix (six values required): #{values}") if values.size != 6

    next if values.map(&:to_f).all? { it == 0.0 }

    attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "matrix(#{values.join(" ")})"
  end
end

#Rotate(a, *origin) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 46

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

#Rotate09Object



60
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 60

def Rotate09(...) = Rotate(-90, ...)

#Rotate90Object



58
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 58

def Rotate90(...) = Rotate(90, ...)

#Scale(x, y = nil) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 62

def Scale(x, y = nil)
  tap do
    next if x.to_f == 0.0 && (y.nil? || y.to_f == 0.0)

    attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "scale(#{(y ? [x, y] : [x]).join(", ")})"
  end
end

#Scale!Object



70
71
72
73
74
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 70

def Scale!(...)
  Scale(...).tap do
    attributes[:"vector-effect"] = "non-scaling-stroke" unless attributes[:"vector-effect"]
  end
end

#Skew(ax, ay) ⇒ Object



76
77
78
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 76

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) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 80

def SkewX(a)
  tap do
    next if a.to_f == 0.0

    attributes[:"transform#{ATTRIBUTE_UPDATE_SUFFIX}"] = "skewX(#{a})"
  end
end

#SkewY(a) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 88

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) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/sevgi/graphics/mixtures/transform.rb', line 96

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