/*
 * MelonJS Game Engine
 * Copyright (C) 2011 - 2015, Olivier Biot, Jason Oster, Aaron McLeod
 * http://www.melonjs.org
 *
 */

me.ObservableVector2d = me.Vector2d.extend({
    /**
     * A Vector2d object that executes an onUpdate function. Use this over me.Vector2d when you need to know each time the vector is moved.
     * @class
     * @extends me.Vector2d
     * @constructor
     * @param {Number} [x=0] x value of the vector
     * @param {Number} [y=0] y value of the vector
     */
    init : function (x, y, settings) {
        /**
         * x value of the vector
         * @public
         * @type Number
         * @name x
         * @memberOf me.ObservableVector2d
         */
        Object.defineProperty(this, "x", {
            get : function () {
                return this._x;
            },

            set : function (value) {
                this.onUpdate(value, this._y, this._x, this._y);
                this._x = value;
            }
        });

        /**
         * y value of the vector
         * @public
         * @type Number
         * @name y
         * @memberOf me.ObservableVector2d
         */
        Object.defineProperty(this, "y", {
            get : function () {
                return this._y;
            },

            set : function (value) {
                this.onUpdate(this._x, value, this._x, this._y);
                this._y = value;
            }
        });

        this.onUpdate = settings.onUpdate;
        this._x = x;
        this._y = y;
    },

    /**
     * Add the passed vector to this vector
     * @name add
     * @memberOf me.ObservableVector2d
     * @function
     * @param {me.Vector2d} v
     * @return {me.ObservableVector2d} Reference to this object for method chaining
     */
    add : function (v) {
        var oldX = this._x;
        var oldY = this._y;
        this._x += v.x;
        this._y += v.y;
        this.onUpdate(this._x, oldX, this._y, oldY);
        return this;
    },

    /**
     * set the Vector x and y properties to the given values<br>
     * @name set
     * @memberOf me.ObservableVector2d
     * @function
     * @param {Number} x
     * @param {Number} y
     * @return {me.ObservableVector2d} Reference to this object for method chaining
     */
    set : function (x, y) {
        if (x !== +x || y !== +y) {
            throw new me.Vector2d.Error(
                "invalid x,y parameters (not a number)"
            );
        }

        var oldX = this._x;
        var oldY = this._y;
        this._x = x;
        this._y = y;
        this.onUpdate(this._x, oldX, this._y, oldY);

        return this;
    },

    /**
     * set the Vector x and y properties using the passed vector
     * @name setV
     * @memberOf me.ObservableVector2d
     * @function
     * @param {me.ObservableVector2d} v
     * @return {me.ObservableVector2d} Reference to this object for method chaining
     */
    setV : function (v) {
        return this.set(v.x, v.y);
    },

    /**
     * Substract the passed vector to this vector
     * @name sub
     * @memberOf me.ObservableVector2d
     * @function
     * @param {me.Vector2d} v
     * @return {me.ObservableVector2d} Reference to this object for method chaining
     */
    sub : function (v) {
        var oldX = this._x;
        var oldY = this._y;
        this._x -= v.x;
        this._y -= v.y;
        this.onUpdate(this._x, oldX, this._y, oldY);
        return this;
    }
});
@@ -1798,78 +1798,69 @@
     
-var oldX = this._x;%0A        var oldY = this._y;%0A        this._x += v.x
+this.onUpdate(this._x + v.x, this._x + v.y, this._x, this._y)
 ;%0A  
@@ -1875,16 +1875,16 @@
 is._
-y
+x
  += v.
-y
+x
 ;%0A  
@@ -1898,46 +1898,17 @@
 his.
-onUpdate(this._x, oldX, this._y, oldY)
+_y += v.y
 ;%0A  
@@ -2421,54 +2421,44 @@
     
-var oldX = this._x;%0A        var oldY =
+this.onUpdate(x, y, this._x,
  this._y
 ;%0A  
@@ -2445,32 +2445,33 @@
 this._x, this._y
+)
 ;%0A        this._
@@ -2501,61 +2501,8 @@
 = y;
-%0A        this.onUpdate(this._x, oldX, this._y, oldY);
 %0A%0A  
@@ -3166,78 +3166,69 @@
     
-var oldX = this._x;%0A        var oldY = this._y;%0A        this._x -= v.x
+this.onUpdate(this._x - v.x, this._x - v.y, this._x, this._y)
 ;%0A  
@@ -3243,16 +3243,16 @@
 is._
-y
+x
  -= v.
-y
+x
 ;%0A  
@@ -3266,46 +3266,17 @@
 his.
-onUpdate(this._x, oldX, this._y, oldY)
+_y -= v.y
 ;%0A  
@@ -3303,8 +3303,9 @@
    %7D%0A%7D);
+%0A

Fix me.ObservableVector2d callback arguments