Here you can find the source of interpolate(int v1, int v2, float f)
public static int interpolate(int v1, int v2, float f)
//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)); } }