Class LinearInterpolator1D

All Implemented Interfaces:
Serializable, Parameterized, LenientComparable, org.opengis.referencing.operation.MathTransform, org.opengis.referencing.operation.MathTransform1D

final class LinearInterpolator1D extends AbstractMathTransform1D implements Serializable
A transform that performs linear interpolation between values. The transform is invertible if, and only if, the values are in increasing order.

If desired values in decreasing order can be supported by inverting the sign of all values, then concatenating this transform with a transform that multiply all output values by -1.

Extrapolation

If an input value is outside the expected range of values, this class extrapolates using the slope defined by the two first points if the requested value is before, or the slope defined by the two last points if the requested value is after. In other words, extrapolations are computed using only values at the extremum where extrapolation happen. This rule causes less surprising behavior when computing a data cube envelope, which may need extrapolation by 0.5 pixel before the first value or after the last value.
Example: if a vertical dimension is made of slices at y₀=5, y₁=10, y₂=100 and y₃=250 meters, then linear interpolation at 0.5 is 7.5 meters and extrapolation at -0.5 is expected to give 2.5 meters.
Since:
0.7
Version:
1.0
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • values

      private final double[] values
      The sequence values specified at construction time. Must contain at least 2 values.
    • inverse

      private final org.opengis.referencing.operation.MathTransform1D inverse
      If the transform is invertible, the inverse. Otherwise null. The transform is invertible only if values are in increasing order.
  • Constructor Details

    • LinearInterpolator1D

      private LinearInterpolator1D(double[] values)
      Creates a new transform which will interpolate in the given table of values. The inputs are {0, 1, … , N} where N is length of output values.

      This constructor assumes that the values array has already been cloned, so it will not clone it again. That array shall contain at least two values.

      Parameters:
      values - the y values in y=f(x) where x = {0, 1, … , values.length-1}.
  • Method Details

    • create

      private static org.opengis.referencing.operation.MathTransform1D create(double[] values)
      Creates a transform for the given values. This method returns an affine transform instead of an interpolator if the given values form a series with a constant increment. The given array shall contain at least two values.
      Parameters:
      values - a copy of the user-provided values. This array may be modified.
    • create

      static org.opengis.referencing.operation.MathTransform1D create(double[] preimage, double[] values)
      Creates a y=f(x) transform for the given preimage (x) and values (y). See MathTransforms.interpolate(double[], double[]) javadoc for more information.
    • getParameterDescriptors

      public org.opengis.parameter.ParameterDescriptorGroup getParameterDescriptors()
      Returns the parameter descriptors for this math transform.
      Specified by:
      getParameterDescriptors in interface Parameterized
      Overrides:
      getParameterDescriptors in class AbstractMathTransform
      Returns:
      the parameter descriptors for this math transform, or null if unspecified.
      See Also:
    • getParameterValues

      public org.opengis.parameter.ParameterValueGroup getParameterValues()
      Returns the parameter values for this math transform.
      Specified by:
      getParameterValues in interface Parameterized
      Overrides:
      getParameterValues in class AbstractMathTransform
      Returns:
      the parameter values for this math transform, or null if unspecified. Note that those parameters may be normalized (e.g. represent a transformation of an ellipsoid of semi-major axis length of 1).
      See Also:
    • isIdentity

      public boolean isIdentity()
      Returns true if this transform is the identity transform. This method should never returns true since we verified the inputs in the create(…) method. We nevertheless verify as a paranoiac safety.
      Specified by:
      isIdentity in interface org.opengis.referencing.operation.MathTransform
      Overrides:
      isIdentity in class AbstractMathTransform
    • transform

      public org.opengis.referencing.operation.Matrix transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, boolean derivate) throws org.opengis.referencing.operation.TransformException
      Combines transform(double), derivative(double) in a single method call.
      Overrides:
      transform in class AbstractMathTransform1D
      Parameters:
      srcPts - the array containing the source coordinates (cannot be null).
      srcOff - the offset to the point to be transformed in the source array.
      dstPts - the array into which the transformed coordinates is returned. May be the same than srcPts. May be null if only the derivative matrix is desired.
      dstOff - the offset to the location of the transformed point that is stored in the destination array.
      derivate - true for computing the derivative, or false if not needed.
      Returns:
      the matrix of the transform derivative at the given source position, or null if the derivate argument is false.
      Throws:
      org.opengis.referencing.operation.TransformException - if the point cannot be transformed or if a problem occurred while calculating the derivative.
      See Also:
    • transform

      public double transform(double x)
      Interpolates a y values for the given x. The given x value should be between 0 to values.length - 1 inclusive. If the given input value is outside that range, then the output value will be extrapolated.
      Specified by:
      transform in interface org.opengis.referencing.operation.MathTransform1D
      Specified by:
      transform in class AbstractMathTransform1D
      Parameters:
      x - the value to transform.
      Returns:
      the transformed value.
    • derivative

      public double derivative(double x)
      Returns the derivative of y for the given x. Note: for each segment, the derivative is considered constant between x inclusive and x+1 exclusive.
      Specified by:
      derivative in interface org.opengis.referencing.operation.MathTransform1D
      Specified by:
      derivative in class AbstractMathTransform1D
      Parameters:
      x - the value where to evaluate the derivative.
      Returns:
      the derivative at the specified point.
    • inverse

      public org.opengis.referencing.operation.MathTransform1D inverse() throws org.opengis.referencing.operation.NoninvertibleTransformException
      Returns the inverse of this transform, or throw an exception if there is no inverse.
      Specified by:
      inverse in interface org.opengis.referencing.operation.MathTransform
      Specified by:
      inverse in interface org.opengis.referencing.operation.MathTransform1D
      Overrides:
      inverse in class AbstractMathTransform1D
      Throws:
      org.opengis.referencing.operation.NoninvertibleTransformException
    • computeHashCode

      protected int computeHashCode()
      Computes a hash code value for this transform.
      Overrides:
      computeHashCode in class AbstractMathTransform
      Returns:
      the hash code value. This value may change between different execution of the Apache SIS library.
    • equals

      public boolean equals(Object object, ComparisonMode mode)
      Compares this transform with the given object for equality.
      Specified by:
      equals in interface LenientComparable
      Overrides:
      equals in class AbstractMathTransform
      Parameters:
      object - the object to compare with this transform.
      mode - the strictness level of the comparison. Default to STRICT.
      Returns:
      true if the given object is considered equals to this math transform.
      See Also: