Files
cocos4/cocos/core/data/utils/binary-search.ts
T
Leslie Leigh 69f864cbf4 uniform-k (#5034)
* 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
2019-08-08 21:38:20 -05:00

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;
}