#include "Line.hpp"

Line::Line(
  const Vector& n,
  const Vector& o
) {
  set(
    n,
    o
  );
}

Line& Line::set(
  const Vector& n,
  const Vector& o
) {
  (normal = n).normalize();
  origin = o;
  return *this;
}

const Vector& Line::getNormal() const {
  return normal;
}

const Vector& Line::getOrigin() const {
  return origin;
}

const double Line::getDistance(const Vector& v) const {
  return sqrt(
    (
      pow(
        (
          (v.x - origin.x) * normal.y - (v.y - origin.y) * normal.x
        ),
        2
      ) + pow(
        (
          (v.y - origin.y) * normal.z - (v.z - origin.z) * normal.y
        ),
        2
      ) + pow(
        (
          (v.z - origin.z) * normal.x - (v.x - origin.x) * normal.z
        ),
        2
      )
    ) / normal.getSquaredLength()
  );
}
