Skip to content

Commit 2c4e2c9

Browse files
authored
fix: tolerate rounding at adjacent keyframe boundaries (#205)
1 parent 75be088 commit 2c4e2c9

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎src/core/animations/keyframe-builder.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class KeyframeBuilder {
161161

162162
if (!next) break;
163163

164-
if (current.start + current.length > next.start) {
164+
if (current.start + current.length - next.start > TIME_EPSILON) {
165165
throw new Error("Overlapping keyframes detected.");
166166
}
167167
}

‎tests/keyframe-builder.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ describe("KeyframeBuilder", () => {
137137
});
138138

139139
describe("timeline boundary safety", () => {
140+
it("plays adjacent decimal segments whose normalised end still rounds past the next start", () => {
141+
const builder = new KeyframeBuilder(
142+
[
143+
{ start: 0, length: 0.7, from: 0, to: 1 },
144+
{ start: 0.7, length: 3.2, from: 1, to: 1 },
145+
{ start: 3.9, length: 0.35, from: 1, to: 0 }
146+
],
147+
4.25
148+
);
149+
150+
expect(builder.getValue(0.35)).toBeCloseTo(0.5);
151+
expect(builder.getValue(2)).toBe(1);
152+
expect(builder.getValue(4.075)).toBeCloseTo(0.5);
153+
expect(builder.getValue(4.25)).toBe(0);
154+
});
155+
140156
it("preserves and evaluates a keyframe that extends beyond a shortened clip", () => {
141157
const builder = new KeyframeBuilder([{ start: 0, length: 10, from: 0, to: 1, interpolation: "linear" }], 5);
142158

0 commit comments

Comments
 (0)