#ifndef BERNSTEIN_H
#define BERNSTEIN_N


#include <print.h>

/*!
\brief Bernstein Polynomial

Defined as (n,i)*t^i*(1-t)^(n-i).
*/
class bernsteinPoly
{
public:
  /** The leading coefficient */
  double coeff;

  /** The degree */
  uint n;
  /** Which polynomial 0..n */
  uint i;

  /** Realizes the function with the current values of n and i. */
  void construct();

  /** Construct the function. */
  void construct( uintc n_, uintc i_);

  /** Dummy constructor, call construct() later. */
  bernsteinPoly() : coeff(0.0), n(0), i(0) {}

  /** Construct the function. */
  bernsteinPoly( uintc n_, uintc i_);

  /** Evaluate the function at t. */
  void eval(double & res, doublec t) const;
  /** Evaluate the function at t. */
  doublec eval(doublec t) const
    { double res; eval(res,t); return res; }
};

/*!
\brief A product of two Bernstein polynomials.

Defined as B(n0,i0)*B(n1,i1) where B is the Bernstein polynomial.
*/
class bernsteinPolyProd
{
public:

  bernsteinPoly b0;
  bernsteinPoly b1;

  /** Realizes the function with the current values. */
  void construct();

  /** Construct the function. */
  bernsteinPolyProd
  ( 
    uintc n0_, 
    uintc i0_,
    uintc n1_, 
    uintc i1_
  );

  /** Evaluate the function at (u,v). */
  void eval(double & res, doublec u, doublec v) const;
  /** Evaluate the function at (u,v). */
  doublec eval(doublec u, doublec v) const
    { double res; eval(res,u,v); return res; }

};

/*
p.498
template
class bernsteinPatch
{
public:

  uintc m;
  uintc n;

  bernsteinPatch(uintc m_, uintc n_)


};
*/




#endif



