Module: Magick::RVG::Transformable

Included in:
Magick::RVG, Group, Image, Use
Defined in:
lib/rvg/transformable.rb

Overview

Transformations are operations on the coordinate system. All the transformations defined within a container (an RVG object or a group) are applied before drawing any shapes or text. All transformations are applied in the order they were defined. Note: This means that

g.translate(10,20).scale(2)

is not the same as

g.scale(2).translate(10,20)

Instance Method Summary collapse

Instance Method Details

#matrix(sx, rx, ry, sy, tx, ty) {|_self| ... } ⇒ Object

Applies the transformation matrix [sx, rx, ry, sy, tx, ty]

Yields:

  • (_self)

Yield Parameters:



42
43
44
45
46
47
48
49
50
# File 'lib/rvg/transformable.rb', line 42

def matrix(sx, rx, ry, sy, tx, ty)
  begin
    @transforms << [:affine, [Float(sx), Float(rx), Float(ry), Float(sy), Float(tx), Float(ty)]]
  rescue ArgumentError
    raise ArgumentError, "arguments must be convertable to float (got #{sx.class}, #{rx.class}, #{ry.class}, #{sy.class}, #{sx.class}, #{sx.class}, #{tx.class}, #{ty.class})"
  end
  yield(self) if block_given?
  self
end

#rotate(angle, *args) {|_self| ... } ⇒ Object

This method can take either of two argument lists:

rotate(angle)

rotate by angle degrees

rotate(angle, cx, cy)

rotate by angle degrees about the point [cx, cy].

Yields:

  • (_self)

Yield Parameters:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rvg/transformable.rb', line 83

def rotate(angle, *args)
  begin
    case args.length
    when 0
      @transforms << [:rotate, [Float(angle)]]
    when 2
      cx = Float(args[0])
      cy = Float(args[1])
      @transforms << [:translate, [cx, cy]]
      @transforms << [:rotate, [Float(angle)]]
      @transforms << [:translate, [-cx, -cy]]
    else
      raise ArgumentError, "wrong number of arguments (#{args.length} for 1 or 3)"
    end
  rescue ArgumentError
    raise ArgumentError, "arguments must be convertable to float (got #{[angle, *args].map(&:class).join(', ')})"
  end
  yield(self) if block_given?
  self
end

#scale(sx, sy = nil) {|_self| ... } ⇒ Object

Multiply the x-coordinates by sx and the y-coordinates by sy. If sy is omitted it defaults to sx.

Yields:

  • (_self)

Yield Parameters:



68
69
70
71
72
73
74
75
76
77
# File 'lib/rvg/transformable.rb', line 68

def scale(sx, sy = nil)
  sy ||= sx
  begin
    @transforms << [:scale, [Float(sx), Float(sy)]]
  rescue ArgumentError
    raise ArgumentError, "arguments must be convertable to float (got #{sx.class}, #{sy.class})"
  end
  yield(self) if block_given?
  self
end

#skewX(angle) {|_self| ... } ⇒ Object

Skew the X-axis by angle degrees.

Yields:

  • (_self)

Yield Parameters:



105
106
107
108
109
110
111
112
113
# File 'lib/rvg/transformable.rb', line 105

def skewX(angle)
  begin
    @transforms << [:skewx, [Float(angle)]]
  rescue ArgumentError
    raise ArgumentError, "argument must be convertable to float (got #{angle.class})"
  end
  yield(self) if block_given?
  self
end

#skewY(angle) {|_self| ... } ⇒ Object

Skew the Y-axis by angle degrees.

Yields:

  • (_self)

Yield Parameters:



116
117
118
119
120
121
122
123
124
# File 'lib/rvg/transformable.rb', line 116

def skewY(angle)
  begin
    @transforms << [:skewy, [Float(angle)]]
  rescue ArgumentError
    raise ArgumentError, "argument must be convertable to float (got #{angle.class})"
  end
  yield(self) if block_given?
  self
end

#translate(tx, ty = nil) {|_self| ... } ⇒ Object

Add tx to all x-coordinates and ty to all y-coordinates. If ty is omitted it defaults to tx.

Yields:

  • (_self)

Yield Parameters:



55
56
57
58
59
60
61
62
63
64
# File 'lib/rvg/transformable.rb', line 55

def translate(tx, ty = nil)
  ty ||= tx
  begin
    @transforms << [:translate, [Float(tx), Float(ty)]]
  rescue ArgumentError
    raise ArgumentError, "arguments must be convertable to float (got #{tx.class}, #{ty.class})"
  end
  yield(self) if block_given?
  self
end