#ifndef LP_VECTOR2_H
#define LP_VECTOR2_H

#include <math.h>
#include <stdio.h>

class LP_Vector2
{
public:
  LP_Vector2()
  : x(0.0f)
  , y(0.0f)
  {
  }

  LP_Vector2(float aX, float aY)
  : x(aX)
  , y(aY)
  {
  }

  LP_Vector2(LP_Vector2& that)
  : x(that.x)
  , y(that.y)
  {
  }

  ~LP_Vector2()
  {
  }

  LP_Vector2& operator=(const LP_Vector2& that)
  {
    if(this != &that)
    {
      x = that.x;
      y = that.y;
    }
    return *this;
  }

  void Set(const float aX, const float aY)
  {
    x = aX;
    y = aY;
  }

  bool operator==(const LP_Vector2& that)
  {
    if(this == &that)
      return true;
   return x == that.x && y == that.y;
  }

  LP_Vector2& operator+=(const LP_Vector2& that)
  {
    x += that.x;
    y += that.y;
    return *this;
  }

  LP_Vector2& operator-=(const LP_Vector2& that)
  {
    x -= that.x;
    y -= that.y;
    return *this;
  }

  static float DotProd(const LP_Vector2& a, const LP_Vector2& b)
  {
    return a.x * b.x + a.y * b.y;
  }

  static float Dist(const LP_Vector2& a, const LP_Vector2& b)
  {
    float t1 = a.x - b.x;
    float t2 = a.y - b.y;
    return sqrt(t1*t1 + t2*t2);
  }

  static float DistSquared(const LP_Vector2& a, const LP_Vector2& b)
  {
    float t1 = a.x - b.x;
    float t2 = a.y - b.y;
    return t1*t1 + t2*t2;
  }

  float Length() const
  {
    return sqrt(x*x + y*y);
  }

  void Scale(const float scaleFactor)
  {
    x *= scaleFactor;
    y *= scaleFactor;
  }

  void Normalize(float scaleFactor)
  {
    scaleFactor = scaleFactor / sqrt(x*x + y*y);
    x *= scaleFactor;
    y *= scaleFactor;
  }

  void Print() const
  {
    printf("x: %f y: %f\n", x, y);
  }

  float x, y;
};

#endif
