Java interpolate interpolate(int v1, int v2, float f)

Here you can find the source of interpolate(int v1, int v2, float f)

Description

interpolate

License

Open Source License

Declaration

public static int interpolate(int v1, int v2, float f) 

Method Source Code

//package com.java2s;

public class Main {
    public static int interpolate(int v1, int v2, float f) {
        return clamp((int) (v1 + f * (v2 - v1)));
    }/* w  ww.j av a2  s  .co m*/

    /**
     * Clamp a value to an interval.
     *
     * @param value
     *    the input parameter.
     * @param lower
     *    the lower clamp threshold.
     * @param upper
     *    the upper clamp threshold.
     * @return
     *  the clamped value.
     */
    public static byte clamp(byte value, byte lower, byte upper) {
        return (value < lower ? lower : (value > upper ? upper : value));
    }

    /**
     * Clamp a value to an interval.
     *
     * @param value
     *    the input parameter.
     * @param lower
     *    the lower clamp threshold.
     * @param upper
     *    the upper clamp threshold.
     * @return
     *  the clamped value.
     */
    public static short clamp(short value, short lower, short upper) {
        return (value < lower ? lower : (value > upper ? upper : value));
    }

    /**
     * Clamp a value to an interval.
     *
     * @param value
     *    the input parameter.
     * @param lower
     *    the lower clamp threshold.
     * @param upper
     *    the upper clamp threshold.
     * @return
     *  the clamped value.
     */
    public static int clamp(int value, int lower, int upper) {
        return (value < lower ? lower : (value > upper ? upper : value));
    }

    /**
     * Clamp a value to an interval.
     *
     * @param value
     *    the input parameter.
     * @param lower
     *    the lower clamp threshold.
     * @param upper
     *    the upper clamp threshold.
     * @return
     *  the clamped value.
     */
    public static long clamp(long value, long lower, long upper) {
        return (value < lower ? lower : (value > upper ? upper : value));
    }

    /**
     * Clamp a value to an interval.
     *
     * @param value
     *    the input parameter.
     * @param lower
     *    the lower clamp threshold.
     * @param upper
     *    the upper clamp threshold.
     * @return
     *  the clamped value.
     */
    public static float clamp(float value, float lower, float upper) {
        return (value < lower ? lower : (value > upper ? upper : value));
    }

    /**
     * Clamp a value to an interval.
     *
     * @param value
     *    the input parameter.
     * @param lower
     *    the lower clamp threshold.
     * @param upper
     *    the upper clamp threshold.
     * @return
     *  the clamped value.
     */
    public static double clamp(double value, double lower, double upper) {
        return (value < lower ? lower : (value > upper ? upper : value));
    }

    /**
     * Clamp a value to the interval <code>[0, 255]</code>.
     *
     * @param value
     *    the input parameter.
     * @return
     *  the clamped value.
     */
    public static byte clamp(byte value) {
        return (value < 0 ? 0 : (value > 255 ? (byte) 255 : value));
    }

    /**
     * Clamp a value to the interval <code>[0, 255]</code>.
     *
     * @param value
     *    the input parameter.
     * @return
     *  the clamped value.
     */
    public static short clamp(short value) {
        return (value < 0 ? 0 : (value > 255 ? (short) 255 : value));
    }

    /**
     * Clamp a value to the interval <code>[0, 255]</code>.
     *
     * @param value
     *    the input parameter.
     * @return
     *  the clamped value.
     */
    public static int clamp(int value) {
        return (value < 0 ? 0 : (value > 255 ? 255 : value));
    }

    /**
     * Clamp a value to the interval <code>[0, 255]</code>.
     *
     * @param value
     *    the input parameter.
     * @return
     *  the clamped value.
     */
    public static long clamp(long value) {
        return (value < 0 ? 0 : (value > 255 ? 255 : value));
    }

    /**
     * Clamp a value to the interval <code>[0, 255]</code>.
     *
     * @param value
     *    the input parameter.
     * @return
     *  the clamped value.
     */
    public static float clamp(float value) {
        return (value < 0 ? 0 : (value > 255 ? 255 : value));
    }

    /**
     * Clamp a value to the interval <code>[0, 255]</code>.
     *
     * @param value
     *    the input parameter.
     * @return
     *  the clamped value.
     */
    public static double clamp(double value) {
        return (value < 0 ? 0 : (value > 255 ? 255 : value));
    }
}

Related

  1. interpolate(float var1, float var2, float var3)
  2. interpolate(int a, int b, int theta, int reciprocal)
  3. interpolate(int i, int n, float u1, float u2, float du)
  4. interpolate(int start, int end, int n, int i)
  5. interpolate(int v1, int v2, float f)
  6. interpolate(Long t, Long t1, Double m1, Long t2, Double m2)
  7. interpolate(long x1, long x2, double y1, double y2, long x)
  8. interpolate(String input, String parameter, String value)
  9. interpolate(String value)