app/src/main/java/me/zhanghai/android/douya/util/MathUtils.java
(完整代码) 1KB/*
* Copyright (c) 2015 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
* All Rights Reserved.
*/
package me.zhanghai.android.douya.util;
public class MathUtils {
private MathUtils() {}
public static int clamp(int value, int min, int max) {
return value < min ? min : value > max ? max : value;
}
public static float clamp(float value, float min, float max) {
return value < min ? min : value > max ? max : value;
}
public static int lerp(int start, int end, float fraction) {
return (int) (start + (end - start) * fraction);
}
public static float lerp(float start, float end, float fraction) {
return start + (end - start) * fraction;
}
public static float unlerp(int start, int end, int value) {
int domainSize = end - start;
if (domainSize == 0) {
throw new IllegalArgumentException("Can't reverse interpolate with domain size of 0");
}
return (float) (value - start) / domainSize;
}
public static float unlerp(float start, float end, float value) {
float domainSize = end - start;
if (domainSize == 0) {
throw new IllegalArgumentException("Can't reverse interpolate with domain size of 0");
}
return (value - start) / domainSize;
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
