/*
    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 FM_SPointToDouble_H
#define FM_SPointToDouble_H

#include "SPoint3.h"

class SPointToDouble
{
public:
  virtual double operator()(SPoint3 pt) const=0;
};

class SZero : public SPointToDouble // dummy function that yields 0 everywhere
{
public:
  virtual double operator() (SPoint3 pt) const 
  {
    return 0.;
  }
};

class SPlane : public SPointToDouble
{
  SPoint3 p;
  SVector3 n;
public:
  SPlane(SPoint3 p_,SVector3 n_):p(p_),n(n_)
  {
    n.normalize();
  }
  virtual double operator() (SPoint3 pt) const 
  {
    SVector3 vec(p,pt);
    double dotp=dot(vec,n);
    return dotp;
  }
};

class SCylinder : public SPointToDouble
{
  SPoint3 p;
  SVector3 n;
  double r;
public:
  SCylinder(SPoint3 p_,SVector3 n_,double r_):p(p_),n(n_),r(r_)
  {
    n.normalize();
  }
  virtual double operator()  (SPoint3 pt) const
  {
    SVector3 vec(p,pt);
    double dotp=dot(vec,n);
    SVector3 vec2=n*dotp;
    SVector3 rr=vec-vec2;
    double dist=rr.norm();
    return dist-r;
  }
};

class SSphere : public SPointToDouble
{
  SPoint3 p;
  double r;
public:
  SSphere(SPoint3 p_,double r_):p(p_),r(r_)
  {  }
  virtual double operator()  (SPoint3 pt) const
  {
    SVector3 vec(p,pt);
    double dist=vec.norm();
    return dist-r;
  }
};

#endif // FM_SPointToDouble_H