class Vector
{
  float x;
  float y;

  Vector() {}
  
  Vector(float x, float y)
  {
    this.x = x;
    this.y = y;
  }
  
  Vector(Vector vec)
  {
    x = vec.x;
    y = vec.y;
  }
  
  Vector set(float x, float y)
  {
    this.x = x;
    this.y = y;
    return this;
  }
  
  Vector set(Vector vec)
  {
    x = vec.x;
    y = vec.y;
    return this;
  }
  
  void zero()
  {
    x = y = 0;
  }
  
  Vector negate()
  {
    return new Vector(-x, -y);
  }
  
  Vector negateLocal()
  {
    x = -x;
    y = -y;
    return this;
  }
  
  Vector add(Vector vec)
  {
    return new Vector(x + vec.x, y + vec.y);
  }
  
  Vector addLocal(Vector vec)
  {
    x += vec.x;
    y += vec.y;
    return this;
  }
  
  Vector subtract(Vector vec)
  {
    return new Vector(x - vec.x, y - vec.y);
  }
  
  Vector subtractLocal(Vector vec)
  {
    x -= vec.x;
    y -= vec.y;
    return this;
  }
  
  Vector divide(float scalar)
  {
    return new Vector(x / scalar, y / scalar);
  }
  
  Vector divideLocal(float scalar)
  {
    x /= scalar;
    y /= scalar;
    return this;
  }
  
  Vector mult(float scalar)
  {
    return new Vector(x * scalar, y * scalar);
  }
  
  Vector multLocal(float scalar)
  {
    x *= scalar;
    y *= scalar;
    return this;
  }
  
  float length()
  {
    return sqrt(x * x + y * y);
  }
  
  Vector normalize()
  {
    float length = length();
    if (length != 0) {
      return divide(length);
    }
    return divide(1);
  }

  Vector normalizeLocal()
  {
    float length = length();
    if (length != 0) {
      return divideLocal(length);
    }
    return divideLocal(1);
  }
  
  Vector clone()
  {
    return new Vector(x, y);
  }
}
