// Gnurbs - A curve and surface library
// Copyright (C) 2008-2026 Eric Bechet
//
// See the LICENSE file for contributions and license information.
// Please report all bugs and problems to <bechet@cadxfem.org>.
//

#ifndef __NLAGRANGE_H
#define __NLAGRANGE_H


#include "ncurve.h"
#include <vector>

class nlagrange : public nparametriccurve
{
protected:
  std::vector<double> pos; // values of u
  std::vector<npoint> val; // interpolations position for each value u
  int nCP; // number of iterpolations positions
public:
  nlagrange(int nCP_) : pos(nCP_),val(nCP_),nCP(nCP_) {}
  virtual int degree(void) const
  {
    return nCP-1 ;
  }
  virtual int nb_CP(void) const
  {
    return nCP ;
  }
  virtual void add_CP(double u_,const npoint &val_)
  {
    pos.push_back(u_);     // to be done in increasing u values...
    val.push_back(val_);
    nCP++;
  }
  virtual double min_u(void) const
  {
    if (nCP) return pos[0];
    else return 0;
  }
  virtual double max_u(void) const
  {
    if (nCP) return pos[nCP-1];
    else return 0;
  }
  double Basis(int which,double u) const;    // basis functions
  virtual void P(double u_,npoint& ret) const ;    // position of a point
  virtual npoint CP(int which) const
  {
    return val[which];  // returns a control point (interpolated point) - const
  }
  virtual npoint& CP(int which)
  {
    return val[which];  // returns a control point (interpolated point)
  }
  virtual void set_CP(int which,const npoint& pt)
  {
    val[which]=pt;  // changes a control point
  }
  void translate(npoint vec); // translates the curve by vector vec
  virtual double u(int which) const
  {
    return pos[which];  // returns u for a given position - const
  }
  virtual double& u(int which)
  {
    return pos[which];  // returns u for a given position
  }
  virtual nlagrange* clone() const // returns a clone (allocated on the heap)
  {
    return new nlagrange(*this);
  }
};

#endif // __NLAGRANGE_H

