001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.math.interpolation;
006
007import edu.wpi.first.math.MathUtil;
008
009/**
010 * An inverse interpolation function which determines where within an interpolation range an object
011 * lies. This behavior can be linear or nonlinear.
012 *
013 * @param <T> The type that the {@link InverseInterpolator} will operate on.
014 */
015@FunctionalInterface
016public interface InverseInterpolator<T> {
017  /**
018   * Return where within interpolation range [0, 1] q is between startValue and endValue.
019   *
020   * @param startValue Lower part of interpolation range.
021   * @param endValue Upper part of interpolation range.
022   * @param q Query.
023   * @return Interpolant in range [0, 1].
024   */
025  double inverseInterpolate(T startValue, T endValue, T q);
026
027  /**
028   * Returns inverse interpolator for Double.
029   *
030   * @return Inverse interpolator for Double.
031   */
032  static InverseInterpolator<Double> forDouble() {
033    return MathUtil::inverseInterpolate;
034  }
035}