#include "Face.hpp"
#include "Graphics.hpp"
#ifdef _MSC_VER
  #include <windows.h>
  #define GLEW_STATIC
  #include <GL/glew.h>
#else
  #include <GL/gl.h>
#endif

Face::Face(const Vertex* v) {
  vertex = v;
}

void Face::render() const {
  glBegin(GL_POINTS);
  vertex->render();
  glEnd();
}

const bool Face::contain(const Vertex* v) const {
  return vertex == v;
}

const bool Face::isDegenerated() const {
  return false;
}

Face& Face::swap(
  const Vertex* o,
  const Vertex* n
) {
  if (vertex == o) {
    vertex = n;
  }
  return *this;
}

Face* Face::clone() const {
  return new Face(vertex);
}

LineFace::LineFace(
  const Vertex* v,
  const Vertex* v2
) : Face(v) {
  vertex2 = v2;
}

void LineFace::render() const {
  glBegin(GL_LINES);
  vertex->render();
  vertex2->render();
  glEnd();
}

const bool LineFace::contain(const Vertex* v) const {
  return Face::contain(v) || vertex2 == v;
}

const bool LineFace::isDegenerated() const {
  return vertex == vertex2;
}

Face& LineFace::swap(
  const Vertex* o,
  const Vertex* n
) {
  if (vertex2 == o) {
    vertex2 = n;
  }
  return Face::swap(
    o,
    n
  );
}

Face* LineFace::clone() const {
  return new LineFace(
    vertex,
    vertex2
  );
}

TriangleFace::TriangleFace(
  const Vertex* v,
  const Vertex* v2,
  const Vertex* v3
) : LineFace(
  v,
  v2
) {
  vertex3 = v3;
}

void TriangleFace::render() const {
  glBegin(GL_TRIANGLES);
  vertex->render();
  vertex2->render();
  vertex3->render();
  glEnd();
}

const bool TriangleFace::contain(const Vertex* v) const {
  return LineFace::contain(v) || vertex3 == v;
}

const bool TriangleFace::isDegenerated() const {
  return LineFace::isDegenerated() || vertex == vertex3 || vertex2 == vertex3;
}

Face& TriangleFace::swap(
  const Vertex* o,
  const Vertex* n
) {
  if (vertex3 == o) {
    vertex3 = n;
  }
  return LineFace::swap(
    o,
    n
  );
}

Face* TriangleFace::clone() const {
  return new TriangleFace(
    vertex,
    vertex2,
    vertex3
  );
}
