<commit_before>'use strict';
define(
    [
        'config',
        'three',
        'Debug',
        'AstronomicalObject',
        'enums/AstronomicalObjectType',
        'GameObjectManager'
    ],
    function(config, THREE, Debug, AstronomicalObject, AstronomicalObjectType, GameObjectManager) {
        return class SpaceShip extends AstronomicalObject {

            // ##############################################
            // # Constructor ################################
            // ##############################################

            constructor(scene, name, options) {
                super();

                this.scene    = scene;

                this.name     = name;
                this.mass     = options.mass     || 5;
                this.position = options.position || new THREE.Vector3();
                this.color    = options.color    || 0x7fffd4;

                this.orientation = new THREE.Vector3(1, 0, 0);

                let scope = this;

                let loader = new THREE.JSONLoader();
                loader.load(options.model, function(shipGeometry, shipMaterials) {
                    let shipMaterial = new THREE.MultiMaterial(shipMaterials);
                    scope.mesh        = new THREE.Mesh(shipGeometry, shipMaterial);
                    scene.add(scope.mesh);

                    scope._createPositionIndicator();
                    scope._createInitialTrajectory();
                    scope._createYPosition(scene);
                });

                if(config.showDirectionalVectors) {
                    this.arrowMesh = this._createDirectionalArrow();
                    this.scene.add(this.arrowMesh);
                }
            }

            // ##############################################
            // # Private functions ##########################
            // ##############################################

            _createPositionIndicator() {
                let positionIndicatorGeometry = new THREE.Geometry();
                    
                let numberSegments = 16;
                let circleSegment = 2 * Math.PI / numberSegments;
                let circleRadius = this.mesh.geometry.boundingSphere.radius * 1.1;

                for(let i = 0; i <= numberSegments; i++) {
                    let vector = new THREE.Vector3(
                        circleRadius * Math.cos(i * circleSegment),
                        0,
                        circleRadius * Math.sin(i * circleSegment)
                    );

                    positionIndicatorGeometry.vertices.push(vector);
                }
                
                let positionIndicatorMaterial = new THREE.LineBasicMaterial({ color: 0x7fffd4 });
                this.positionIndicator        = new THREE.Line(positionIndicatorGeometry, positionIndicatorMaterial);
                this.scene.add(this.positionIndicator);
            }

            // ##############################################

            _createInitialTrajectory() {
                let geometry  = new THREE.BufferGeometry();
                let material  = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
                let positions = [this.position.x, this.position.y, this.position.z];
                let colors    = [1, 1, 1];

                geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
                geometry.addAttribute('color',    new THREE.BufferAttribute(new Float32Array(colors),    3));

                this.trajectory = new THREE.Line(geometry, material);
                this.scene.add(this.trajectory);
            }

            // ##############################################

            _updateTrajectory(deltaT, smoothDeltaT) {
                if(this.trajectory) {
                    let positions   = [this.position.x, this.position.y, this.position.z];
                    let colors      = [1, 1, 1];
                    let tPosition   = this.position.clone();
                    let tVelocity   = this.velocity.clone();
                    let n           = 1000;
                    let gameObjects = GameObjectManager.get();

                    for(let i = 1; i < n; i++) {
                        let tAcceleration = this.force(
                                tPosition,
                                this.mass,
                                this.id,
                                gameObjects)
                            .divideScalar(this.mass);

                        tPosition = tPosition.add(
                            tVelocity
                                .add(tAcceleration.multiplyScalar(smoothDeltaT / 2))
                        );

                        let newAcceleration = this.force(
                                tPosition,
                                this.mass,
                                this.id, gameObjects)
                            .divideScalar(this.mass);

                        tVelocity = tVelocity.add(
                            tAcceleration.add(newAcceleration).multiplyScalar(smoothDeltaT)
                        );

                        let col = 1 - (i / n / 2 + 0.5);

                        if(i % 25 == 0) {
                            positions.push(tPosition.x, tPosition.y, tPosition.z);
                            colors.push(col, col, col);
                        }
                    }
                    
                    this.trajectory.geometry.dispose();
                    this.trajectory.geometry = null;
                    this.trajectory.geometry = new THREE.BufferGeometry();
                    
                    this.trajectory.geometry.attributes.position = new THREE.BufferAttribute(new Float32Array(positions), 3);
                    this.trajectory.geometry.attributes.color    = new THREE.BufferAttribute(new Float32Array(colors),    3);
                }
            }

            // ##############################################
            // # Public functions ###########################
            // ##############################################
            
            update(deltaT, smoothDeltaT, spaceObjects) {
                super.update(deltaT, smoothDeltaT, spaceObjects);

                this._updateTrajectory(deltaT, smoothDeltaT, spaceObjects);

                if(this.mesh) {
                    this._updateYPosition();
                }

                let camera = this.scene.camera.camera;

                if(this.mesh == null) return;
                this.mesh.position.set(this.position.x, this.position.y, this.position.z);
                this.positionIndicator.position.set(this.position.x, this.position.y, this.position.z);
                this.positionIndicator.scale.set(
                    2 + 1 / camera.zoom,
                    2 + 1 / camera.zoom,
                    2 + 1 / camera.zoom
                );

                if(camera.zoom >= 25) {<commit_msg>Keeping SpaceShip's position indicator on y=0<commit_after>'use strict';
define(
    [
        'config',
        'three',
        'Debug',
        'AstronomicalObject',
        'enums/AstronomicalObjectType',
        'GameObjectManager'
    ],
    function(config, THREE, Debug, AstronomicalObject, AstronomicalObjectType, GameObjectManager) {
        return class SpaceShip extends AstronomicalObject {

            // ##############################################
            // # Constructor ################################
            // ##############################################

            constructor(scene, name, options) {
                super();

                this.scene    = scene;

                this.name     = name;
                this.mass     = options.mass     || 5;
                this.position = options.position || new THREE.Vector3();
                this.color    = options.color    || 0x7fffd4;

                this.orientation = new THREE.Vector3(1, 0, 0);

                let scope = this;

                let loader = new THREE.JSONLoader();
                loader.load(options.model, function(shipGeometry, shipMaterials) {
                    let shipMaterial = new THREE.MultiMaterial(shipMaterials);
                    scope.mesh        = new THREE.Mesh(shipGeometry, shipMaterial);
                    scene.add(scope.mesh);

                    scope._createPositionIndicator();
                    scope._createInitialTrajectory();
                    scope._createYPosition(scene);
                });

                if(config.showDirectionalVectors) {
                    this.arrowMesh = this._createDirectionalArrow();
                    this.scene.add(this.arrowMesh);
                }
            }

            // ##############################################
            // # Private functions ##########################
            // ##############################################

            _createPositionIndicator() {
                let positionIndicatorGeometry = new THREE.Geometry();
                    
                let numberSegments = 16;
                let circleSegment = 2 * Math.PI / numberSegments;
                let circleRadius = this.mesh.geometry.boundingSphere.radius * 1.1;

                for(let i = 0; i <= numberSegments; i++) {
                    let vector = new THREE.Vector3(
                        circleRadius * Math.cos(i * circleSegment),
                        0,
                        circleRadius * Math.sin(i * circleSegment)
                    );

                    positionIndicatorGeometry.vertices.push(vector);
                }
                
                let positionIndicatorMaterial = new THREE.LineBasicMaterial({ color: 0x7fffd4 });
                this.positionIndicator        = new THREE.Line(positionIndicatorGeometry, positionIndicatorMaterial);
                this.scene.add(this.positionIndicator);
            }

            // ##############################################

            _createInitialTrajectory() {
                let geometry  = new THREE.BufferGeometry();
                let material  = new THREE.LineBasicMaterial({ vertexColors: THREE.VertexColors });
                let positions = [this.position.x, this.position.y, this.position.z];
                let colors    = [1, 1, 1];

                geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
                geometry.addAttribute('color',    new THREE.BufferAttribute(new Float32Array(colors),    3));

                this.trajectory = new THREE.Line(geometry, material);
                this.scene.add(this.trajectory);
            }

            // ##############################################

            _updateTrajectory(deltaT, smoothDeltaT) {
                if(this.trajectory) {
                    let positions   = [this.position.x, this.position.y, this.position.z];
                    let colors      = [1, 1, 1];
                    let tPosition   = this.position.clone();
                    let tVelocity   = this.velocity.clone();
                    let n           = 1000;
                    let gameObjects = GameObjectManager.get();

                    for(let i = 1; i < n; i++) {
                        let tAcceleration = this.force(
                                tPosition,
                                this.mass,
                                this.id,
                                gameObjects)
                            .divideScalar(this.mass);

                        tPosition = tPosition.add(
                            tVelocity
                                .add(tAcceleration.multiplyScalar(smoothDeltaT / 2))
                        );

                        let newAcceleration = this.force(
                                tPosition,
                                this.mass,
                                this.id, gameObjects)
                            .divideScalar(this.mass);

                        tVelocity = tVelocity.add(
                            tAcceleration.add(newAcceleration).multiplyScalar(smoothDeltaT)
                        );

                        let col = 1 - (i / n / 2 + 0.5);

                        if(i % 25 == 0) {
                            positions.push(tPosition.x, tPosition.y, tPosition.z);
                            colors.push(col, col, col);
                        }
                    }
                    
                    this.trajectory.geometry.dispose();
                    this.trajectory.geometry = null;
                    this.trajectory.geometry = new THREE.BufferGeometry();
                    
                    this.trajectory.geometry.attributes.position = new THREE.BufferAttribute(new Float32Array(positions), 3);
                    this.trajectory.geometry.attributes.color    = new THREE.BufferAttribute(new Float32Array(colors),    3);
                }
            }

            // ##############################################
            // # Public functions ###########################
            // ##############################################
            
            update(deltaT, smoothDeltaT, spaceObjects) {
                super.update(deltaT, smoothDeltaT, spaceObjects);

                this._updateTrajectory(deltaT, smoothDeltaT, spaceObjects);

                if(this.mesh) {
                    this._updateYPosition();
                }

                let camera = this.scene.camera.camera;

                if(this.mesh == null) return;
                this.mesh.position.set(this.position.x, this.position.y, this.position.z);
                this.positionIndicator.position.set(this.position.x, 0, this.position.z);
                this.positionIndicator.scale.set(
                    2 + 1 / camera.zoom,
                    2 + 1 / camera.zoom,
                    2 + 1 / camera.zoom
                );

                if(camera.zoom >= 25) {
{'fraction_non_alphanumeric': 0.14935622317596567, 'fraction_numerical': 0.008583690987124463, 'mean_word_length': 1.2912159947558177, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2066478', 'n_tokens_mistral': 3431, 'n_tokens_neox': 3053, 'n_words': 561}