Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix key search for animation curves

The binary search used to determine the key id in an animation curve
(USBinarySearchNearest) never returned the last key for curves with
an even number of keys.

Fixed by replacing the break conditions with a stricter loop condition
and returning either the lower or the upper bound (i or j).
  • Loading branch information...
commit ed714f694cadedf0e3712893b41ff335eb2a91e1 1 parent ed22d82
@superquadratic superquadratic authored
Showing with 4 additions and 11 deletions.
  1. +4 −11 src/uslscore/USBinarySearch.h
View
15 src/uslscore/USBinarySearch.h
@@ -57,22 +57,15 @@ u32 USBinarySearchNearest ( const TYPE* buffer, const TYPE& key, u32 total ) {
if ( key < buffer [ i ]) return NO_MATCH;
if ( buffer [ j ] < key ) return NO_MATCH;
- while ( s ) {
+ while ( s > 1 ) {
u32 c = i + ( s >> 1 );
const TYPE& test = buffer [ c ];
-
if ( test < key ) {
-
- if ( i == c ) break;
-
i = c;
}
else if ( key < test ) {
-
- if ( j == c ) break;
-
j = c;
}
else {
@@ -81,11 +74,11 @@ u32 USBinarySearchNearest ( const TYPE* buffer, const TYPE& key, u32 total ) {
s = j - i;
}
- if ( key < buffer [ i ] ) {
- return i - 1;
+ if ( key < buffer [ j ] ) {
+ return i;
}
else {
- return i;
+ return j;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.