/* This file is part of the Neper software package. */
/* Copyright (C) 2003-2014, Romain Quey. */
/* See the COPYING file in the top-level directory. */

#include "net_tess_.h"

int
net_tess (struct IN In, int level, struct TESS PTess,
	  int cell, struct SEEDSET *pGSet, int TessId,
	  struct MTESS *pMTess, struct TESS *pTess)
{
  int dim = In.dim;

  if (In.levelqty > 1 && dim == 2)
    dim = 3;

  if (In.morpho[level] && (!strcmp (In.morpho[level], "cube")))
    net_tess_cube (3, PTess, cell, *pGSet, TessId, pTess);
  else if (In.morpho[level] && (!strcmp (In.morpho[level], "square")))
    net_tess_cube (2, PTess, cell, *pGSet, TessId, pTess);
  else
  {
    // standard tessellation
    if (!In.centroid[level])
      net_tess_standard (dim, PTess, cell, *pGSet, TessId, pTess);

    // centroidal tessellation
    else
      net_tess_centroid (dim, In, PTess, cell, pGSet, TessId, pTess);
  }

  if ((*pTess).Dim == 3)
  {
    // finalizing tessellation
    net_tess_set_domain (PTess, cell, TessId, pMTess, pTess);
  }

  net_tess_finalize (pTess);

  net_tess_cells (*pGSet, pTess);

  return 0;
}
