UNPKG

openfl

Version:

A fast, productive library for 2D cross-platform development.

424 lines (406 loc) 10.7 kB
// Class: lime.math._Matrix3.Matrix3_Impl_ var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../../hxClasses_stub").default; var $hxEnums = require("./../../../hxEnums_stub").default; var $import = require("./../../../import_stub").default; function js__$Boot_HaxeError() {return require("./../../../js/_Boot/HaxeError");} function lime_math_Vector2() {return require("./../../../lime/math/Vector2");} function lime_math_CairoMatrix3() {return require("./../../../lime/math/CairoMatrix3");} function lime_math_Rectangle() {return require("./../../../lime/math/Rectangle");} // Constructor var Matrix3_Impl_ = function(){} // Meta Matrix3_Impl_.__name__ = "lime.math._Matrix3.Matrix3_Impl_"; Matrix3_Impl_.__isInterface__ = false; Matrix3_Impl_.prototype = { }; Matrix3_Impl_.prototype.__class__ = Matrix3_Impl_.prototype.constructor = $hxClasses["lime.math._Matrix3.Matrix3_Impl_"] = Matrix3_Impl_; // Init // Statics Matrix3_Impl_._new = function(a,b,c,d,tx,ty) { if(ty == null) { ty = 0; } if(tx == null) { tx = 0; } if(d == null) { d = 1; } if(c == null) { c = 0; } if(b == null) { b = 0; } if(a == null) { a = 1; } var elements = null; var array = [a,b,0,c,d,0,tx,ty,1]; var view = null; var buffer = null; var len = null; var this1; if(elements != null) { this1 = new Float32Array(elements); } else if(array != null) { this1 = new Float32Array(array); } else if(view != null) { this1 = new Float32Array(view); } else if(buffer != null) { if(len == null) { this1 = new Float32Array(buffer,0); } else { this1 = new Float32Array(buffer,0,len); } } else { this1 = null; } var this2 = this1; return this2; } Matrix3_Impl_.clone = function(this1) { return Matrix3_Impl_._new(this1[0],this1[1],this1[3],this1[4],this1[6],this1[7]); } Matrix3_Impl_.concat = function(this1,m) { var a1 = this1[0] * m[0] + this1[1] * m[3]; this1[1] = this1[0] * m[1] + this1[1] * m[4]; this1[0] = a1; var c1 = this1[3] * m[0] + this1[4] * m[3]; this1[4] = this1[3] * m[1] + this1[4] * m[4]; this1[3] = c1; var tx1 = this1[6] * m[0] + this1[7] * m[3] + m[6]; this1[7] = this1[6] * m[1] + this1[7] * m[4] + m[7]; this1[6] = tx1; } Matrix3_Impl_.copyColumnFrom = function(this1,column,vector4) { if(column > 2) { throw new (js__$Boot_HaxeError().default)("Column " + column + " out of bounds (2)"); } else if(column == 0) { this1[0] = vector4.x; this1[1] = vector4.y; } else if(column == 1) { this1[3] = vector4.x; this1[4] = vector4.y; } else { this1[6] = vector4.x; this1[7] = vector4.y; } } Matrix3_Impl_.copyColumnTo = function(this1,column,vector4) { if(column > 2) { throw new (js__$Boot_HaxeError().default)("Column " + column + " out of bounds (2)"); } else if(column == 0) { vector4.x = this1[0]; vector4.y = this1[1]; vector4.z = 0; } else if(column == 1) { vector4.x = this1[3]; vector4.y = this1[4]; vector4.z = 0; } else { vector4.x = this1[6]; vector4.y = this1[7]; vector4.z = 1; } } Matrix3_Impl_.copyFrom = function(this1,sourceMatrix3) { this1[0] = sourceMatrix3[0]; this1[1] = sourceMatrix3[1]; this1[3] = sourceMatrix3[3]; this1[4] = sourceMatrix3[4]; this1[6] = sourceMatrix3[6]; this1[7] = sourceMatrix3[7]; } Matrix3_Impl_.copyRowFrom = function(this1,row,vector4) { if(row > 2) { throw new (js__$Boot_HaxeError().default)("Row " + row + " out of bounds (2)"); } else if(row == 0) { this1[0] = vector4.x; this1[3] = vector4.y; this1[6] = vector4.z; } else if(row == 1) { this1[1] = vector4.x; this1[4] = vector4.y; this1[7] = vector4.z; } } Matrix3_Impl_.copyRowTo = function(this1,row,vector4) { if(row > 2) { throw new (js__$Boot_HaxeError().default)("Row " + row + " out of bounds (2)"); } else if(row == 0) { vector4.x = this1[0]; vector4.y = this1[3]; vector4.z = this1[6]; } else if(row == 1) { vector4.x = this1[1]; vector4.y = this1[4]; vector4.z = this1[7]; } else { vector4.setTo(0,0,1); } } Matrix3_Impl_.createBox = function(this1,scaleX,scaleY,rotation,xTranslate,yTranslate) { if(yTranslate == null) { yTranslate = 0; } if(xTranslate == null) { xTranslate = 0; } if(rotation == null) { rotation = 0; } if(rotation != 0) { var cos = Math.cos(rotation); var sin = Math.sin(rotation); this1[0] = cos * scaleX; this1[1] = sin * scaleY; this1[3] = -sin * scaleX; this1[4] = cos * scaleY; } else { this1[0] = scaleX; this1[1] = 0; this1[3] = 0; this1[4] = scaleY; } this1[6] = xTranslate; this1[7] = yTranslate; } Matrix3_Impl_.createGradientBox = function(this1,width,height,rotation,xTranslate,yTranslate) { if(yTranslate == null) { yTranslate = 0; } if(xTranslate == null) { xTranslate = 0; } if(rotation == null) { rotation = 0; } this1[0] = width / 1638.4; this1[4] = height / 1638.4; if(rotation != 0) { var cos = Math.cos(rotation); var sin = Math.sin(rotation); this1[1] = sin * this1[4]; this1[3] = -sin * this1[0]; this1[0] *= cos; this1[4] *= cos; } else { this1[1] = 0; this1[3] = 0; } this1[6] = xTranslate + width / 2; this1[7] = yTranslate + height / 2; } Matrix3_Impl_.equals = function(this1,matrix3) { if(matrix3 != null && this1[6] == matrix3[6] && this1[7] == matrix3[7] && this1[0] == matrix3[0] && this1[1] == matrix3[1] && this1[3] == matrix3[3]) { return this1[4] == matrix3[4]; } else { return false; } } Matrix3_Impl_.deltaTransformVector = function(this1,Vector2,result) { if(result == null) { result = new (lime_math_Vector2().default)(); } result.x = Vector2.x * this1[0] + Vector2.y * this1[3]; result.y = Vector2.x * this1[1] + Vector2.y * this1[4]; return result; } Matrix3_Impl_.fromCairoMatrix3 = function(matrix) { return Matrix3_Impl_._new(matrix.a,matrix.b,matrix.c,matrix.d,matrix.tx,matrix.ty); } Matrix3_Impl_.fromFloat32Array = function(array) { if(array.length != 9) { throw new (js__$Boot_HaxeError().default)("Expected array of length 9, got " + array.length); } return array; } Matrix3_Impl_.identity = function(this1) { this1[0] = 1; this1[1] = 0; this1[3] = 0; this1[4] = 1; this1[6] = 0; this1[7] = 0; } Matrix3_Impl_.invert = function(this1) { var norm = this1[0] * this1[4] - this1[1] * this1[3]; if(norm == 0) { this1[0] = this1[1] = this1[3] = this1[4] = 0; this1[6] = -this1[6]; this1[7] = -this1[7]; } else { norm = 1.0 / norm; var a1 = this1[4] * norm; this1[4] = this1[0] * norm; this1[0] = a1; this1[1] *= -norm; this1[3] *= -norm; var tx1 = -this1[0] * this1[6] - this1[3] * this1[7]; this1[7] = -this1[1] * this1[6] - this1[4] * this1[7]; this1[6] = tx1; } if(this1.length != 9) { throw new (js__$Boot_HaxeError().default)("Expected array of length 9, got " + this1.length); } return this1; } Matrix3_Impl_.rotate = function(this1,theta) { var cos = Math.cos(theta); var sin = Math.sin(theta); var a1 = this1[0] * cos - this1[1] * sin; this1[1] = this1[0] * sin + this1[1] * cos; this1[0] = a1; var c1 = this1[3] * cos - this1[4] * sin; this1[4] = this1[3] * sin + this1[4] * cos; this1[3] = c1; var tx1 = this1[6] * cos - this1[7] * sin; this1[7] = this1[6] * sin + this1[7] * cos; this1[6] = tx1; } Matrix3_Impl_.scale = function(this1,sx,sy) { this1[0] *= sx; this1[1] *= sy; this1[3] *= sx; this1[4] *= sy; this1[6] *= sx; this1[7] *= sy; } Matrix3_Impl_.setRotation = function(this1,theta,scale) { if(scale == null) { scale = 1; } this1[0] = Math.cos(theta) * scale; this1[3] = Math.sin(theta) * scale; this1[1] = -this1[3]; this1[4] = this1[0]; } Matrix3_Impl_.setTo = function(this1,a,b,c,d,tx,ty) { this1[0] = a; this1[1] = b; this1[3] = c; this1[4] = d; this1[6] = tx; this1[7] = ty; } Matrix3_Impl_.toCairoMatrix3 = function(this1) { return new (lime_math_CairoMatrix3().default)(this1[0],this1[1],this1[3],this1[4],this1[6],this1[7]); } Matrix3_Impl_.toString = function(this1) { return "matrix(" + this1[0] + ", " + this1[1] + ", " + this1[3] + ", " + this1[4] + ", " + this1[6] + ", " + this1[7] + ")"; } Matrix3_Impl_.transformRect = function(this1,rect,result) { if(result == null) { result = new (lime_math_Rectangle().default)(); } var tx0 = this1[0] * rect.x + this1[3] * rect.y; var tx1 = tx0; var ty0 = this1[1] * rect.x + this1[4] * rect.y; var ty1 = ty0; var tx = this1[0] * (rect.x + rect.width) + this1[3] * rect.y; var ty = this1[1] * (rect.x + rect.width) + this1[4] * rect.y; if(tx < tx0) { tx0 = tx; } if(ty < ty0) { ty0 = ty; } if(tx > tx1) { tx1 = tx; } if(ty > ty1) { ty1 = ty; } tx = this1[0] * (rect.x + rect.width) + this1[3] * (rect.y + rect.height); ty = this1[1] * (rect.x + rect.width) + this1[4] * (rect.y + rect.height); if(tx < tx0) { tx0 = tx; } if(ty < ty0) { ty0 = ty; } if(tx > tx1) { tx1 = tx; } if(ty > ty1) { ty1 = ty; } tx = this1[0] * rect.x + this1[3] * (rect.y + rect.height); ty = this1[1] * rect.x + this1[4] * (rect.y + rect.height); if(tx < tx0) { tx0 = tx; } if(ty < ty0) { ty0 = ty; } if(tx > tx1) { tx1 = tx; } if(ty > ty1) { ty1 = ty; } result.setTo(tx0 + tx,ty0 + ty,tx1 - tx0,ty1 - ty0); return result; } Matrix3_Impl_.transformVector = function(this1,pos,result) { if(result == null) { result = new (lime_math_Vector2().default)(); } result.x = pos.x * this1[0] + pos.y * this1[3] + this1[6]; result.y = pos.x * this1[1] + pos.y * this1[4] + this1[7]; return result; } Matrix3_Impl_.translate = function(this1,dx,dy) { this1[6] += dx; this1[7] += dy; } Matrix3_Impl_.get_a = function(this1) { return this1[0]; } Matrix3_Impl_.set_a = function(this1,value) { return this1[0] = value; } Matrix3_Impl_.get_b = function(this1) { return this1[1]; } Matrix3_Impl_.set_b = function(this1,value) { return this1[1] = value; } Matrix3_Impl_.get_c = function(this1) { return this1[3]; } Matrix3_Impl_.set_c = function(this1,value) { return this1[3] = value; } Matrix3_Impl_.get_d = function(this1) { return this1[4]; } Matrix3_Impl_.set_d = function(this1,value) { return this1[4] = value; } Matrix3_Impl_.get_tx = function(this1) { return this1[6]; } Matrix3_Impl_.set_tx = function(this1,value) { return this1[6] = value; } Matrix3_Impl_.get_ty = function(this1) { return this1[7]; } Matrix3_Impl_.set_ty = function(this1,value) { return this1[7] = value; } Matrix3_Impl_.get = function(this1,index) { return this1[index]; } Matrix3_Impl_.set = function(this1,index,value) { this1[index] = value; return value; } // Export exports.default = Matrix3_Impl_;