Skip to content

Commit c4d0bc8

Browse files
committed
refactor: drop non-null assertions from bouncingBallToSVG script
1 parent 1b327c2 commit c4d0bc8

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

scripts/bouncingBallToSVG.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ function buildBounces(): Array<{ tStart: number; tEnd: number; h: number }> {
5050
const bounces: Array<{ tStart: number; tEnd: number; h: number }> = [];
5151
let t = 0;
5252
for (let n = 0; n < NUM_BOUNCES; n++) {
53-
const dt = durations[n]! / totalDuration;
54-
bounces.push({ tStart: t, tEnd: t + dt, h: heights[n]! });
53+
const duration = durations[n];
54+
const height = heights[n];
55+
if (duration === undefined || height === undefined) {
56+
continue;
57+
}
58+
const dt = duration / totalDuration;
59+
bounces.push({ tStart: t, tEnd: t + dt, h: height });
5560
t += dt;
5661
}
5762
return bounces;
@@ -89,8 +94,11 @@ function computeSnapshots(): Point[] {
8994
const heightAboveFloor = bounce.h * (1 - (2 * tLocal - 1) ** 2);
9095

9196
// x: linearly interpolated between the two floor contacts of this bounce
92-
const xLeft = xContacts[bounceIdx]!;
93-
const xRight = xContacts[bounceIdx + 1]!;
97+
const xLeft = xContacts[bounceIdx];
98+
const xRight = xContacts[bounceIdx + 1];
99+
if (xLeft === undefined || xRight === undefined) {
100+
continue;
101+
}
94102
const x = xLeft + tLocal * (xRight - xLeft);
95103

96104
// svg y increases downward; offset by ball radius so ball sits on floor

0 commit comments

Comments
 (0)