Skip to content

Commit ed0b081

Browse files
committed
Keyframe::IsIncreasing(): Search over points, not values
Searching over the keyframe points is considerably faster than calculating interpolating values and searching over them.
1 parent b40fa69 commit ed0b081

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/KeyFrame.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,23 @@ bool Keyframe::IsIncreasing(int index) const
282282
if (index < 1 || (index + 1) >= GetLength()) {
283283
return true;
284284
}
285-
int64_t const current = GetLong(index);
286-
// TODO: skip over constant sections.
285+
std::vector<Point>::const_iterator candidate =
286+
std::lower_bound(begin(Points), end(Points), static_cast<double>(index), IsPointBeforeX);
287+
if (candidate == end(Points)) {
288+
return false; // After the last point, thus constant.
289+
}
290+
if ((candidate->co.X == index) || (candidate == begin(Points))) {
291+
++candidate;
292+
}
293+
int64_t const value = GetLong(index);
287294
do {
288-
int64_t const next = GetLong(++index);
289-
if (next > current) return true;
290-
if (next < current) return false;
291-
} while (index < GetLength());
295+
if (value < round(candidate->co.Y)) {
296+
return true;
297+
} else if (value > round(candidate->co.Y)) {
298+
return false;
299+
}
300+
++candidate;
301+
} while (candidate != end(Points));
292302
return false;
293303
}
294304

0 commit comments

Comments
 (0)