// 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>.
//
// Reference:
// "The Nurbs Book" Les Piegl, Wayne Tiller,
// ISBN 3-540-61545-8 2nd ed. Springer-Verlarg Berlin heidelberg New York.
// pp. 241-263

#include <iostream>
#include <fstream>

#include "nbspline.h"
#include "reparametrization.h"
#include "ndisplay.h"
#include "nutil.h"
#include "gnurbscallbacks.h"

void init_bsplines(nbspline &curve, nbspline &param)
{
  // Nurbs Book, example of page 246.
  for(int i = 0; i < 3; ++i)
  {
    curve.u(i) = param.u(i) = 0.0;
    curve.u(i+3) = param.u(i+3) = 1.0;
  }

  curve.CP(0) = npoint(0.0, 0.0, 0.0, 1.0);
  curve.CP(1) = npoint(0.5, 1.0, 0.0, 1.0);
  curve.CP(2) = npoint(1.0, 0.0, 0.0, 2.0);

  param.CP(0) = npoint(0.0, 0.0, 0.0, 1.0);
  param.CP(1) = npoint(7.0/24.0, 0.0, 0.0, 1.0);
  param.CP(2) = npoint(1.0, 0.0, 0.0, 1.0);
}

int main()
{
  data_container data;
  ndisplay display;

  int nCP = 3;
  nbspline curve(nCP, 2), param(nCP, 2);
  init_bsplines(curve, param);

  Reparametrization reparam(curve, param);
  reparam.apply();
  param = reparam.get();

  gnurbscallbacks CB;
  CB.add_entity(&curve);
  CB.add_entity(&param);

  display.setcallbacks(&CB);
  CB.draw();
  display.init_data(CB.datas);
  display.display();

  return 0;
}
