<commit_before>/*jshint white: false, strict: false, plusplus: false, onevar: false,
  nomen: false */
/*global define: false, console: false, window: false, setTimeout: false */

define( function ( require ) {

    return function( engine ) {
        
        var math = engine.math;
        var Component = require( '../component' );
        var Delegate = require( '../delegate' );

        var thisType = 'Transform';

        var Transform = function( options ) {

            options = options || {};
            var that = this;
            
            var _owner = null;
            Object.defineProperty( this, 'owner', {
                get: function() {
                    return _owner;
                },
                set: function( value ) {
                    if( value != _owner ) {
                        _owner = value;
                        onOwnerChanged( value );
                    }
                }
            });
            
            var _ownerChanged = new Delegate();
            Object.defineProperty( this, 'ownerChanged', {
                get: function() {
                    return _ownerChanged;
                }
            });
            var onOwnerChanged = function( options ) {
                if( _ownerChanged ) {
                    _ownerChanged( options );
                }
            };

            var _position = options.position || math.vector3.zero;
            var _rotation = options.rotation || math.vector3.zero;
            var _scale = options.scale || math.vector3.one;
            var _absolute = null;
            var _relative = null;

            var _cache = math.matrix4.identity;
            var _cached = false;    // True if the cached version of our fixed transform is valid, false otherwise
            var _recompile = true;  // True if we need to recompile the absolute transform, false otherwise

            var matrix = function() {
                if( _cached ) {
                    return _cache;
                } else {
                    _cache = math.transform.fixed( _position, _rotation, _scale);   // TD: this should compute the result into the buffer instead of returning a new matrix
                    _cached = true;
                    return _cache;
                }
            };

            Object.defineProperty( this, 'position', {
                get: function() {
                    return math.Vector3( _position );
                },
                set: function( value ) {
                    if( !math.vector3.equal( value, _position ) ) {
                        _position = value;  // TD: math.vector3.copy( _position, value )
                        _cached = false;
                    }
                }
            });

            Object.defineProperty( this, 'rotation', {
                get: function() {
                    return math.Vector3( _rotation );
                },
                set: function( value ) {
                    if( !math.vector3.equal( value, _rotation ) ) {
                        _rotation = value;  // TD: math.vector3.copy( _rotation, value )
                        _cached = false;
                    }
                }
            });

            Object.defineProperty( this, 'scale', {
                get: function() {
                    return math.Vector3( _scale );
                },
                set: function( value ) {
                    if( !math.vector3.equal( value, _scale ) ) {
                        _scale = value;     // TD: math.vector3.copy( _scale, value )
                        _cached = false;
                    }
                }
            });
            
            Object.defineProperty( this, 'absolute', {
                get: function() {
                    if( _recompile ) {
                        if( this.owner.parent && this.owner.parent.contains( thisType ) ) {
                            var parentTransform = this.owner.parent.find( thisType );
                            math.matrix4.multiply( parentTransform.absolute, matrix(), _absolute );
                        } else {
                            _absolute = matrix();
                        }
                        _recompile = false;<commit_msg>Most of the computations in Transform are allocating new buffers instead of computing into existing buffers. Will fix this later.<commit_after>/*jshint white: false, strict: false, plusplus: false, onevar: false,
  nomen: false */
/*global define: false, console: false, window: false, setTimeout: false */

define( function ( require ) {

    return function( engine ) {
        
        var math = engine.math;
        var Component = require( '../component' );
        var Delegate = require( '../delegate' );

        var thisType = 'Transform';

        var Transform = function( options ) {

            options = options || {};
            var that = this;
            
            var _owner = null;
            Object.defineProperty( this, 'owner', {
                get: function() {
                    return _owner;
                },
                set: function( value ) {
                    if( value != _owner ) {
                        _owner = value;
                        onOwnerChanged( value );
                    }
                }
            });
            
            var _ownerChanged = new Delegate();
            Object.defineProperty( this, 'ownerChanged', {
                get: function() {
                    return _ownerChanged;
                }
            });
            var onOwnerChanged = function( options ) {
                if( _ownerChanged ) {
                    _ownerChanged( options );
                }
            };

            var _position = options.position || math.vector3.zero;
            var _rotation = options.rotation || math.vector3.zero;
            var _scale = options.scale || math.vector3.one;
            var _absolute = null;
            var _relative = null;

            var _cache = math.matrix4.identity;
            var _cached = false;    // True if the cached version of our fixed transform is valid, false otherwise
            var _recompile = true;  // True if we need to recompile the absolute transform, false otherwise

            var matrix = function() {
                if( _cached ) {
                    return _cache;
                } else {
                    _cache = math.transform.fixed( _position, _rotation, _scale);   // TD: this should compute the result into the buffer instead of returning a new matrix
                    _cached = true;
                    return _cache;
                }
            };

            Object.defineProperty( this, 'position', {
                get: function() {
                    return math.Vector3( _position );
                },
                set: function( value ) {
                    if( !math.vector3.equal( value, _position ) ) {
                        _position = value;  // TD: math.vector3.copy( _position, value )
                        _cached = false;
                    }
                }
            });

            Object.defineProperty( this, 'rotation', {
                get: function() {
                    return math.Vector3( _rotation );
                },
                set: function( value ) {
                    if( !math.vector3.equal( value, _rotation ) ) {
                        _rotation = value;  // TD: math.vector3.copy( _rotation, value )
                        _cached = false;
                    }
                }
            });

            Object.defineProperty( this, 'scale', {
                get: function() {
                    return math.Vector3( _scale );
                },
                set: function( value ) {
                    if( !math.vector3.equal( value, _scale ) ) {
                        _scale = value;     // TD: math.vector3.copy( _scale, value )
                        _cached = false;
                    }
                }
            });
            
            Object.defineProperty( this, 'absolute', {
                get: function() {
                    if( _recompile ) {
                        if( this.owner.parent && this.owner.parent.contains( thisType ) ) {
                            var parentTransform = this.owner.parent.find( thisType );                            
                            _absolute = math.matrix4.multiply( parentTransform.absolute, matrix() );
                        } else {
                            _absolute = matrix();
                        }
                        _recompile = false;
{'fraction_non_alphanumeric': 0.09254319842282269, 'fraction_numerical': 0.0032471297692218486, 'mean_word_length': 1.0846023688663282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6864833', 'n_tokens_mistral': 2035, 'n_tokens_neox': 1897, 'n_words': 546}