Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCG_EDGE_H
Toshihiro Shimizu 890ddd
#define TCG_EDGE_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 e=""></typename>
Toshihiro Shimizu 890ddd
struct edge_traits {
Shinya Kitaoka 120a6e
  typedef typename E::vertices_const_iterator vertices_const_iterator;
Shinya Kitaoka 120a6e
  typedef typename E::vertices_iterator vertices_iterator;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  typedef typename E::faces_const_iterator faces_const_iterator;
Shinya Kitaoka 120a6e
  typedef typename E::faces_iterator faces_iterator;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class Edge {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  typedef const int *vertices_const_iterator;
Shinya Kitaoka 120a6e
  typedef int *vertices_iterator;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  typedef const int *faces_const_iterator;
Shinya Kitaoka 120a6e
  typedef int *faces_iterator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  int m_v[2];
Shinya Kitaoka 120a6e
  int m_f[2];
Shinya Kitaoka 120a6e
  int m_index;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Edge() : m_index(-1) {
Shinya Kitaoka 120a6e
    m_v[0] = -1, m_v[1] = -1;
Shinya Kitaoka 120a6e
    m_f[0] = -1, m_f[1] = -1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  Edge(int v1, int v2) : m_index(-1) {
Shinya Kitaoka 120a6e
    m_v[0] = v1, m_v[1] = v2;
Shinya Kitaoka 120a6e
    m_f[0] = -1, m_f[1] = -1;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ~Edge() {}
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 vertex(int i) const { return m_v[i]; }
Shinya Kitaoka 120a6e
  int verticesCount() const { return m_v[0] < 0 ? 0 : m_v[1] < 0 ? 1 : 2; }
Shinya Kitaoka 120a6e
  int otherVertex(int v) const { return m_v[0] == v ? m_v[1] : m_v[0]; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void addVertex(int v) {
Shinya Kitaoka 120a6e
    assert(verticesCount() < 2);
Shinya Kitaoka 120a6e
    m_v[verticesCount()] = v;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void setVertex(int i, int v) { assert(i < verticesCount()), m_v[i] = v; }
Shinya Kitaoka 120a6e
  vertices_iterator eraseVertex(vertices_iterator it) {
Shinya Kitaoka 120a6e
    *std::copy(it + 1, verticesEnd(), it) = -1;
Shinya Kitaoka 120a6e
    return it;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  vertices_const_iterator verticesBegin() const { return m_v; }
Shinya Kitaoka 120a6e
  vertices_const_iterator verticesEnd() const { return m_v + verticesCount(); }
Shinya Kitaoka 120a6e
  vertices_iterator verticesBegin() { return m_v; }
Shinya Kitaoka 120a6e
  vertices_iterator verticesEnd() { return m_v + verticesCount(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int face(int i) const { return m_f[i]; }
Shinya Kitaoka 120a6e
  int facesCount() const { return m_f[0] < 0 ? 0 : m_f[1] < 0 ? 1 : 2; }
Shinya Kitaoka 120a6e
  int otherFace(int f) const { return m_f[0] == f ? m_f[1] : m_f[0]; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void addFace(int f) {
Shinya Kitaoka 120a6e
    assert(facesCount() < 2);
Shinya Kitaoka 120a6e
    m_f[facesCount()] = f;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void setFace(int i, int f) { assert(i < facesCount()), m_f[i] = f; }
Shinya Kitaoka 120a6e
  faces_iterator eraseFace(faces_iterator it) {
Shinya Kitaoka 120a6e
    *std::copy(it + 1, facesEnd(), it) = -1;
Shinya Kitaoka 120a6e
    return it;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  faces_const_iterator facesBegin() const { return m_f; }
Shinya Kitaoka 120a6e
  faces_const_iterator facesEnd() const { return m_f + facesCount(); }
Shinya Kitaoka 120a6e
  faces_iterator facesBegin() { return m_f; }
Shinya Kitaoka 120a6e
  faces_iterator facesEnd() { return m_f + facesCount(); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace tcg
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // TCG_EDGE_H