<commit_before>/*=========================================================================

  Program:   itkUNC
  Module:    $RCSfile: itkSpline1D.cxx,v $
  Language:  C++
  Date:      $Date: 2003/01/13 19:59:26 $
  Version:   $Revision: 1.3 $

  Copyright (c) 2002 CADDLab @ UNC. All rights reserved.
  See itkUNCCopyright.txt for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "itkSpline1D.h"
#include <cmath>


namespace itk 
{

class Spline1DValFunc : public UserFunc<double, double> 
{
  Spline1D * spline;
  double cVal;
public:
  Spline1DValFunc(Spline1D * newSpline)
    {
    spline = newSpline;
    cVal = 0;
    };
  const double & value(const double & x)
    {
    cVal = spline->value(x);
    return cVal;
    };
};

class Spline1DDerivFunc : public UserFunc<double, double> 
{
  Spline1D * spline;
  double cDeriv;
public:
  Spline1DDerivFunc(Spline1D * newSpline)
    {
    spline = newSpline;
    cDeriv = 0;
    };
  const double & value(const double & x)
    {
    cDeriv = spline->valueD(x);
    return cDeriv;
    }
};

//
//
//
Spline1D::
Spline1D()
{
  cDefined = false;

  cClip = true;

  cXMin = 0;
  cXMax = 1;

  cOpt1DVal = new Spline1DValFunc(this);
  cOpt1DDeriv = new Spline1DDerivFunc(this);

  use(NULL, NULL);
}

Spline1D::
Spline1D(UserFunc<int, double> *newFuncVal, Optimizer1D *newOpt1D)
{
  cDefined = false;

  cClip = true;

  cXMin = 0;
  cXMax = 1;

  cData.set_size(4);

  cOpt1DVal = new Spline1DValFunc(this);
  cOpt1DDeriv = new Spline1DDerivFunc(this);

  use(newFuncVal, newOpt1D);
}

Spline1D::
~Spline1D()
{
  if(cDefined) 
  {
    cDefined = false;

    delete cOpt1DVal;
    delete cOpt1DDeriv;
  }
}

//
//
//
void Spline1D::
use(UserFunc<int, double> *newFuncVal, Optimizer1D *newOpt1D)
{
    cDefined = true;

    cFuncVal = newFuncVal;

    cOpt1D = newOpt1D;
    if(cOpt1D != NULL)
        cOpt1D->use(cOpt1DVal, cOpt1DDeriv);

    cNewData = true;
}

//
//
//
bool Spline1D::
clipEdge(void)
{
    return cClip;
}

void Spline1D::
clipEdge(bool newClip)
{
    cClip = newClip;
}

int Spline1D::
xMin(void)
{
    return cXMin;
}

void Spline1D::
xMin(int newXMin)
{
    cXMin = newXMin;
}

int Spline1D::
xMax(void)
{
    return cXMax;
}

void Spline1D::
xMax(int newXMax)
{
    cXMax = newXMax;
}

//
//
//
bool Spline1D::
newData(void)
{<commit_msg>ENH: Setting the spline's limits sets the optimizer's limits.<commit_after>/*=========================================================================

  Program:   itkUNC
  Module:    $RCSfile: itkSpline1D.cxx,v $
  Language:  C++
  Date:      $Date: 2003/01/13 19:59:26 $
  Version:   $Revision: 1.3 $

  Copyright (c) 2002 CADDLab @ UNC. All rights reserved.
  See itkUNCCopyright.txt for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "itkSpline1D.h"
#include <cmath>


namespace itk 
{

class Spline1DValFunc : public UserFunc<double, double> 
{
  Spline1D * spline;
  double cVal;
public:
  Spline1DValFunc(Spline1D * newSpline)
    {
    spline = newSpline;
    cVal = 0;
    };
  const double & value(const double & x)
    {
    cVal = spline->value(x);
    std::cout << "Spline x = " << x << " : val = " << cVal << std::endl;
    return cVal;
    };
};

class Spline1DDerivFunc : public UserFunc<double, double> 
{
  Spline1D * spline;
  double cDeriv;
public:
  Spline1DDerivFunc(Spline1D * newSpline)
    {
    spline = newSpline;
    cDeriv = 0;
    };
  const double & value(const double & x)
    {
    cDeriv = spline->valueD(x);
    std::cout << "Spline x = " << x << " : dx = " << cDeriv << std::endl;
    return cDeriv;
    }
};

//
//
//
Spline1D::
Spline1D()
{
  cDefined = false;

  cClip = true;

  cXMin = 0;
  cXMax = 1;

  cOpt1DVal = new Spline1DValFunc(this);
  cOpt1DDeriv = new Spline1DDerivFunc(this);

  use(NULL, NULL);
}

Spline1D::
Spline1D(UserFunc<int, double> *newFuncVal, Optimizer1D *newOpt1D)
{
  cDefined = false;

  cClip = true;

  cXMin = 0;
  cXMax = 1;

  cData.set_size(4);

  cOpt1DVal = new Spline1DValFunc(this);
  cOpt1DDeriv = new Spline1DDerivFunc(this);

  use(newFuncVal, newOpt1D);
}

Spline1D::
~Spline1D()
{
  if(cDefined) 
  {
    cDefined = false;

    delete cOpt1DVal;
    delete cOpt1DDeriv;
  }
}

//
//
//
void Spline1D::
use(UserFunc<int, double> *newFuncVal, Optimizer1D *newOpt1D)
{
    cDefined = true;

    cFuncVal = newFuncVal;

    cOpt1D = newOpt1D;
    if(cOpt1D != NULL)
      {
      cOpt1D->use(cOpt1DVal, cOpt1DDeriv);
      }

    cNewData = true;
}

//
//
//
bool Spline1D::
clipEdge(void)
{
    return cClip;
}

void Spline1D::
clipEdge(bool newClip)
{
    cClip = newClip;
}

int Spline1D::
xMin(void)
{
    return cXMin;
}

void Spline1D::
xMin(int newXMin)
{
    cXMin = newXMin;
    if(cOpt1D)
      {
      cOpt1D->xMin( cXMin );
      }
}

int Spline1D::
xMax(void)
{
    return cXMax;
}

void Spline1D::
xMax(int newXMax)
{
    cXMax = newXMax;
    if(cOpt1D)
      {
      cOpt1D->xMax( cXMax );
      }
}

//
//
//
bool Spline1D::
newData(void)
{
{'fraction_non_alphanumeric': 0.17486738613499178, 'fraction_numerical': 0.027071520029266508, 'mean_word_length': 3.086696562032885, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5986933', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2181, 'n_words': 460}