#ifndef D3MINRECURSIVE_H
#define D3MINRECURSIVE_H

#include <cassert>
#include <vector>
using namespace std;

#include <d3minoperator.h>

class d3tess;

//  Brief:  Recursively looks at all links for minimization.
//
//    Plug in the minizizer.
//    The assumption is that there are no loops so a 
//    minimum state can be found, else infinite recursion.
class d3minrecursive 
{
  // Mesh
  d3tess & tess;

  // The client supplied binary minimize operator.
  d3minoperator * minimizer;

  // Do not instanciate this class inside a loop as
  //   STL preallocates memory for efficiency.
  vector<uint> process;

  // Iterate around surrounding simplexes and minimize them.
  bool const minimizesimplex(uintc a);
public:

  // Constructor gets a mesh and minimizer which it
  //   owns.  ie on deletion the minimizer is destructed.
  d3minrecursive(d3tess & _tess, d3minoperator * _minimizer);

  // Destructor releases the minimizer.
  ~d3minrecursive();
 
  // Give an initial simplex to start from.
  //   If the mesh is changed true is returned, else false.
  bool const eval(uintc a);

};

//  Brief: Implements nested recursion as a binary operator.
// 
//         An object is minimized with its neighbours until
//         no such minimization is possible.  Beware of infinite
//         recursion with loops.  This depends on the minimizer.
class d3minrecursiveoperator : public d3minoperator
{
  d3minrecursive x;
public:

  d3minrecursiveoperator(d3tess & _tess, d3minoperator * _minimizer);

  virtual ~d3minrecursiveoperator();

  bool const eval(uintc a, uintc b);

};



#endif



