package de.frajul.particlelab.data;

/**
 * Created by Julian on 01.12.2015.
 */
public class Vector {

    public float x, y;

    public Vector() {
        this(0, 0);
    }

    public Vector(Vector other) {
        this(other.x, other.y);
    }

    public Vector(float x, float y) {
        set(x, y);
    }

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

    public Vector set(float x, float y) {
        this.x = x;
        this.y = y;
        return this;
    }

    public float length() {
        return (float) Math.sqrt(x * x + y * y);
    }

    public Vector normalize() {
        float length = this.length();
        x /= length;
        y /= length;
        return this;
    }

    public Vector translate(Vector other) {
        this.x += other.x;
        this.y += other.y;
        return this;
    }

    public Vector translate(float x, float y) {
        this.x += x;
        this.y += y;
        return this;
    }

    public Vector mul(float z) {
        x *= z;
        y *= z;
        return this;
    }

    public Vector mul(Vector other) {
        this.x *= other.x;
        this.y *= other.y;
        return this;
    }

    public Vector mul(float x, float y) {
        this.x *= x;
        this.y *= y;
        return this;
    }

    public Vector negate() {
        this.x *= -1;
        this.y *= -1;
        return this;
    }

    public Vector vectorTo(Vector other) {
        float x = other.x - this.x;
        float y = other.y - this.y;
        return new Vector(x, y);
    }

    public void setX(float x) {
        this.x = x;
    }

    public void setY(float y) {
        this.y = y;
    }

    public float getX() {
        return x;
    }

    public float getY() {
        return y;
    }
}
