<commit_before>(function (window, undefined) {
    "use strict";

    if (!window.Trios2D)
        throw new Error("You must include Trios2D in your HTML");

    var Trios2D = window.Trios2D,
        Vector = Trios2D.Vector,
        GameObject = Trios2D.GameObject,
        Component = Trios2D.Component;


    function Physics() {
        // Calling Component Constructor
        Component.apply(this);

        this._velocity = new Vector();
        this._aceleration = new Vector();

        this._lastVelocity = this._velocity;

    }

    Physics.prototype = Object.create(Component.prototype, {
        position: {
            get: function position() {
                if (this.gameObject) {
                    return this.gameObject.position;
                }
            },

            set: function position(val) {
                if (this.gameObject) {
                    this.gameObject.position = val;
                }
            },

            enumerable: true
        },

        velocity: {
            get: function velocity() {
                if (this.position.equal(this._lastPosition || this.position)) {
                    return this._velocity;
                } else {
                    // immediat position change would make the velocity increases in the update frame where it was made
                    return this.position.sub(this._lastPosition).divide(this._lastDelta / 1000);
                }
            },

            set: function  velocity(val) {
                this._velocity = val;
            }
        },

        aceleration: {
            get: function aceleration() {
                if (this.velocity.equal(this._lastVelocity)) {
                    return this._aceleration;
                } else {
                    // immediat velocity change would make the aceleration increases in the update frame where it was made
                    return this.velocity.sub(this._lastVelocity).divide(this._lastDelta / 1000);
                }
            },

            set: function aceleration(val) {
                this._aceleration = val;
            }
        }

    });

    Physics.prototype.update = function update(delta, gameObject) {

        if (this._aceleration.hasValue()) {
            this._velocity = this._velocity.add(this._aceleration.multiply(delta / 1000));
        }

        if (this._velocity.hasValue()) {
            this.position = this.position.add(this._velocity.multiply(delta / 1000));
        }


        this._lastVelocity = this.velocity;
        this._lastPosition = this.position;
        this._lastDelta = delta;
    };


    window.Trios2D.Components.Physics = Physics;

}(window));<commit_msg>Physics qhich calculates the velocity with the position variation and the aceleration with velocity variation finished. (Does not modifies the internal value)<commit_after>(function (window, undefined) {
    "use strict";

    if (!window.Trios2D)
        throw new Error("You must include Trios2D in your HTML");

    var Trios2D = window.Trios2D,
        Vector = Trios2D.Vector,
        GameObject = Trios2D.GameObject,
        Component = Trios2D.Component;


    function Physics() {
        // Calling Component Constructor
        Component.apply(this);

        this._velocity = new Vector();
        this._aceleration = new Vector();

        this._lastVelocity = this._velocity;

    }

    Physics.prototype = Object.create(Component.prototype, {
        position: {
            get: function position() {
                if (this.gameObject) {
                    return this.gameObject.position;
                }
            },

            set: function position(val) {
                if (this.gameObject) {
                    this.gameObject.position = val;
                }
            },

            enumerable: true
        },

        velocity: {
            get: function velocity() {
                if (this.position.equal(this._lastPosition || this.position)) {
                    return this._velocity;
                } else {
                    // immediat position change would make the velocity increases in the update frame where it was made
                    return this.position.sub(this._lastPosition).divide(this._lastDelta / 1000).round(5);
                }
            },

            set: function  velocity(val) {
                this._velocity = val;
                this._lastPosition = undefined;
            }
        },

        aceleration: {
            get: function aceleration() {
                if (this.velocity.equal(this._lastVelocity)) {
                    return this._aceleration;
                } else {
                    // immediat velocity change would make the aceleration increases in the update frame where it was made
                    return this.velocity.sub(this._lastVelocity).divide(this._lastDelta / 1000).round(5);
                }
            },

            set: function aceleration(val) {
                this._aceleration = val;
                this._lastVelocity = this._velocity;

            }
        }

    });

    Physics.prototype.update = function update(delta, gameObject) {

        if (this._aceleration.hasValue()) {
            this._velocity = this._velocity.add(this._aceleration.multiply(delta / 1000));
        }

        if (this._velocity.hasValue()) {
            this.position = this.position.add(this._velocity.multiply(delta / 1000));
        }

//
////        this._lastPosition = this.position;
//        this._lastVelocity = this.velocity;
//        this._lastPosition = this.position;
//
        this._lastDelta = delta;
    };

    Physics.prototype.postupdate = function postupdate(delta, gameObject) {

//        this._lastPosition = this.position;
        this._lastVelocity = this.velocity;
        this._lastPosition = this.position;

//        this._lastDelta = delta;
    };


    window.Trios2D.Components.Physics = Physics;

}(window));
{'fraction_non_alphanumeric': 0.09739714525608732, 'fraction_numerical': 0.008396305625524769, 'mean_word_length': 1.6031468531468531, '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': '6161327', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1454, 'n_words': 334}