Thank you Gilles for your detailed response!
Gilles wrote:
> [...]
> How about "SplineInterpolator" provide a factory method to select one or the
> other implementation?
> I.e. something like
> ---CUT---
> public SplineInterpolator implements UnivariateInterpolator {
> /** Interpolation algorithm variant. */
> private final BiFunction<double[], double[], UnivariateFunction> algo;
>
> /**
> * Factory method.
> * @param clamped ...
> * @return a new interpolator instance.
> */
> public static SplineInterpolator create(boolean clamped) {
> if (clamped) {
> algo = new Clamped();
> } else {
> algo = new Unclamped();
> }
> }
>
> @Override
> public PolynomialSplineFunction interpolate(double[] x, double[] y) {
> return algo.apply(x, y);
> }
>
> private static class Unclamped
> implements BiFunction<double[], double[], PolynomialSplineFunction> {
> // ... current implementation ...
> }
>
> private static class Clamped
> implements BiFunction<double[], double[], PolynomialSplineFunction> {
> // ... your proposed functionality ...
> }
>
> // Commons functions ...
> }
> ---CUT---
I like your idea of a factory method for "SplineInterpolator" but am not sure
whether it will provide any benefit. The newly proposed "clamped" spline
requires two additional boundary conditions specifying the slopes at each
interpolation run and thus, simply overloading of the interpolate(...) function
of interface UnivariateInterpolator to accept two additional parameters seems
to be an attractive approach. Something like this:
---CUT---8<---
public class SplineInterpolator implements UnivariateInterpolator {
@Override
public PolynomialSplineFunction interpolate(double[] x, double[] y) {
// ... current default implementation of unclamped spline ...
}
public PolynomialSplineFunction interpolate(double[] x, double[] y, double
startSlope, double endSlope) {
// ... newly proposed clamped spline variant ...
}
// Commons functions ...
}
--->8---CUT---
Is this still complying with the library design or will it break hearts? What
do you think? If we wanted to specify the additional slope parameters in your
factory method approach, these parameters would have to be passed initially
during creation of the new BiFunction object and thus would require a
re-creation of the whole object for each new interpolation run with just
varying slope parameters. I'm not sure if this "overhead" is desired :D
Thanks in advance!
Michi
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]