package com.ezardlabs.dethsquare;

/**
 * Representation of 2D vectors and points
 */
public final class Vector2 {
	public float x;
	public float y;

	/**
	 * Shorthand for writing Vector2(0, 0)
	 */
	public Vector2() {

	}

	/**
	 * Creates a new vector with the given x and y components
	 */
	public Vector2(float x, float y) {
		this.x = x;
		this.y = y;
	}

	/**
	 * Sets the x and y components of the vector
	 *
	 * @param x the new x component
	 * @param y the new y component
	 */
	public void set(float x, float y) {
		this.x = x;
		this.y = y;
	}

	/**
	 * Returns a new {@link Vector2} that has been offset by the given parameters
	 * @param x The amount to offset the x coordinate by
	 * @param y The amount to offset the y coordinate by
	 * @return The offset {@link Vector2}
	 */
	public Vector2 offset(float x, float y) {
		return new Vector2(this.x + x, this.y + y);
	}

	/**
	 * Calculates the distance between 2 vector points
	 * @param a the first point
	 * @param b the second point
	 * @return The distance between the 2 points
	 */
	public static double distance(Vector2 a, Vector2 b) {
		return Math.sqrt(Math.pow(b.x - a.x, 2) + Math.pow(b.y - a.y, 2));
	}

	@Override
	public String toString() {
		return "Vector2(" + x + ", " + y + ")";
	}

	@Override
	public boolean equals(Object o) {
		return o instanceof Vector2 && ((Vector2) o).x == x && ((Vector2) o).y == y;
	}
}
@@ -510,32 +510,107 @@
 t x, float y) %7B%0A
+%09%09if (listener != null) listener.onVector2Changed(x - this.x, y - this.y);%0A
 %09%09this.x = x;%0A%09%09
@@ -599,32 +599,32 @@
 ;%0A%09%09this.x = x;%0A
-
 %09%09this.y = y;%0A%09%7D
@@ -900,24 +900,81 @@
  float y) %7B%0A
+%09%09if (listener != null) listener.onVector2Changed(x, y);%0A
 %09%09return new
@@ -1433,24 +1433,24 @@
 Object o) %7B%0A
-
 %09%09return o i
@@ -1518,10 +1518,239 @@
 == y;%0A%09%7D
+%0A%0A%09private Vector2ChangeListener listener;%0A%0A%09void setVector2ChangeListener(Vector2ChangeListener listener) %7B%0A%09%09this.listener = listener;%0A%09%7D%0A%0A%09interface Vector2ChangeListener %7B%0A%09%09void onVector2Changed(float xDiff, float yDiff);%0A%09%7D
 %0A%7D

Add ability to listen for changes to a Vector2