Files
cocos4/cocos/core/data/utils/binary-search.ts
T
Leslie Leigh 5936b42393 animation (#4153)
* animation

* animation

* update
2019-04-04 19:09:09 +08:00

20 lines
435 B
TypeScript

const EPSILON = 1e-6;
export function binarySearchEpsilon (array: number[], value: number) {
let l = 0;
for (let h = array.length - 1, m = h >>> 1; l <= h; m = (l + h) >>> 1) {
const test = array[m];
if (test > value + EPSILON) {
h = m - 1;
}
else if (test < value - EPSILON) {
l = m + 1;
}
else {
return m;
}
}
return ~l;
}