Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCG_FACE_H
Toshihiro Shimizu 890ddd
#define TCG_FACE_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include "assert.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace tcg {
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename f=""></typename>
Toshihiro Shimizu 890ddd
struct face_traits {
Shinya Kitaoka 120a6e
  typedef typename F::edges_const_iterator edges_const_iterator;
Shinya Kitaoka 120a6e
  typedef typename F::edges_iterator edges_iterator;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class Face {
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  int m_index;
Shinya Kitaoka 120a6e
  tcg::list<int> m_edges;</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef tcg::list<int>::const_iterator edges_const_iterator;</int>
Shinya Kitaoka 120a6e
  typedef tcg::list<int>::iterator edges_iterator;</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Face() : m_index(-1) {}
Shinya Kitaoka 120a6e
  ~Face() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setIndex(int idx) { m_index = idx; }
Shinya Kitaoka 120a6e
  int getIndex() const { return m_index; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int edge(int e) const { return m_edges[e]; }
Shinya Kitaoka 120a6e
  int &edge(int e) { return m_edges[e]; }
Shinya Kitaoka 120a6e
  int edgesCount() const { return (int)m_edges.size(); }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void addEdge(int idx) { m_edges.push_back(idx); }
Shinya Kitaoka 120a6e
  edges_iterator eraseEdge(const edges_iterator &it) {
Shinya Kitaoka 120a6e
    return m_edges.erase(it);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  edges_const_iterator edgesBegin() const { return m_edges.begin(); }
Shinya Kitaoka 120a6e
  edges_const_iterator edgesEnd() const { return m_edges.end(); }
Shinya Kitaoka 120a6e
  edges_iterator edgesBegin() { return m_edges.begin(); }
Shinya Kitaoka 120a6e
  edges_iterator edgesEnd() { return m_edges.end(); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <int n=""></int>
Shinya Kitaoka 120a6e
class FaceN {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef const int *edges_const_iterator;
Shinya Kitaoka 120a6e
  typedef int *edges_iterator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  int m_e[N], m_count;
Shinya Kitaoka 120a6e
  int m_index;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FaceN() : m_index(-1), m_count(0) { std::fill(m_e, m_e + N, -1); }
Shinya Kitaoka 120a6e
  FaceN(int (&edges)[N]) : m_index(-1), m_count(0) {
Shinya Kitaoka 120a6e
    std::copy(edges, edges + N, m_e), m_count = N;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ~FaceN() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setIndex(int idx) { m_index = idx; }
Shinya Kitaoka 120a6e
  int getIndex() const { return m_index; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int edge(int e) const {
Shinya Kitaoka 120a6e
    assert(e < m_count);
Shinya Kitaoka 120a6e
    return m_e[e];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int &edge(int e) {
Shinya Kitaoka 120a6e
    assert(e < m_count);
Shinya Kitaoka 120a6e
    return m_e[e];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  int edgesCount() const { return m_count; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void addEdge(int idx) {
Shinya Kitaoka 120a6e
    assert(m_count < N);
Shinya Kitaoka 120a6e
    m_e[m_count++] = idx;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void setEdge(int e, int idx) {
Shinya Kitaoka 120a6e
    assert(e < m_count);
Shinya Kitaoka 120a6e
    m_e[e] = idx;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  edges_iterator eraseEdge(const edges_iterator &it) {
Shinya Kitaoka 120a6e
    std::copy(it + 1, edgesEnd(), it);
Shinya Kitaoka 120a6e
    m_e[--m_count] = -1;
Shinya Kitaoka 120a6e
    return it;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  edges_const_iterator edgesBegin() const { return m_e; }
Shinya Kitaoka 120a6e
  edges_const_iterator edgesEnd() const { return m_e + m_count; }
Shinya Kitaoka 120a6e
  edges_iterator edgesBegin() { return m_e; }
Shinya Kitaoka 120a6e
  edges_iterator edgesEnd() { return m_e + m_count; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace tcg
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // TCG_FACE_H