/*
    C++ Mesh Generation Library
    Copyright (c) 2000echet <eric at bechet dot ca>

    This file is part of the C++ Mesh Generation Library.

    See the NOTICE & LICENSE files for conditions.
*/
//---------------------------------------------------------------------------
#ifndef SIZE_FUNCTION_H
#define SIZE_FUNCTION_H
//---------------------------------------------------------------------------


#include "mesh_const.h"

#include "metric_field.h"


/// Size function class
template<class V> class Size_Function
{
private:

///
  V *v1,*v2;
///
  Vector Vect;
///
  Metric_Field<V> *Metric_at_node;


public :
///
  Size_Function ( V &V1, V &V2, Metric_Field<V> &M ) :Vect ( V::Dimension )
  {
    v1=&V1;
    v2=&V2;

    for ( int i=0; i<V::Dimension; ++i )
    {
      Vect[i]=V2[i]-V1[i];
    }

    Metric_at_node=&M;
  }

///
  double operator() ( double t )
  {
    Metric_Tensor MM ( V::Dimension );
    V Node;

    for ( int i=0; i<V::Dimension; ++i )
    {
      Node[i]= ( *v1 ) [i]* ( 1.-t ) + ( *v2 ) [i]* ( t );
    }

    ( *Metric_at_node ) ( Node,MM );
    return MM.Calculate_Length ( Vect );
  }
};

#endif // SIZE_FUNCTION_H

 
