<commit_before>'use strict';
var MACROUTILS = require( 'osg/Utils' );
var Vec3 = require( 'osg/Vec3' );
var Matrix = require( 'osg/Matrix' );
var Manipulator = require( 'osgGA/Manipulator' );
var OrbitManipulatorDeviceOrientationController = require( 'osgGA/OrbitManipulatorDeviceOrientationController' );
var OrbitManipulatorGamePadController = require( 'osgGA/OrbitManipulatorGamePadController' );
var OrbitManipulatorHammerController = require( 'osgGA/OrbitManipulatorHammerController' );
var OrbitManipulatorLeapMotionController = require( 'osgGA/OrbitManipulatorLeapMotionController' );
var OrbitManipulatorStandardMouseKeyboardController = require( 'osgGA/OrbitManipulatorStandardMouseKeyboardController' );
var OrbitManipulatorWebVRController = require( 'osgGA/OrbitManipulatorWebVRController' );


/**
 *  OrbitManipulator
 *  @class
 */
var OrbitManipulator = function ( boundStrategy ) {
    Manipulator.call( this, boundStrategy );
    this._homePosition = Vec3.create();
    this._frustum = {};
    this.init();
};

OrbitManipulator.Interpolator = function ( size, delay ) {
    this._current = new Array( size );
    this._target = new Array( size );
    this._delta = new Array( size );
    this._delay = ( delay !== undefined ) ? delay : 0.15;
    this._reset = false;
    this._start = 0.0;
    this.reset();
};
OrbitManipulator.Interpolator.prototype = {
    setDelay: function ( delay ) {
        this._delay = delay;
    },
    reset: function () {
        for ( var i = 0, l = this._current.length; i < l; i++ ) {
            this._current[ i ] = this._target[ i ] = 0.0;
        }
        this._reset = true;
    },
    update: function ( dt ) {
        // assume 60 fps to be consistent with the old _delay values for backward compatibility
        // (otherwise we'd have to adjust the _delay values by multiplying to 60 )
        var dtDelay = Math.min( 1.0, this._delay * dt * 60.0 );
        for ( var i = 0, l = this._current.length; i < l; i++ ) {
            var d = ( this._target[ i ] - this._current[ i ] ) * dtDelay;
            this._delta[ i ] = d;
            this._current[ i ] += d;
        }
        return this._delta;
    },
    set: function () {
        for ( var i = 0, l = this._current.length; i < l; i++ ) {
            this._current[ i ] = this._target[ i ] = arguments[ i ];
        }
        this._reset = false;
    },
    isReset: function () {
        return this._reset;
    },
    getCurrent: function () {
        return this._current;
    },
    setTarget: function () {
        for ( var i = 0, l = this._target.length; i < l; i++ ) {
            if ( this._reset ) {
                this._target[ i ] = this._current[ i ] = arguments[ i ];
            } else {
                this._target[ i ] = arguments[ i ];
            }
        }
        this._reset = false;
    },
    addTarget: function () {
        for ( var i = 0; i < arguments.length; i++ ) {
            this._target[ i ] += arguments[ i ];
        }
    },
    getTarget: function () {
        return this._target;
    },
    getDelta: function () {
        return this._delta;
    },
    getStart: function () {
        return this._start;
    },
    setStart: function ( start ) {
        this._start = start;
    }
};

OrbitManipulator.AvailableControllerList = [ 'StandardMouseKeyboard',
    'LeapMotion',
    'GamePad',
    'Hammer',
    'DeviceOrientation',
    'WebVR'
];

OrbitManipulator.ControllerList = [ 'StandardMouseKeyboard',
    'LeapMotion',
    'GamePad',
    'Hammer',
    'DeviceOrientation',
    'WebVR'
];

var DOT_LIMIT = 0.99; // angle limit around the pole

