Class: DYI::Matrix

Inherits:
Object
  • Object
show all
Defined in:
lib/dyi/matrix.rb,
lib/ironruby.rb

Overview

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Matrix

:call-seq: new (xx, yx, xy, yy, x0, y0)

Since:

  • 1.0.0



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dyi/matrix.rb', line 32

def initialize(*args)
  case args.first
  when :translate
    @xx = @yy = 1
    @xy = @yx = 0
    @x0 = args[1]
    @y0 = args[2] || 0
  when :scale
    @xx = args[1]
    @yy = args[2] || args[1]
    @xy = @yx = @x0 = @y0 = 0
  when :rotate
    @xx = @yy = DYI::Util.cos(args[1])
    @xy = -(@yx = DYI::Util.sin(args[1]))
    @x0 = @y0 = 0
  when :skewX
    @xx = @yy = 1
    @xy = DYI::Util.tan(args[1])
    @yx = @x0 = @y0 = 0
  when :skewY
    @xx = @yy = 1
    @yx = DYI::Util.tan(args[1])
    @xy = @x0 = @y0 = 0
  else
    raise ArgumentError unless args.size == 6
    @xx, @yx, @xy, @yy, @x0, @y0 = args
  end
end

Instance Attribute Details

#x0Object

Since:

  • 1.0.0



27
28
29
# File 'lib/dyi/matrix.rb', line 27

def x0
  @x0
end

#xxObject

Since:

  • 1.0.0



27
28
29
# File 'lib/dyi/matrix.rb', line 27

def xx
  @xx
end

#xyObject

Since:

  • 1.0.0



27
28
29
# File 'lib/dyi/matrix.rb', line 27

def xy
  @xy
end

#y0Object

Since:

  • 1.0.0



27
28
29
# File 'lib/dyi/matrix.rb', line 27

def y0
  @y0
end

#yxObject

Since:

  • 1.0.0



27
28
29
# File 'lib/dyi/matrix.rb', line 27

def yx
  @yx
end

#yyObject

Since:

  • 1.0.0



27
28
29
# File 'lib/dyi/matrix.rb', line 27

def yy
  @yy
end

Class Method Details

.identityObject

Since:

  • 1.0.0



98
99
100
# File 'lib/dyi/matrix.rb', line 98

def identity
  new(1, 0, 0, 1, 0, 0)
end

.rotate(angle) ⇒ Object

Since:

  • 1.0.0



110
111
112
# File 'lib/dyi/matrix.rb', line 110

def rotate(angle)
  new(:rotate, angle)
end

.scale(sx, sy) ⇒ Object

Since:

  • 1.0.0



106
107
108
# File 'lib/dyi/matrix.rb', line 106

def scale(sx, sy)
  new(:scale, sx, sy)
end

.skew_x(angle) ⇒ Object

Since:

  • 1.0.0



114
115
116
# File 'lib/dyi/matrix.rb', line 114

def skew_x(angle)
  new(:skewX, angle)
end

.skew_y(angle) ⇒ Object

Since:

  • 1.0.0



118
119
120
# File 'lib/dyi/matrix.rb', line 118

def skew_y(angle)
  new(:skewY, angle)
end

.translate(tx, ty) ⇒ Object

Since:

  • 1.0.0



102
103
104
# File 'lib/dyi/matrix.rb', line 102

def translate(tx, ty)
  new(:translate, tx, ty)
end

Instance Method Details

#*(other) ⇒ Object

Since:

  • 1.0.0



61
62
63
64
65
66
# File 'lib/dyi/matrix.rb', line 61

def *(other)
  self.class.new(
    xx * other.xx + xy * other.yx,      yx * other.xx + yy * other.yx,
    xx * other.xy + xy * other.yy,      yx * other.xy + yy * other.yy,
    xx * other.x0 + xy * other.y0 + x0, yx * other.x0 + yy * other.y0 + y0)
end

#==(other) ⇒ Object

Since:

  • 1.0.0



68
69
70
# File 'lib/dyi/matrix.rb', line 68

def ==(other)
  xx == other.xx && yx == other.yx && xy == other.xy && yy == other.yy && x0 == other.x0 && y0 == other.y0
end

#rotate(angle) ⇒ Object

Since:

  • 1.0.0



80
81
82
# File 'lib/dyi/matrix.rb', line 80

def rotate(angle)
  self * Matrix.rotate(angle)
end

#scale(sx, xy) ⇒ Object

Since:

  • 1.0.0



76
77
78
# File 'lib/dyi/matrix.rb', line 76

def scale(sx, xy)
  self * Matrix.scale(sx, xy)
end

#skew_x(angle) ⇒ Object

Since:

  • 1.0.0



84
85
86
# File 'lib/dyi/matrix.rb', line 84

def skew_x(angle)
  self * Matrix.skew_x(angle)
end

#skew_y(angle) ⇒ Object

Since:

  • 1.0.0



88
89
90
# File 'lib/dyi/matrix.rb', line 88

def skew_y(angle)
  self * Matrix.skew_y(angle)
end

#to_cls_matrixObject

Since:

  • 0.0.0



131
132
133
# File 'lib/ironruby.rb', line 131

def to_cls_matrix
  System::Drawing::Drawing2D::Matrix.new(xx, yx, xy, yy, x0, y0)
end

#transform(coordinate) ⇒ Object

Since:

  • 1.0.0



92
93
94
# File 'lib/dyi/matrix.rb', line 92

def transform(coordinate)
  Coordinate.new(coordinate.x * @xx + coordinate.y * @xy + @x0, coordinate.x * @yx + coordinate.y * @yy + @y0)
end

#translate(tx, ty) ⇒ Object

Since:

  • 1.0.0



72
73
74
# File 'lib/dyi/matrix.rb', line 72

def translate(tx, ty)
  self * Matrix.translate(tx, ty)
end