avm2: Implement all remaining matrix methods

This commit is contained in:
onkrot 2022-08-22 19:33:52 +05:00 committed by Adrian Wielgosik
parent 86e6983943
commit 1a243bdd86
6 changed files with 1256 additions and 0 deletions

View File

@ -1,4 +1,7 @@
package flash.geom {
import flash.geom.Point;
import flash.geom.Vector3D;
public class Matrix {
public var a:Number;
public var b:Number;
@ -16,6 +19,103 @@ package flash.geom {
this.ty = ty;
}
public function clone():Matrix {
return new Matrix(this.a,this.b,this.c,this.d,this.tx,this.ty);
}
public function concat(m:Matrix):void {
var a = m.a * this.a + m.c * this.b;
var b = m.b * this.a + m.d * this.b;
var c = m.a * this.c + m.c * this.d;
var d = m.b * this.c + m.d * this.d;
var tx = m.a * this.tx + m.c * this.ty + m.tx;
var ty = m.b * this.tx + m.d * this.ty + m.ty;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
}
public function copyColumnFrom(column:uint, vector3D:Vector3D):void {
// FP BUG: For some reason these methods are identical
this.copyRowFrom(column, vector3D);
}
public function copyColumnTo(column:uint, vector3D:Vector3D):void {
if(column == 0) {
vector3D.x = this.a;
vector3D.y = this.b;
vector3D.z = 0;
}
else if (column == 1) {
vector3D.x = this.c;
vector3D.y = this.d;
vector3D.z = 0;
}
else if (column == 2) {
vector3D.x = this.tx;
vector3D.y = this.ty;
vector3D.z = 1;
} // otherwise vector is unchanged
}
public function copyFrom(sourceMatrix: Matrix): void {
this.a = sourceMatrix.a;
this.b = sourceMatrix.b;
this.c = sourceMatrix.c;
this.d = sourceMatrix.d;
this.tx = sourceMatrix.tx;
this.ty = sourceMatrix.ty;
}
public function copyRowFrom(row: uint, vector3D: Vector3D): void {
if (row == 0) {
this.a = vector3D.x;
this.c = vector3D.y;
this.tx = vector3D.z;
} else if(row == 1) {
this.b = vector3D.x;
this.d = vector3D.y;
this.ty = vector3D.z;
} // otherwise matrix is unchanged
}
public function copyRowTo(row:uint, vector3D:Vector3D):void {
if(row == 0) {
vector3D.x = this.a;
vector3D.y = this.c;
vector3D.z = this.tx;
}
else if (row == 1) {
vector3D.x = this.b;
vector3D.y = this.d;
vector3D.z = this.ty;
}
else if (row == 2) {
vector3D.x = 0;
vector3D.y = 0;
vector3D.z = 1;
} // otherwise vector is unchanged
}
public function createBox(scaleX:Number, scaleY:Number, rotation:Number = 0, tx:Number = 0, ty:Number = 0):void {
this.identity();
this.rotate(rotation);
this.scale(scaleX, scaleY);
this.translate(tx, ty);
}
public function createGradientBox(width: Number, height: Number, rotation: Number = 0, tx: Number = 0, ty: Number = 0): void {
this.createBox(width / 1638.4, height / 1638.4, rotation, tx + width / 2, ty + height / 2);
}
public function deltaTransformPoint(point:Point):Point {
return new Point(this.a * point.x + this.c * point.y, this.b * point.x + this.d * point.y);
}
public function identity():void {
this.a = 1;
this.b = 0;
@ -25,13 +125,71 @@ package flash.geom {
this.ty = 0;
}
public function invert():void {
var det = this.a * this.d - this.c * this.b;
var tx = (this.d * this.tx - this.c * this.ty) / -det;
var ty = (this.b * this.tx - this.a * this.ty) / det;
var a = this.d / det;
var b = this.b / -det;
var c = this.c / -det;
var d = this.a / det;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
}
public function rotate(angle:Number):void {
var sin = Math.sin(angle);
var cos = Math.cos(angle);
var a = cos * this.a + (-sin) * this.b;
var b = sin * this.a + cos * this.b;
var c = cos * this.c + (-sin) * this.d;
var d = sin * this.c + cos * this.d;
var tx = cos * this.tx + (-sin) * this.ty;
var ty = sin * this.tx + cos * this.ty;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
}
public function scale(sx:Number, sy:Number):void {
this.a *= sx;
this.b *= sy;
this.c *= sx;
this.d *= sy;
this.tx *= sx;
this.ty *= sy;
}
public function setTo(aa:Number, ba:Number, ca:Number, da:Number, txa:Number, tya:Number):void {
this.a = aa;
this.b = ba;
this.c = ca;
this.d = da;
this.tx = txa;
this.ty = tya;
}
public function toString():String {
return "(a=" + this.a + ", b=" + this.b + ", c=" + this.c + ", d=" + this.d + ", tx=" + this.tx + ", ty=" + this.ty + ")";
}
public function transformPoint(point:Point):Point {
return new Point(this.a * point.x + this.c * point.y + this.tx, this.b * point.x + this.d * point.y + this.ty);
}
public function translate(dx:Number, dy:Number):void {
this.tx += dx;
this.ty += dy;
}
}
}

View File

@ -842,6 +842,9 @@ swf_tests_approx! {
(as3_edittext_tab_stops, "avm2/edittext_tab_stops", 1, epsilon = 5.0),
(as3_edittext_underline, "avm2/edittext_underline", 1, epsilon = 4.0),
(as3_math, "avm2/math", 1, max_relative = 30.0 * f64::EPSILON),
(as3_matrix, "avm2/matrix", 1, @num_patterns = &[
Regex::new(r"\(a=(.+?), b=(.+?), c=(.+?), d=(.+?), tx=(.+?), ty=(.+?)\)").unwrap()
], max_relative = f32::EPSILON as f64),
(as3_number_toexponential, "avm2/number_toexponential", 1, max_relative = 0.001),
(as3_number_tofixed, "avm2/number_tofixed", 1, max_relative = 0.001),
(as3_number_toprecision, "avm2/number_toprecision", 1, max_relative = 0.001),

View File

@ -0,0 +1,755 @@
package {
public class Test {
}
}
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Vector3D;
trace("new matrix", new Matrix());
trace("new Matrix(1)", new Matrix(1));
trace("new Matrix(1, 2)", new Matrix(1, 2));
trace("new Matrix(1, 2, 3)", new Matrix(1, 2, 3));
trace("new Matrix(1, 2, 3, 4)", new Matrix(1, 2, 3, 4));
trace("new Matrix(1, 2, 3, 4, 5)", new Matrix(1, 2, 3, 4, 5));
trace("new Matrix(1, 2, 3, 4, 5, 6)", new Matrix(1, 2, 3, 4, 5, 6));
// cannot use NaN values with approximate tester
// var temp = {}; // to please the compiler
// trace("// new Matrix(1, 2, 3, {})");
// trace(new Matrix(1, 2, 3, temp));
trace("");
trace("// new Matrix(1, 2, 3, 4, 5, 6) .identity()");
var matrix = new Matrix(1, 2, 3, 4, 5, 6);
matrix.identity();
trace(matrix);
trace("");
trace("");
trace("/// Clones");
matrix = new Matrix(1, 2, 3, 4, 5, 6);
var cloned = matrix.clone();
trace("// matrix");
trace(matrix);
trace("");
trace("// cloned");
trace(cloned);
trace("");
trace("// matrix === cloned");
trace(matrix === cloned);
trace("");
trace("");
// cannot use NaN values with approximate tester
// var temp = {};
// matrix = new Matrix(1, 2, temp, 4, 5, 6);
// cloned = matrix.clone();
// trace("// matrix");
// trace(matrix);
// trace("");
trace("// cloned");
trace(cloned);
trace("");
trace("// matrix === cloned");
trace(matrix === cloned);
trace("");
trace("");
trace("/// scale");
trace("// matrix");
matrix = new Matrix();
trace(matrix);
trace("");
trace("// matrix.scale(3, 5)");
matrix.scale(3, 5);
trace(matrix);
trace("");
trace("");
trace("// matrix");
matrix = new Matrix(2, 0, 0, 2, 100, 100);
trace(matrix);
trace("");
trace("// matrix.scale(7, 11)");
matrix.scale(7, 11);
trace(matrix);
trace("");
trace("");
trace("// matrix");
matrix = new Matrix(1, 2, 3, 4, 5, 6);
trace(matrix);
trace("");
trace("// matrix.scale(13, 17)");
matrix.scale(13, 17);
trace(matrix);
trace("");
trace("");
trace("/// rotate");
matrix = new Matrix();
trace(matrix);
trace("");
trace("// matrix.rotate(0)");
matrix.rotate(0);
trace(matrix);
trace("");
trace("");
trace("/// rotate");
trace("// matrix");
matrix = new Matrix();
trace(matrix);
trace("");
trace("// matrix.rotate(0.5)");
matrix.rotate(0.5);
trace(matrix);
trace("");
trace("");
trace("// matrix");
matrix = new Matrix(1, 2, 3, 4, 5, 6);
trace(matrix);
trace("");
trace("// matrix.rotate(0)");
matrix.rotate(0);
trace(matrix);
trace("");
trace("");
trace("// matrix");
matrix = new Matrix(1, 2, 3, 4, 5, 6);
trace(matrix);
trace("");
trace("// matrix.rotate((90/180)*Math.PI)");
matrix.rotate((90/180)*Math.PI);
trace(matrix);
trace("");
trace("");
trace("/// translate");
trace("// matrix");
matrix = new Matrix();
trace("// matrix.translate(3, 5)");
matrix.translate(3, 5);
trace(matrix);
trace("");
trace("");
trace("// matrix");
matrix = new Matrix(2, 0, 0, 2, 100, 100);
trace("// matrix.translate(7, 11)");
matrix.translate(7, 11);
trace(matrix);
trace("");
trace("");
trace("/// concat");
var scale = new Matrix();
scale.scale(3, 5);
var translate = new Matrix();
translate.translate(7, 9);
var rotate = new Matrix();
rotate.rotate(Math.PI / 2);
matrix = new Matrix(11, 13, 17, 19, 23, 29);
trace("matrix:", matrix);
trace("scale(3, 5):", scale);
trace("translate(7, 9):", translate);
trace("rotate(Math.PI / 2):", rotate);
trace("");
var result = matrix.clone();
trace("//double transform");
result = scale.clone();
result.concat(translate);
trace("//scale + translate", result);
result = translate.clone();
result.concat(scale);
trace("//translate + scale", result);
result = scale.clone();
result.concat(rotate);
trace("//scale + rotate", result);
result = rotate.clone();
result.concat(scale);
trace("//rotate + scale", result);
result = translate.clone();
result.concat(rotate);
trace("//translate + rotate", result);
result = rotate.clone();
result.concat(translate);
trace("//rotate + translate", result);
trace("");
trace("//triple transform");
result = scale.clone();
result.concat(translate);
result.concat(rotate);
trace("//scale + translate + rotate", result);
result = scale.clone();
result.concat(rotate);
result.concat(translate);
trace("//scale + rotate + translate", result);
result = translate.clone();
result.concat(scale);
result.concat(rotate);
trace("//translate + scale + rotate", result);
result = translate.clone();
result.concat(rotate);
result.concat(scale);
trace("//translate + rotate + scale", result);
result = rotate.clone();
result.concat(translate);
result.concat(scale);
trace("//rotate + translate + scale", result);
result = rotate.clone();
result.concat(scale);
result.concat(translate);
trace("//rotate + scale + translate", result);
trace("");
trace("//right application");
trace("");
trace("//single transform");
result = matrix.clone();
result.concat(scale);
trace("//matrix + scale", result);
result = matrix.clone();
result.concat(translate);
trace("//matrix + translate", result);
result = matrix.clone();
result.concat(rotate);
trace("//matrix + rotate", result);
trace("");
trace("//double transform");
result = matrix.clone();
result.concat(scale);
result.concat(translate);
trace("//matrix + scale + translate", result);
result = matrix.clone();
result.concat(translate);
result.concat(scale);
trace("//matrix + translate + scale", result);
result = matrix.clone();
result.concat(scale);
result.concat(rotate);
trace("//matrix + scale + rotate", result);
result = matrix.clone();
result.concat(rotate);
result.concat(scale);
trace("//matrix + rotate + scale", result);
result = matrix.clone();
result.concat(translate);
result.concat(rotate);
trace("//matrix + translate + rotate", result);
result = matrix.clone();
result.concat(rotate);
result.concat(translate);
trace("//matrix + rotate + translate", result);
trace("");
trace("//triple transform");
result = matrix.clone();
result.concat(scale);
result.concat(translate);
result.concat(rotate);
trace("//matrix + scale + translate + rotate", result);
result = matrix.clone();
result.concat(scale);
result.concat(rotate);
result.concat(translate);
trace("//matrix + scale + rotate + translate", result);
result = matrix.clone();
result.concat(translate);
result.concat(scale);
result.concat(rotate);
trace("//matrix + translate + scale + rotate", result);
result = matrix.clone();
result.concat(translate);
result.concat(rotate);
result.concat(scale);
trace("//matrix + translate + rotate + scale", result);
result = matrix.clone();
result.concat(rotate);
result.concat(translate);
result.concat(scale);
trace("//matrix + rotate + translate + scale", result);
result = matrix.clone();
result.concat(rotate);
result.concat(scale);
result.concat(translate);
trace("//matrix + rotate + scale + translate", result);
trace("");
trace("//left application");
trace("");
trace("//single transform");
result = scale.clone();
result.concat(matrix);
trace("//scale + matrix", result);
result = translate.clone();
result.concat(matrix);
trace("//translate + matrix", result);
result = rotate.clone();
result.concat(matrix);
trace("//rotate + matrix", result);
trace("");
trace("//double transform");
result = scale.clone();
result.concat(translate);
result.concat(matrix);
trace("//scale + translate + matrix", result);
result = translate.clone();
result.concat(scale);
result.concat(matrix);
trace("//translate + scale + matrix", result);
result = scale.clone();
result.concat(rotate);
result.concat(matrix);
trace("//scale + rotate + matrix", result);
result = rotate.clone();
result.concat(scale);
result.concat(matrix);
trace("//rotate + scale + matrix", result);
result = translate.clone();
result.concat(rotate);
result.concat(matrix);
trace("//translate + rotate + matrix", result);
result = rotate.clone();
result.concat(translate);
result.concat(matrix);
trace("//rotate + translate + matrix", result);
trace("");
trace("//triple transform");
result = scale.clone();
result.concat(translate);
result.concat(rotate);
result.concat(matrix);
trace("//scale + translate + rotate + matrix", result);
result = scale.clone();
result.concat(rotate);
result.concat(translate);
result.concat(matrix);
trace("//scale + rotate + translate + matrix", result);
result = translate.clone();
result.concat(scale);
result.concat(rotate);
result.concat(matrix);
trace("//translate + scale + rotate + matrix", result);
result = translate.clone();
result.concat(rotate);
result.concat(scale);
result.concat(matrix);
trace("//translate + rotate + scale + matrix", result);
result = rotate.clone();
result.concat(translate);
result.concat(scale);
result.concat(matrix);
trace("//rotate + translate + scale + matrix", result);
result = rotate.clone();
result.concat(scale);
result.concat(translate);
result.concat(matrix);
trace("//rotate + scale + translate + matrix", result);
trace("");
trace("//middle application");
trace("");
trace("//double transform");
result = scale.clone();
result.concat(matrix);
result.concat(translate);
trace("//scale + matrix + translate", result);
result = translate.clone();
result.concat(matrix);
result.concat(scale);
trace("//translate + matrix + scale", result);
result = scale.clone();
result.concat(matrix);
result.concat(rotate);
trace("//scale + matrix + rotate", result);
result = rotate.clone();
result.concat(matrix);
result.concat(scale);
trace("//rotate + matrix + scale", result);
result = translate.clone();
result.concat(matrix);
result.concat(rotate);
trace("//translate + matrix + rotate", result);
result = rotate.clone();
result.concat(matrix);
result.concat(translate);
trace("//rotate + matrix + translate", result);
trace("");
trace("//triple transform #1");
result = scale.clone();
result.concat(matrix);
result.concat(translate);
result.concat(rotate);
trace("//scale + matrix + translate + rotate", result);
result = scale.clone();
result.concat(matrix);
result.concat(rotate);
result.concat(translate);
trace("//scale + matrix + rotate + translate", result);
result = translate.clone();
result.concat(matrix);
result.concat(scale);
result.concat(rotate);
trace("//translate + matrix + scale + rotate", result);
result = translate.clone();
result.concat(matrix);
result.concat(rotate);
result.concat(scale);
trace("//translate + matrix + rotate + scale", result);
result = rotate.clone();
result.concat(matrix);
result.concat(translate);
result.concat(scale);
trace("//rotate + matrix + translate + scale", result);
result = rotate.clone();
result.concat(matrix);
result.concat(scale);
result.concat(translate);
trace("//rotate + matrix + scale + translate", result);
trace("");
trace("//triple transform #2");
result = scale.clone();
result.concat(translate);
result.concat(matrix);
result.concat(rotate);
trace("//scale + translate + matrix + rotate", result);
result = scale.clone();
result.concat(rotate);
result.concat(matrix);
result.concat(translate);
trace("//scale + rotate + matrix + translate", result);
result = translate.clone();
result.concat(scale);
result.concat(matrix);
result.concat(rotate);
trace("//translate + scale + matrix + rotate", result);
result = translate.clone();
result.concat(rotate);
result.concat(matrix);
result.concat(scale);
trace("//translate + rotate + matrix + scale", result);
result = rotate.clone();
result.concat(translate);
result.concat(matrix);
result.concat(scale);
trace("//rotate + translate + matrix + scale", result);
result = rotate.clone();
result.concat(scale);
result.concat(matrix);
result.concat(translate);
trace("//rotate + scale + matrix + translate", result);
trace("");
trace("");
trace("/// invert");
trace("// matrix");
matrix = new Matrix();
trace(matrix);
trace("");
trace("// matrix.invert()");
matrix.invert();
trace(matrix);
trace("");
trace("");
trace("// matrix");
matrix = new Matrix(2, 3, 5, 7, 9, 11);
trace(matrix);
trace("");
trace("// matrix.invert()");
matrix.invert();
trace(matrix);
trace("");
trace("");
trace("/// createBox");
trace("// matrix = new Matrix();");
matrix = new Matrix();
trace(matrix);
trace("");
trace("// matrix.createBox(2, 3)");
matrix.createBox(2, 3);
trace(matrix);
trace("");
trace("// matrix.createBox(2, 3, 0)");
matrix.createBox(2, 3, 0);
trace(matrix);
trace("");
trace("// matrix.createBox(2, 3, 5)");
matrix.createBox(2, 3, 5);
trace(matrix);
trace("");
trace("// matrix.createBox(2, 3, 5, 7)");
matrix.createBox(2, 3, 5, 7);
trace(matrix);
trace("");
trace("// matrix.createBox(2, 3, 5, 7, 9)");
matrix.createBox(2, 3, 5, 7, 9);
trace(matrix);
trace("");
trace("");
trace("/// createGradientBox");
trace("// matrix = new Matrix();");
matrix = new Matrix();
trace(matrix);
trace("");
trace("// matrix.createGradientBox(200, 300)");
matrix.createGradientBox(200, 300);
trace(matrix);
trace("");
trace("// matrix.createGradientBox(200, 300, 0)");
matrix.createGradientBox(200, 300, 0);
trace(matrix);
trace("");
trace("// matrix.createGradientBox(200, 300, 500)");
matrix.createGradientBox(200, 300, 500);
trace(matrix);
trace("");
trace("// matrix.createGradientBox(200, 300, 500, 700)");
matrix.createGradientBox(200, 300, 500, 700);
trace(matrix);
trace("");
trace("// matrix.createGradientBox(200, 300, 500, 700, 900)");
matrix.createGradientBox(200, 300, 500, 700, 900);
trace(matrix);
trace("");
trace("");
trace("/// transformPoint");
trace("// matrix = new Matrix(2, 3, 5, 7, 11, 13);");
matrix = new Matrix(2, 3, 5, 7, 11, 13);
trace(matrix);
trace("");
trace("// matrix.transformPoint(new Point(1, 1));");
trace(matrix.transformPoint(new Point(1, 1)));
trace("");
trace("");
trace("/// deltaTransformPoint");
trace("// matrix = new Matrix(2, 3, 5, 7, 11, 13);");
matrix = new Matrix(2, 3, 5, 7, 11, 13);
trace(matrix);
trace("");
trace("// matrix.deltaTransformPoint(new Point(1, 1));");
trace(matrix.deltaTransformPoint(new Point(1, 1)));
trace("");
trace("");
trace("/// copyFrom");
trace("// matrix = new Matrix(2, 3, 5, 7, 11, 13);");
matrix = new Matrix(2, 3, 5, 7, 11, 13);
trace(matrix);
trace("// matrix2 = new Matrix();");
var matrix2 = new Matrix();
trace(matrix2);
trace("");
trace("// matrix2.copyFrom(matrix);");
matrix2.copyFrom(matrix);
trace(matrix2);
trace("");
trace("");
trace("/// setTo");
trace("// matrix = new Matrix();");
matrix = new Matrix();
trace(matrix);
trace("");
trace("// matrix.setTo(2, 3, 5, 7, 11, 13);");
matrix.setTo(2, 3, 5, 7, 11, 13);
trace(matrix);
trace("");
trace("");
trace("/// copyRowTo");
trace("// matrix = new Matrix(2, 3, 5, 7, 11, 13);");
matrix = new Matrix(2, 3, 5, 7, 11, 13);
trace("// vector = new Vector3D(1,2,3,4);");
var vector = new Vector3D(1,2,3,4);
trace(matrix);
trace(vector);
trace("");
trace("// matrix.copyRowTo(0, vector);");
matrix.copyRowTo(0, vector);
trace(vector);
trace("// matrix.copyRowTo(1, vector);");
matrix.copyRowTo(1, vector);
trace(vector);
trace("// matrix.copyRowTo(2, vector);");
matrix.copyRowTo(2, vector);
trace(vector);
trace("// matrix.copyRowTo(3, vector);");
matrix.copyRowTo(3, vector);
trace(vector);
trace("");
trace("");
trace("/// copyColumnTo");
trace("// matrix = new Matrix(2, 3, 5, 7, 11, 13);");
matrix = new Matrix(2, 3, 5, 7, 11, 13);
trace("// vector = new Vector3D(1,2,3,4);");
var vector = new Vector3D(1,2,3,4);
trace(matrix);
trace(vector);
trace("");
trace("// matrix.copyColumnTo(0, vector);");
matrix.copyColumnTo(0, vector);
trace(vector);
trace("// matrix.copyColumnTo(1, vector);");
matrix.copyColumnTo(1, vector);
trace(vector);
trace("// matrix.copyColumnTo(2, vector);");
matrix.copyColumnTo(2, vector);
trace(vector);
trace("// matrix.copyColumnTo(3, vector);");
matrix.copyColumnTo(3, vector);
trace(vector);
trace("");
trace("");
trace("/// copyRowFrom");
trace("// matrix = new Matrix(2, 3, 5, 7, 11, 13);");
matrix = new Matrix(2, 3, 5, 7, 11, 13);
trace("// vector = new Vector3D(17,19,23,29);");
var vector = new Vector3D(17,19,23,29);
trace(matrix);
trace(vector);
trace("");
trace("// matrix.copyRowFrom(0, vector);");
matrix.copyRowFrom(0, vector);
trace(matrix);
trace("// matrix.copyRowFrom(1, vector);");
matrix.copyRowFrom(1, vector);
trace(matrix);
trace("// matrix.copyRowFrom(2, vector);");
matrix.copyRowFrom(2, vector);
trace(matrix);
trace("// matrix.copyRowFrom(3, vector);");
matrix.copyRowFrom(3, vector);
trace(matrix);
trace("");
trace("");
trace("/// copyColumnFrom");
trace("// matrix = new Matrix(2, 3, 5, 7, 11, 13);");
matrix = new Matrix(2, 3, 5, 7, 11, 13);
trace("// vector = new Vector3D(17,19,23,29);");
var vector = new Vector3D(17,19,23,29);
trace(matrix);
trace(vector);
trace("");
trace("// matrix.copyColumnFrom(0, vector);");
matrix.copyColumnFrom(0, vector);
trace(matrix);
trace("// matrix.copyColumnFrom(1, vector);");
matrix.copyColumnFrom(1, vector);
trace(matrix);
trace("// matrix.copyColumnFrom(2, vector);");
matrix.copyColumnFrom(2, vector);
trace(matrix);
trace("// matrix.copyColumnFrom(3, vector);");
matrix.copyColumnFrom(3, vector);
trace(matrix);
trace("");
trace("");

View File

@ -0,0 +1,340 @@
new matrix (a=1, b=0, c=0, d=1, tx=0, ty=0)
new Matrix(1) (a=1, b=0, c=0, d=1, tx=0, ty=0)
new Matrix(1, 2) (a=1, b=2, c=0, d=1, tx=0, ty=0)
new Matrix(1, 2, 3) (a=1, b=2, c=3, d=1, tx=0, ty=0)
new Matrix(1, 2, 3, 4) (a=1, b=2, c=3, d=4, tx=0, ty=0)
new Matrix(1, 2, 3, 4, 5) (a=1, b=2, c=3, d=4, tx=5, ty=0)
new Matrix(1, 2, 3, 4, 5, 6) (a=1, b=2, c=3, d=4, tx=5, ty=6)
// new Matrix(1, 2, 3, 4, 5, 6) .identity()
(a=1, b=0, c=0, d=1, tx=0, ty=0)
/// Clones
// matrix
(a=1, b=2, c=3, d=4, tx=5, ty=6)
// cloned
(a=1, b=2, c=3, d=4, tx=5, ty=6)
// matrix === cloned
false
// cloned
(a=1, b=2, c=3, d=4, tx=5, ty=6)
// matrix === cloned
false
/// scale
// matrix
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix.scale(3, 5)
(a=3, b=0, c=0, d=5, tx=0, ty=0)
// matrix
(a=2, b=0, c=0, d=2, tx=100, ty=100)
// matrix.scale(7, 11)
(a=14, b=0, c=0, d=22, tx=700, ty=1100)
// matrix
(a=1, b=2, c=3, d=4, tx=5, ty=6)
// matrix.scale(13, 17)
(a=13, b=34, c=39, d=68, tx=65, ty=102)
/// rotate
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix.rotate(0)
(a=1, b=0, c=0, d=1, tx=0, ty=0)
/// rotate
// matrix
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix.rotate(0.5)
(a=0.8775825618903728, b=0.479425538604203, c=-0.479425538604203, d=0.8775825618903728, tx=0, ty=0)
// matrix
(a=1, b=2, c=3, d=4, tx=5, ty=6)
// matrix.rotate(0)
(a=1, b=2, c=3, d=4, tx=5, ty=6)
// matrix
(a=1, b=2, c=3, d=4, tx=5, ty=6)
// matrix.rotate((90/180)*Math.PI)
(a=-2, b=1.0000000000000002, c=-4, d=3.0000000000000004, tx=-6, ty=5)
/// translate
// matrix
// matrix.translate(3, 5)
(a=1, b=0, c=0, d=1, tx=3, ty=5)
// matrix
// matrix.translate(7, 11)
(a=2, b=0, c=0, d=2, tx=107, ty=111)
/// concat
matrix: (a=11, b=13, c=17, d=19, tx=23, ty=29)
scale(3, 5): (a=3, b=0, c=0, d=5, tx=0, ty=0)
translate(7, 9): (a=1, b=0, c=0, d=1, tx=7, ty=9)
rotate(Math.PI / 2): (a=6.123233995736766e-17, b=1, c=-1, d=6.123233995736766e-17, tx=0, ty=0)
//double transform
//scale + translate (a=3, b=0, c=0, d=5, tx=7, ty=9)
//translate + scale (a=3, b=0, c=0, d=5, tx=21, ty=45)
//scale + rotate (a=1.8369701987210297e-16, b=3, c=-5, d=3.061616997868383e-16, tx=0, ty=0)
//rotate + scale (a=1.8369701987210297e-16, b=5, c=-3, d=3.061616997868383e-16, tx=0, ty=0)
//translate + rotate (a=6.123233995736766e-17, b=1, c=-1, d=6.123233995736766e-17, tx=-9, ty=7.000000000000001)
//rotate + translate (a=6.123233995736766e-17, b=1, c=-1, d=6.123233995736766e-17, tx=7, ty=9)
//triple transform
//scale + translate + rotate (a=1.8369701987210297e-16, b=3, c=-5, d=3.061616997868383e-16, tx=-9, ty=7.000000000000001)
//scale + rotate + translate (a=1.8369701987210297e-16, b=3, c=-5, d=3.061616997868383e-16, tx=7, ty=9)
//translate + scale + rotate (a=1.8369701987210297e-16, b=3, c=-5, d=3.061616997868383e-16, tx=-45, ty=21.000000000000004)
//translate + rotate + scale (a=1.8369701987210297e-16, b=5, c=-3, d=3.061616997868383e-16, tx=-27, ty=35.00000000000001)
//rotate + translate + scale (a=1.8369701987210297e-16, b=5, c=-3, d=3.061616997868383e-16, tx=21, ty=45)
//rotate + scale + translate (a=1.8369701987210297e-16, b=5, c=-3, d=3.061616997868383e-16, tx=7, ty=9)
//right application
//single transform
//matrix + scale (a=33, b=65, c=51, d=95, tx=69, ty=145)
//matrix + translate (a=11, b=13, c=17, d=19, tx=30, ty=38)
//matrix + rotate (a=-13, b=11, c=-19, d=17, tx=-29, ty=23)
//double transform
//matrix + scale + translate (a=33, b=65, c=51, d=95, tx=76, ty=154)
//matrix + translate + scale (a=33, b=65, c=51, d=95, tx=90, ty=190)
//matrix + scale + rotate (a=-65, b=33.00000000000001, c=-95, d=51.00000000000001, tx=-145, ty=69.00000000000001)
//matrix + rotate + scale (a=-39, b=55, c=-57, d=85, tx=-87, ty=115)
//matrix + translate + rotate (a=-13, b=11, c=-19, d=17, tx=-38, ty=30.000000000000004)
//matrix + rotate + translate (a=-13, b=11, c=-19, d=17, tx=-22, ty=32)
//triple transform
//matrix + scale + translate + rotate (a=-65, b=33.00000000000001, c=-95, d=51.00000000000001, tx=-154, ty=76.00000000000001)
//matrix + scale + rotate + translate (a=-65, b=33.00000000000001, c=-95, d=51.00000000000001, tx=-138, ty=78.00000000000001)
//matrix + translate + scale + rotate (a=-65, b=33.00000000000001, c=-95, d=51.00000000000001, tx=-190, ty=90.00000000000001)
//matrix + translate + rotate + scale (a=-39, b=55, c=-57, d=85, tx=-114, ty=150.00000000000003)
//matrix + rotate + translate + scale (a=-39, b=55, c=-57, d=85, tx=-66, ty=160)
//matrix + rotate + scale + translate (a=-39, b=55, c=-57, d=85, tx=-80, ty=124)
//left application
//single transform
//scale + matrix (a=33, b=39, c=85, d=95, tx=23, ty=29)
//translate + matrix (a=11, b=13, c=17, d=19, tx=253, ty=291)
//rotate + matrix (a=17, b=19, c=-10.999999999999998, d=-12.999999999999998, tx=23, ty=29)
//double transform
//scale + translate + matrix (a=33, b=39, c=85, d=95, tx=253, ty=291)
//translate + scale + matrix (a=33, b=39, c=85, d=95, tx=1019, ty=1157)
//scale + rotate + matrix (a=51, b=57, c=-54.99999999999999, d=-65, tx=23, ty=29)
//rotate + scale + matrix (a=85, b=95, c=-32.99999999999999, d=-38.99999999999999, tx=23, ty=29)
//translate + rotate + matrix (a=17, b=19, c=-10.999999999999998, d=-12.999999999999998, tx=43.000000000000014, ty=45.00000000000003)
//rotate + translate + matrix (a=17, b=19, c=-10.999999999999998, d=-12.999999999999998, tx=253, ty=291)
//triple transform
//scale + translate + rotate + matrix (a=51, b=57, c=-54.99999999999999, d=-65, tx=43.000000000000014, ty=45.00000000000003)
//scale + rotate + translate + matrix (a=51, b=57, c=-54.99999999999999, d=-65, tx=253, ty=291)
//translate + scale + rotate + matrix (a=51, b=57, c=-54.99999999999999, d=-65, tx=-114.99999999999994, ty=-156.99999999999994)
//translate + rotate + scale + matrix (a=85, b=95, c=-32.99999999999999, d=-38.99999999999999, tx=321.0000000000001, ty=343.0000000000001)
//rotate + translate + scale + matrix (a=85, b=95, c=-32.99999999999999, d=-38.99999999999999, tx=1019, ty=1157)
//rotate + scale + translate + matrix (a=85, b=95, c=-32.99999999999999, d=-38.99999999999999, tx=253, ty=291)
//middle application
//double transform
//scale + matrix + translate (a=33, b=39, c=85, d=95, tx=30, ty=38)
//translate + matrix + scale (a=33, b=65, c=51, d=95, tx=759, ty=1455)
//scale + matrix + rotate (a=-39, b=33, c=-95, d=85, tx=-29, ty=23)
//rotate + matrix + scale (a=51, b=95, c=-32.99999999999999, d=-64.99999999999999, tx=69, ty=145)
//translate + matrix + rotate (a=-13, b=11, c=-19, d=17, tx=-291, ty=253.00000000000003)
//rotate + matrix + translate (a=17, b=19, c=-10.999999999999998, d=-12.999999999999998, tx=30, ty=38)
//triple transform #1
//scale + matrix + translate + rotate (a=-39, b=33, c=-95, d=85, tx=-38, ty=30.000000000000004)
//scale + matrix + rotate + translate (a=-39, b=33, c=-95, d=85, tx=-22, ty=32)
//translate + matrix + scale + rotate (a=-65, b=33.00000000000001, c=-95, d=51.00000000000001, tx=-1455, ty=759.0000000000001)
//translate + matrix + rotate + scale (a=-39, b=55, c=-57, d=85, tx=-873, ty=1265.0000000000002)
//rotate + matrix + translate + scale (a=51, b=95, c=-32.99999999999999, d=-64.99999999999999, tx=90, ty=190)
//rotate + matrix + scale + translate (a=51, b=95, c=-32.99999999999999, d=-64.99999999999999, tx=76, ty=154)
//triple transform #2
//scale + translate + matrix + rotate (a=-39, b=33, c=-95, d=85, tx=-291, ty=253.00000000000003)
//scale + rotate + matrix + translate (a=51, b=57, c=-54.99999999999999, d=-65, tx=30, ty=38)
//translate + scale + matrix + rotate (a=-39, b=33, c=-95, d=85, tx=-1157, ty=1019.0000000000001)
//translate + rotate + matrix + scale (a=51, b=95, c=-32.99999999999999, d=-64.99999999999999, tx=129.00000000000006, ty=225.00000000000014)
//rotate + translate + matrix + scale (a=51, b=95, c=-32.99999999999999, d=-64.99999999999999, tx=759, ty=1455)
//rotate + scale + matrix + translate (a=85, b=95, c=-32.99999999999999, d=-38.99999999999999, tx=30, ty=38)
/// invert
// matrix
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix.invert()
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix
(a=2, b=3, c=5, d=7, tx=9, ty=11)
// matrix.invert()
(a=-7, b=3, c=5, d=-2, tx=8, ty=-5)
/// createBox
// matrix = new Matrix();
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix.createBox(2, 3)
(a=2, b=0, c=0, d=3, tx=0, ty=0)
// matrix.createBox(2, 3, 0)
(a=2, b=0, c=0, d=3, tx=0, ty=0)
// matrix.createBox(2, 3, 5)
(a=0.5673243709264525, b=-2.8767728239894153, c=1.917848549326277, d=0.8509865563896788, tx=0, ty=0)
// matrix.createBox(2, 3, 5, 7)
(a=0.5673243709264525, b=-2.8767728239894153, c=1.917848549326277, d=0.8509865563896788, tx=7, ty=0)
// matrix.createBox(2, 3, 5, 7, 9)
(a=0.5673243709264525, b=-2.8767728239894153, c=1.917848549326277, d=0.8509865563896788, tx=7, ty=9)
/// createGradientBox
// matrix = new Matrix();
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix.createGradientBox(200, 300)
(a=0.1220703125, b=0, c=0, d=0.18310546875, tx=100, ty=150)
// matrix.createGradientBox(200, 300, 0)
(a=0.1220703125, b=0, c=0, d=0.18310546875, tx=100, ty=150)
// matrix.createGradientBox(200, 300, 500)
(a=-0.10789175701067846, b=-0.08565157568160574, c=0.05710105045440383, d=-0.1618376355160177, tx=100, ty=150)
// matrix.createGradientBox(200, 300, 500, 700)
(a=-0.10789175701067846, b=-0.08565157568160574, c=0.05710105045440383, d=-0.1618376355160177, tx=800, ty=150)
// matrix.createGradientBox(200, 300, 500, 700, 900)
(a=-0.10789175701067846, b=-0.08565157568160574, c=0.05710105045440383, d=-0.1618376355160177, tx=800, ty=1050)
/// transformPoint
// matrix = new Matrix(2, 3, 5, 7, 11, 13);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
// matrix.transformPoint(new Point(1, 1));
(x=18, y=23)
/// deltaTransformPoint
// matrix = new Matrix(2, 3, 5, 7, 11, 13);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
// matrix.deltaTransformPoint(new Point(1, 1));
(x=7, y=10)
/// copyFrom
// matrix = new Matrix(2, 3, 5, 7, 11, 13);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
// matrix2 = new Matrix();
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix2.copyFrom(matrix);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
/// setTo
// matrix = new Matrix();
(a=1, b=0, c=0, d=1, tx=0, ty=0)
// matrix.setTo(2, 3, 5, 7, 11, 13);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
/// copyRowTo
// matrix = new Matrix(2, 3, 5, 7, 11, 13);
// vector = new Vector3D(1,2,3,4);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
Vector3D(1, 2, 3)
// matrix.copyRowTo(0, vector);
Vector3D(2, 5, 11)
// matrix.copyRowTo(1, vector);
Vector3D(3, 7, 13)
// matrix.copyRowTo(2, vector);
Vector3D(0, 0, 1)
// matrix.copyRowTo(3, vector);
Vector3D(0, 0, 1)
/// copyColumnTo
// matrix = new Matrix(2, 3, 5, 7, 11, 13);
// vector = new Vector3D(1,2,3,4);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
Vector3D(1, 2, 3)
// matrix.copyColumnTo(0, vector);
Vector3D(2, 3, 0)
// matrix.copyColumnTo(1, vector);
Vector3D(5, 7, 0)
// matrix.copyColumnTo(2, vector);
Vector3D(11, 13, 1)
// matrix.copyColumnTo(3, vector);
Vector3D(11, 13, 1)
/// copyRowFrom
// matrix = new Matrix(2, 3, 5, 7, 11, 13);
// vector = new Vector3D(17,19,23,29);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
Vector3D(17, 19, 23)
// matrix.copyRowFrom(0, vector);
(a=17, b=3, c=19, d=7, tx=23, ty=13)
// matrix.copyRowFrom(1, vector);
(a=17, b=17, c=19, d=19, tx=23, ty=23)
// matrix.copyRowFrom(2, vector);
(a=17, b=17, c=19, d=19, tx=23, ty=23)
// matrix.copyRowFrom(3, vector);
(a=17, b=17, c=19, d=19, tx=23, ty=23)
/// copyColumnFrom
// matrix = new Matrix(2, 3, 5, 7, 11, 13);
// vector = new Vector3D(17,19,23,29);
(a=2, b=3, c=5, d=7, tx=11, ty=13)
Vector3D(17, 19, 23)
// matrix.copyColumnFrom(0, vector);
(a=17, b=3, c=19, d=7, tx=23, ty=13)
// matrix.copyColumnFrom(1, vector);
(a=17, b=17, c=19, d=19, tx=23, ty=23)
// matrix.copyColumnFrom(2, vector);
(a=17, b=17, c=19, d=19, tx=23, ty=23)
// matrix.copyColumnFrom(3, vector);
(a=17, b=17, c=19, d=19, tx=23, ty=23)

Binary file not shown.

Binary file not shown.