新增hash
This commit is contained in:
@@ -88,7 +88,7 @@ module es {
|
||||
return Math.atan2(to.y - from.y, to.x - from.x);
|
||||
}
|
||||
|
||||
public static angleToVector(angleRadians: number, length: number){
|
||||
public static angleToVector(angleRadians: number, length: number) {
|
||||
return new Vector2(Math.cos(angleRadians) * length, Math.sin(angleRadians) * length);
|
||||
}
|
||||
|
||||
@@ -97,14 +97,32 @@ module es {
|
||||
* @param t
|
||||
* @param length
|
||||
*/
|
||||
public static incrementWithWrap(t: number, length: number){
|
||||
t ++;
|
||||
public static incrementWithWrap(t: number, length: number) {
|
||||
t++;
|
||||
if (t == length)
|
||||
return 0;
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以roundToNearest为步长,将值舍入到最接近的数字。例如:在125中找到127到最近的5个结果
|
||||
* @param value
|
||||
* @param roundToNearest
|
||||
*/
|
||||
public static roundToNearest(value: number, roundToNearest: number) {
|
||||
return Math.round(value / roundToNearest) * roundToNearest;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查传递的值是否在某个阈值之下。对于小规模、精确的比较很有用
|
||||
* @param value
|
||||
* @param ep
|
||||
*/
|
||||
public static withinEpsilon(value: number, ep: number = this.Epsilon) {
|
||||
return Math.abs(value) < ep;
|
||||
}
|
||||
|
||||
/**
|
||||
* 由上移量向上移。start可以小于或大于end。例如:开始是2,结束是10,移位是4,结果是6
|
||||
* @param start
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
class WebGLUtils {
|
||||
/**
|
||||
* 获取webgl context
|
||||
*/
|
||||
public static getContext() {
|
||||
const canvas = document.getElementsByTagName('canvas')[0];
|
||||
return canvas.getContext('2d');
|
||||
}
|
||||
}
|
||||
22
source/src/Utils/Hash.ts
Normal file
22
source/src/Utils/Hash.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
module es {
|
||||
export class Hash {
|
||||
/**
|
||||
* 从一个字节数组中计算一个哈希值
|
||||
* @param data
|
||||
*/
|
||||
public static computeHash(...data: number[]) {
|
||||
const p: number = 16777619;
|
||||
let hash = 2166136261;
|
||||
|
||||
for (let i = 0; i < data.length; i++)
|
||||
hash = (hash ^ data[i]) * p;
|
||||
|
||||
hash += hash << 13;
|
||||
hash ^= hash >> 7;
|
||||
hash += hash << 3;
|
||||
hash ^= hash >> 17;
|
||||
hash += hash << 5;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user