File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments