mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
69f864cbf4
* uniform-k * update * update * typo * opt AnimCurve constructor * refactor animation-clip * rename * adapt animation clip new data structure to skeletal animation clip * opt error * opt error msg * uniform test current file configuration * opt err msg * opt * fix * adapt skeletal clip * fix * fix * fix
20 lines
513 B
TypeScript
20 lines
513 B
TypeScript
|
|
const EPSILON = 1e-6;
|
|
|
|
export function binarySearchEpsilon (array: number[], value: number) {
|
|
let low = 0;
|
|
let high = array.length - 1;
|
|
let middle = high >>> 1;
|
|
for (; low <= high; middle = (low + high) >>> 1) {
|
|
const middleValue = array[middle];
|
|
if (middleValue > (value + EPSILON)) {
|
|
high = middle - 1;
|
|
} else if (middleValue < (value - EPSILON)) {
|
|
low = middle + 1;
|
|
} else {
|
|
return middle;
|
|
}
|
|
}
|
|
return ~low;
|
|
}
|