/** @lends OrbitManipulator.prototype */
OrbitManipulator.prototype = MACROUTILS.objectInherit( Manipulator.prototype, {
    init: function () {
        this._distance = 25.0;
        this._target = Vec3.create();
        this._upz = Vec3.createAndSet( 0.0, 0.0, 1.0 );
        Vec3.init( this._target );

        var rot1 = Matrix.makeRotate( -Math.PI, 0.0, 0.0, 1.0, Matrix.create() );
        var rot2 = Matrix.makeRotate( Math.PI / 10.0, 1.0, 0.0, 0.0, Matrix.create() );
        this._rotation = Matrix.create();
        Matrix.mult( rot1, rot2, this._rotation );
        this._time = 0.0;
        this._rotBase = Matrix.create();

        this._rotate = new OrbitManipulator.Interpolator( 2 );
        this._pan = new OrbitManipulator.Interpolator( 2 );
        this._zoom = new OrbitManipulator.Interpolator( 1 );

        this._maxDistance = Infinity;
        this._minDistance = 1e-10; // min distance allowed between eye and target
        this._minSpeed = 1e-10; // set a limit to pan/zoom speed
        this._scaleMouseMotion = 1.0;

        this._inverseMatrix = Matrix.create();

        // if we hit the min distance and can't zoom anymore, maybe we still want to move on
        // with a very low _minDistance, it's like a fps manipulator as long as you don't unzoom
        this._autoPushTarget = true;

        // instance of controller
        var self = this;

        OrbitManipulator.ControllerList.forEach( function ( value ) {
            if ( OrbitManipulator[ value ] !== undefined ) {
                self._controllerList[ value ] = new OrbitManipulator[ value ]( self );
            }
        } );
    },
    setDelay: function ( dt ) {
        this._rotate.setDelay( dt );
        this._pan.setDelay( dt );
        this._zoom.setDelay( dt );
    },
    reset: function () {
        this.init();
    },
    setTarget: function ( target ) {
        Vec3.copy( target, this._target );
        var eyePos = Vec3.create();
        this.getEyePosition( eyePos );
        this._distance = Vec3.distance( eyePos, target );
    },
    setEyePosition: ( function () {
        var f = Vec3.create();
        var s = Vec3.create();
        var u = Vec3.create();
        return function ( eye ) {
            var result = this._rotation;
            var center = this._target;

            Vec3.sub( eye, center, f );
            Vec3.normalize( f, f );

            var p = Vec3.dot( f, this._upz );
            if ( Math.abs( p ) > DOT_LIMIT ) {
                // we force z to DOT_LIMIT and we normalize the vec3 vector by only editing the x and y component
                var a = Math.sqrt( ( 1.0 - DOT_LIMIT * DOT_LIMIT ) / ( f[ 0 ] * f[ 0 ] + f[ 1 ] * f[ 1 ] ) );
                f[ 0 ] *= a;
                f[ 1 ] *= a;
                f[ 2 ] = DOT_LIMIT * Math.sign( p );
            }

            Vec3.cross( f, this._upz, s );
            Vec3.normalize( s, s );

            Vec3.cross( s, f, u );
            Vec3.normalize( u, u );

            // s[0], f[0], u[0], 0.0,
            // s[1], f[1], u[1], 0.0,
            // s[2], f[2], u[2], 0.0,<commit_msg>Removes setEyePosition orbit limitation<commit_after>'use strict';
var MACROUTILS = require( 'osg/Utils' );
var Vec3 = require( 'osg/Vec3' );
var Matrix = require( 'osg/Matrix' );
var Manipulator = require( 'osgGA/Manipulator' );
var OrbitManipulatorDeviceOrientationController = require( 'osgGA/OrbitManipulatorDeviceOrientationController' );
var OrbitManipulatorGamePadController = require( 'osgGA/OrbitManipulatorGamePadController' );
var OrbitManipulatorHammerController = require( 'osgGA/OrbitManipulatorHammerController' );
var OrbitManipulatorLeapMotionController = require( 'osgGA/OrbitManipulatorLeapMotionController' );
var OrbitManipulatorStandardMouseKeyboardController = require( 'osgGA/OrbitManipulatorStandardMouseKeyboardController' );
var OrbitManipulatorWebVRController = require( 'osgGA/OrbitManipulatorWebVRController' );


/**
 *  OrbitManipulator
 *  @class
 */
var OrbitManipulator = function ( boundStrategy ) {
    Manipulator.call( this, boundStrategy );
    this._homePosition = Vec3.create();
    this._frustum = {};
    this.init();
};

OrbitManipulator.Interpolator = function ( size, delay ) {
    this._current = new Array( size );
    this._target = new Array( size );
    this._delta = new Array( size );
    this._delay = ( delay !== undefined ) ? delay : 0.15;
    this._reset = false;
    this._start = 0.0;
    this.reset();
};
OrbitManipulator.Interpolator.prototype = {
    setDelay: function ( delay ) {
        this._delay = delay;
    },
    reset: function () {
        for ( var i = 0, l = this._current.length; i < l; i++ ) {
            this._current[ i ] = this._target[ i ] = 0.0;
        }
        this._reset = true;
    },
    update: function ( dt ) {
        // assume 60 fps to be consistent with the old _delay values for backward compatibility
        // (otherwise we'd have to adjust the _delay values by multiplying to 60 )
        var dtDelay = Math.min( 1.0, this._delay * dt * 60.0 );
        for ( var i = 0, l = this._current.length; i < l; i++ ) {
            var d = ( this._target[ i ] - this._current[ i ] ) * dtDelay;
            this._delta[ i ] = d;
            this._current[ i ] += d;
        }
        return this._delta;
    },
    set: function () {
        for ( var i = 0, l = this._current.length; i < l; i++ ) {
            this._current[ i ] = this._target[ i ] = arguments[ i ];
        }
        this._reset = false;
    },
    isReset: function () {
        return this._reset;
    },
    getCurrent: function () {
        return this._current;
    },
    setTarget: function () {
        for ( var i = 0, l = this._target.length; i < l; i++ ) {
            if ( this._reset ) {
                this._target[ i ] = this._current[ i ] = arguments[ i ];
            } else {
                this._target[ i ] = arguments[ i ];
            }
        }
        this._reset = false;
    },
    addTarget: function () {
        for ( var i = 0; i < arguments.length; i++ ) {
            this._target[ i ] += arguments[ i ];
        }
    },
    getTarget: function () {
        return this._target;
    },
    getDelta: function () {
        return this._delta;
    },
    getStart: function () {
        return this._start;
    },
    setStart: function ( start ) {
        this._start = start;
    }
};

OrbitManipulator.AvailableControllerList = [ 'StandardMouseKeyboard',
    'LeapMotion',
    'GamePad',
    'Hammer',
    'DeviceOrientation',
    'WebVR'
];

OrbitManipulator.ControllerList = [ 'StandardMouseKeyboard',
    'LeapMotion',
    'GamePad',
    'Hammer',
    'DeviceOrientation',
    'WebVR'
];

var DOT_LIMIT = 0.99; // angle limit around the pole

/** @lends OrbitManipulator.prototype */
OrbitManipulator.prototype = MACROUTILS.objectInherit( Manipulator.prototype, {
    init: function () {
        this._distance = 25.0;
        this._target = Vec3.create();
        this._upz = Vec3.createAndSet( 0.0, 0.0, 1.0 );
        Vec3.init( this._target );

        var rot1 = Matrix.makeRotate( -Math.PI, 0.0, 0.0, 1.0, Matrix.create() );
        var rot2 = Matrix.makeRotate( Math.PI / 10.0, 1.0, 0.0, 0.0, Matrix.create() );
        this._rotation = Matrix.create();
        Matrix.mult( rot1, rot2, this._rotation );
        this._time = 0.0;
        this._rotBase = Matrix.create();

        this._rotate = new OrbitManipulator.Interpolator( 2 );
        this._pan = new OrbitManipulator.Interpolator( 2 );
        this._zoom = new OrbitManipulator.Interpolator( 1 );

        this._maxDistance = Infinity;
        this._minDistance = 1e-10; // min distance allowed between eye and target
        this._minSpeed = 1e-10; // set a limit to pan/zoom speed
        this._scaleMouseMotion = 1.0;

        this._inverseMatrix = Matrix.create();

        // if we hit the min distance and can't zoom anymore, maybe we still want to move on
        // with a very low _minDistance, it's like a fps manipulator as long as you don't unzoom
        this._autoPushTarget = true;

        // instance of controller
        var self = this;

        OrbitManipulator.ControllerList.forEach( function ( value ) {
            if ( OrbitManipulator[ value ] !== undefined ) {
                self._controllerList[ value ] = new OrbitManipulator[ value ]( self );
            }
        } );
    },
    setDelay: function ( dt ) {
        this._rotate.setDelay( dt );
        this._pan.setDelay( dt );
        this._zoom.setDelay( dt );
    },
    reset: function () {
        this.init();
    },
    setTarget: function ( target ) {
        Vec3.copy( target, this._target );
        var eyePos = Vec3.create();
        this.getEyePosition( eyePos );
        this._distance = Vec3.distance( eyePos, target );
    },
    setEyePosition: ( function () {
        var f = Vec3.create();
        var s = Vec3.create();
        var u = Vec3.create();
        return function ( eye ) {
            var result = this._rotation;
            var center = this._target;

            Vec3.sub( eye, center, f );
            Vec3.normalize( f, f );

            Vec3.cross( f, this._upz, s );
            Vec3.normalize( s, s );

            Vec3.cross( s, f, u );
            Vec3.normalize( u, u );

            // s[0], f[0], u[0], 0.0,
            // s[1], f[1], u[1], 0.0,
            // s[2], f[2], u[2], 0.0,
{'fraction_non_alphanumeric': 0.13115132845591065, 'fraction_numerical': 0.01594147092799384, 'mean_word_length': 2.10744197176358, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 4, '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': '6181047', 'n_tokens_mistral': 4195, 'n_tokens_neox': 4024, 'n_words': 1023}