#ifndef MESHRECT_H
#define MESHRECT_H 

#include <point.h>
#include <print.h>

typedef point3<double> pt3;

/*!
\brief  Surface as a rectangular bezier patches.

(x,y) defines the surface with height z.
*/
class meshrect
{
public:

  /** M partitions of X-axis. */
  uintc M;

  /** N partitions of Y-axis. */
  uintc N;

  /** The points in the 2D matrix. */
  pt3 * mat;

  /** i is the x-axis, j is the y-axis. */
  pt3 & pij(uintc i, uintc j)
    { return mat[i+j*N]; }
  /** i is the x-axis, j is the y-axis. */
  pt3 const & pij(uintc i, uintc j) const
    { return mat[i+j*N]; }

  /** Create a surface of points with uniform x and y values
        between and includeing [0.0,1.0]. */
  meshrect(uintc M_, uintc N_);

  /** Cleanup. */
  ~meshrect();

  /** Apply a function over the surface to calculate the z value. */
  template< typename F >
  void func( F & f )
  {
    for (uint i=0; i<M*N; ++i)
      f(mat[i].z,mat[i].x,mat[i].y);
  }

  /** Print the mesh as a 2D array. */
  void print() const;
      
};



#endif



