Class: DYI::Matrix
- Inherits:
-
Object
- Object
- DYI::Matrix
- Defined in:
- lib/dyi/matrix.rb,
lib/ironruby.rb
Overview
Instance Attribute Summary collapse
Class Method Summary collapse
- .identity ⇒ Object
- .rotate(angle) ⇒ Object
- .scale(sx, sy) ⇒ Object
- .skew_x(angle) ⇒ Object
- .skew_y(angle) ⇒ Object
- .translate(tx, ty) ⇒ Object
Instance Method Summary collapse
- #*(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(*args) ⇒ Matrix
constructor
:call-seq: new (xx, yx, xy, yy, x0, y0).
- #rotate(angle) ⇒ Object
- #scale(sx, xy) ⇒ Object
- #skew_x(angle) ⇒ Object
- #skew_y(angle) ⇒ Object
- #to_cls_matrix ⇒ Object
- #transform(coordinate) ⇒ Object
- #translate(tx, ty) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Matrix
:call-seq: new (xx, yx, xy, yy, x0, y0)
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
#x0 ⇒ Object
27 28 29 |
# File 'lib/dyi/matrix.rb', line 27 def x0 @x0 end |
#xx ⇒ Object
27 28 29 |
# File 'lib/dyi/matrix.rb', line 27 def xx @xx end |
#xy ⇒ Object
27 28 29 |
# File 'lib/dyi/matrix.rb', line 27 def xy @xy end |
#y0 ⇒ Object
27 28 29 |
# File 'lib/dyi/matrix.rb', line 27 def y0 @y0 end |
#yx ⇒ Object
27 28 29 |
# File 'lib/dyi/matrix.rb', line 27 def yx @yx end |
#yy ⇒ Object
27 28 29 |
# File 'lib/dyi/matrix.rb', line 27 def yy @yy end |
Class Method Details
.identity ⇒ Object
98 99 100 |
# File 'lib/dyi/matrix.rb', line 98 def identity new(1, 0, 0, 1, 0, 0) end |
.rotate(angle) ⇒ Object
110 111 112 |
# File 'lib/dyi/matrix.rb', line 110 def rotate(angle) new(:rotate, angle) end |
.scale(sx, sy) ⇒ Object
106 107 108 |
# File 'lib/dyi/matrix.rb', line 106 def scale(sx, sy) new(:scale, sx, sy) end |
.skew_x(angle) ⇒ Object
114 115 116 |
# File 'lib/dyi/matrix.rb', line 114 def skew_x(angle) new(:skewX, angle) end |
.skew_y(angle) ⇒ Object
118 119 120 |
# File 'lib/dyi/matrix.rb', line 118 def skew_y(angle) new(:skewY, angle) end |
.translate(tx, ty) ⇒ Object
102 103 104 |
# File 'lib/dyi/matrix.rb', line 102 def translate(tx, ty) new(:translate, tx, ty) end |
Instance Method Details
#*(other) ⇒ Object
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
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
80 81 82 |
# File 'lib/dyi/matrix.rb', line 80 def rotate(angle) self * Matrix.rotate(angle) end |
#scale(sx, xy) ⇒ Object
76 77 78 |
# File 'lib/dyi/matrix.rb', line 76 def scale(sx, xy) self * Matrix.scale(sx, xy) end |
#skew_x(angle) ⇒ Object
84 85 86 |
# File 'lib/dyi/matrix.rb', line 84 def skew_x(angle) self * Matrix.skew_x(angle) end |
#skew_y(angle) ⇒ Object
88 89 90 |
# File 'lib/dyi/matrix.rb', line 88 def skew_y(angle) self * Matrix.skew_y(angle) end |
#to_cls_matrix ⇒ Object
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
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 |