#ifndef LEASTSQRS_H
#define LEASTSQRS_H

#include <point.h>

typedef point2<double> pt2;
typedef unsigned int uint;
typedef unsigned int const uintc;

/*!
  \brief Fit connected straight lines in 2D minimizing their length. 

  Minimize the y coordinate of each point.
  alpha * distance(pts[i].y-x[i])

  Minimize the straight line segment lengths.
  beta * dist(pts[i+1],pts[i])
*/
class leastsqrs
{
  /** The control points. */
  vector<pt2> const & pts;
  uint size;
public:

  /** The weight of the change in y. */
  double alpha;
  /** The weight of the line length. */
  double beta;
  /** The varying y coordinate state. */
  double * xi;

  leastsqrs
  ( 
    vector<pt2> const & pts_,
    double const alpha_=1.0,
    double const beta_=1.0
  );
  ~leastsqrs();

  void operator () 
  (
    double & fval 
  );
};



#endif



