// *********************************************************
// Triangle Class
// Author : Tamy Boubekeur (boubek@gmail.com).
// Copyright (C) 2008 Tamy Boubekeur.
// All rights reserved.
// *********************************************************

#ifndef TRIANGLE_H
#define TRIANGLE_H

#include <iostream>
#include <vector>
#include "Vertex.h"
#include "Vec3D.h"

class Triangle {
public:
    Triangle () { init (0, 0, 0); }
    Triangle (unsigned int v0, unsigned int v1, unsigned int v2) { init (v0, v1, v2); }
    Triangle (const unsigned int * vp) { init (vp[0], vp[1], vp[2]); }
    Triangle (const Triangle & it) { init (it.v[0], it.v[1], it.v[2]); }
    virtual ~Triangle () {}
    Triangle & operator= (const Triangle & it) { init (it.v[0], it.v[1], it.v[2]); return (*this); }
    bool operator== (const Triangle & t) const { return (v[0] == t.v[0] && v[1] == t.v[1] && v[2] == t.v[2]); }
    unsigned int getVertex (unsigned int i) const { return v[i]; }
    void setVertex (unsigned int i, unsigned int vertex) { v[i] = vertex; }
    bool contains (unsigned int vertex) const { return (v[0] == vertex || v[1] == vertex || v[2] == vertex); }
    float minPos(unsigned int axis, const std::vector<Vertex>& vertices) const;
    float maxPos(unsigned int axis, const std::vector<Vertex>& vertices) const;
  
protected:
    inline void init (unsigned int v0, unsigned int v1, unsigned int v2) {
        v[0] = v0; v[1] = v1; v[2] = v2;  
    }
  
private:
    unsigned int v[3];
};

extern std::ostream & operator<< (std::ostream & output, const Triangle & t);


#endif // TRIANGLE_H

// Some Emacs-Hints -- please don't remove:
//
//  Local Variables:
//  mode:C++
//  tab-width:4
//  End:
