<commit_before>package aerys.minko.type.math
{
	import aerys.minko.ns.minko;
	import aerys.minko.type.Factory;
	import aerys.minko.type.IVersionnable;
	
	import flash.geom.Matrix3D;
	import flash.geom.Orientation3D;
	import flash.geom.Utils3D;
	import flash.geom.Vector3D;

	public class Matrix4x4 implements IVersionnable
	{
		use namespace minko;
		
		private static const FACTORY			: Factory	= Factory.getFactory(Matrix4x4);
		
		private static const TMP_VECTOR			: Vector.<Number>	= new Vector.<Number>();
		private static const TMP_MATRIX			: Matrix4x4			= new Matrix4x4();
		
		private static const UPDATE_NONE		: uint		= 0;
		private static const UPDATE_DATA		: uint		= 1;
		private static const UPDATE_MATRIX		: uint		= 2;
		private static const UPDATE_ALL			: uint		= UPDATE_DATA | UPDATE_MATRIX;
		
		protected var _matrix		: Matrix3D			= new Matrix3D();
		
		private var _invalid	: Boolean			= false;
		
		private var _version	: uint				= 0;
		private var _data		: Vector.<Number>	= new Vector.<Number>();
		
		minko function getMatrix3D() : Matrix3D
		{
			return validMatrix3D;
		}
		
		protected function get validMatrix3D() : Matrix3D
		{
			if (invalid)
				updateMatrix();
			
			return _matrix;
		}
		
		protected function get invalid() : Boolean
		{
			return _invalid;
		}
		
		public function get version()	: uint		{ return _version; }
		
		public function Matrix4x4(m11 : Number	= 1., m12 : Number	= 0., m13 : Number	= 0., m14 : Number	= 0.,
								  m21 : Number	= 0., m22 : Number	= 1., m23 : Number	= 0., m24 : Number	= 0.,
								  m31 : Number	= 0., m32 : Number	= 0., m33 : Number	= 1., m34 : Number	= 0.,
								  m41 : Number	= 0., m42 : Number	= 0., m43 : Number	= 0., m44 : Number	= 1.)
		{
			initialize(m11, m12, m13, m14,
					   m21, m22, m23, m24,
					   m31, m32, m33, m34,
					   m41, m42, m43, m44);
		}
		
		private function initialize(m11 : Number, m12 : Number, m13 : Number, m14 : Number,
									m21 : Number, m22 : Number, m23 : Number, m24 : Number,
									m31 : Number, m32 : Number, m33 : Number, m34 : Number,
									m41 : Number, m42 : Number, m43 : Number, m44 : Number) : void
		{
			TMP_VECTOR.length = 0;
			TMP_VECTOR.push(m11, m12, m13, m14,
							m21, m22, m23, m24,
							m31, m32, m33, m34,
							m41, m42, m43, m44);
			
			validMatrix3D.copyRawDataFrom(TMP_VECTOR);
		}
		
		protected function invalidate() : void
		{
			_invalid = true;
			++_version;
		}
		
		protected function updateMatrix() : void
		{
			_invalid = false;
		}
		
		public function push() : Matrix4x4
		{
			validMatrix3D.copyRawDataTo(_data, _data.length);
			
			return this;
		}
		
		public function pop() : Matrix4x4
		{
			var dataLength : int = _data.length;
			
			validMatrix3D.copyRawDataFrom(_data, dataLength - 16);
			_data.length = dataLength - 16;
			invalidate();
			
			return this;
		}
		
		public function multiply(m : Matrix4x4) : Matrix4x4
		{
			validMatrix3D.prepend(m.validMatrix3D);
			
			invalidate();
			
			return this;
		}
		
		public function multiplyInverse(m : Matrix4x4) : Matrix4x4
		{
			validMatrix3D.append(m.validMatrix3D);
			
			invalidate();
			
			return this;
		}<commit_msg>Matrix4x4.pop() will have no effect when there is nothing to pop<commit_after>package aerys.minko.type.math
{
	import aerys.minko.ns.minko;
	import aerys.minko.type.Factory;
	import aerys.minko.type.IVersionnable;
	
	import flash.geom.Matrix3D;
	import flash.geom.Orientation3D;
	import flash.geom.Utils3D;
	import flash.geom.Vector3D;

	public class Matrix4x4 implements IVersionnable
	{
		use namespace minko;
		
		private static const FACTORY			: Factory	= Factory.getFactory(Matrix4x4);
		
		private static const TMP_VECTOR			: Vector.<Number>	= new Vector.<Number>();
		private static const TMP_MATRIX			: Matrix4x4			= new Matrix4x4();
		
		private static const UPDATE_NONE		: uint		= 0;
		private static const UPDATE_DATA		: uint		= 1;
		private static const UPDATE_MATRIX		: uint		= 2;
		private static const UPDATE_ALL			: uint		= UPDATE_DATA | UPDATE_MATRIX;
		
		protected var _matrix		: Matrix3D			= new Matrix3D();
		
		private var _invalid	: Boolean			= false;
		
		private var _version	: uint				= 0;
		private var _data		: Vector.<Number>	= new Vector.<Number>();
		
		minko function getMatrix3D() : Matrix3D
		{
			return validMatrix3D;
		}
		
		protected function get validMatrix3D() : Matrix3D
		{
			if (invalid)
				updateMatrix();
			
			return _matrix;
		}
		
		protected function get invalid() : Boolean
		{
			return _invalid;
		}
		
		public function get version()	: uint		{ return _version; }
		
		public function Matrix4x4(m11 : Number	= 1., m12 : Number	= 0., m13 : Number	= 0., m14 : Number	= 0.,
								  m21 : Number	= 0., m22 : Number	= 1., m23 : Number	= 0., m24 : Number	= 0.,
								  m31 : Number	= 0., m32 : Number	= 0., m33 : Number	= 1., m34 : Number	= 0.,
								  m41 : Number	= 0., m42 : Number	= 0., m43 : Number	= 0., m44 : Number	= 1.)
		{
			initialize(m11, m12, m13, m14,
					   m21, m22, m23, m24,
					   m31, m32, m33, m34,
					   m41, m42, m43, m44);
		}
		
		private function initialize(m11 : Number, m12 : Number, m13 : Number, m14 : Number,
									m21 : Number, m22 : Number, m23 : Number, m24 : Number,
									m31 : Number, m32 : Number, m33 : Number, m34 : Number,
									m41 : Number, m42 : Number, m43 : Number, m44 : Number) : void
		{
			TMP_VECTOR.length = 0;
			TMP_VECTOR.push(m11, m12, m13, m14,
							m21, m22, m23, m24,
							m31, m32, m33, m34,
							m41, m42, m43, m44);
			
			validMatrix3D.copyRawDataFrom(TMP_VECTOR);
		}
		
		protected function invalidate() : void
		{
			_invalid = true;
			++_version;
		}
		
		protected function updateMatrix() : void
		{
			_invalid = false;
		}
		
		public function push() : Matrix4x4
		{
			validMatrix3D.copyRawDataTo(_data, _data.length);
			
			return this;
		}
		
		public function pop() : Matrix4x4
		{
			var dataLength : int = _data.length;
			
			if (dataLength)
			{
				validMatrix3D.copyRawDataFrom(_data, dataLength - 16);
				_data.length = dataLength - 16;
				invalidate();
			}
			
			return this;
		}
		
		public function multiply(m : Matrix4x4) : Matrix4x4
		{
			validMatrix3D.prepend(m.validMatrix3D);
			
			invalidate();
			
			return this;
		}
		
		public function multiplyInverse(m : Matrix4x4) : Matrix4x4
		{
			validMatrix3D.append(m.validMatrix3D);
			
			invalidate();
			
			return this;
		}
{'fraction_non_alphanumeric': 0.10965527998752145, 'fraction_numerical': 0.0605209795663703, 'mean_word_length': 2.634920634920635, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4109573', 'n_tokens_mistral': 3065, 'n_tokens_neox': 2318, 'n_words': 606}