#include "GR_config.h"
#ifdef BROKEN_INLINE
#include "GR_assert.h"
#include "GR_BFace.h"

BFaceCV::BFaceCV(const int iNV, Vert** const ppVIn, const
                             int iBCIn)
{
  assert(iNV >= 1 && iNV <= 4);
  iN = iNV;
  iBC = iBCIn;
  ppV = new Vert*[iNV];
  if (ppVIn) {
    for (int i = 0; i < iNV; i++) {
      if (ppVIn[i] == pVInvalidVert)
        vFatalError("Invalid vertex assigned to boundary face",
                    "BFaceCV constructor");
      ppV[i] = ppVIn[i];
    }
  }
  else {
    for (int i = 0; i < iNV; i++)
      ppV[i] = pVInvalidVert;
  }
}

bool BFaceCV::qHasVert(Vert* const pV) const
{
  assert(pV->qValid());
  for (int i = 0; i < iN; i++)
    if (pV == ppV[i]) return true;
  return false;
}

void BFaceCV::vReplaceVert(Vert* const pVOld, Vert* const pVNew)
{
  assert2(pVOld->qValid(), "Tried to replace non-existent vert");
  assert2(pVNew->qValid(), "Tried to add non-existent vert");
  int iRepl = -1;
  int i;
  for (i = 0; i < iN; i++) {
    assert2(pVNew != ppV[i], "Vert already exists for this BFace");
    if (ppV[i] == pVOld) iRepl = i;
  }
  assert2(iRepl >= 0, "Tried to replace vert which doesn't bound this BFace");
  if (i < 0) vFatalError("Tried to replace vert which didn't bound face",
                         "BFace::vReplaceVert");
  ppV[iRepl] = pVNew;
}

void BFaceCV::vSetVerts(const int iNV, Vert** const ppVIn)
{
  assert(iNV >= 1 && iNV <= 4);
  if (ppV && iNV != iN) {
    delete [] ppV;
    ppV = new Vert*[iNV];
  }
  else if (!ppV)
    ppV = new Vert*[iNV];
  iN = iNV;
  for (int i = 0; i < iNV; i++) {
    if (ppVIn[i] == pVInvalidVert || !ppVIn[i]->qValid())
      vFatalError("Invalid vertex assigned to boundary face",
                  "BFaceCV constructor");
    ppV[i] = ppVIn[i];
  }
}

#endif


