@@ -164,7 +164,8 @@ export const scale: (state: CameraState) => (time: number) => Vector2 = createSe
164164 scalingConstants . maximum
165165 ) ;
166166
167- return ( time ) => {
167+ // memoizing this so the vector returned will be the same object reference if called with the same `time`.
168+ return defaultMemoize ( ( time ) => {
168169 /**
169170 * If the animation has completed, return the `scaleNotCountingAnimation`, as
170171 * the animation always completes with the scale set back at starting value.
@@ -247,12 +248,13 @@ export const scale: (state: CameraState) => (time: number) => Vector2 = createSe
247248 */
248249 return [ lerpedScale , lerpedScale ] ;
249250 }
250- } ;
251+ } ) ;
251252 } else {
252253 /**
253254 * The scale should be the same in both axes.
255+ * Memoizing this so the vector returned will be the same object reference every time.
254256 */
255- return ( ) => [ scaleNotCountingAnimation , scaleNotCountingAnimation ] ;
257+ return defaultMemoize ( ( ) => [ scaleNotCountingAnimation , scaleNotCountingAnimation ] ) ;
256258 }
257259
258260 /**
@@ -277,22 +279,26 @@ export const clippingPlanes: (
277279) => ( time : number ) => ClippingPlanes = createSelector (
278280 ( state ) => state . rasterSize ,
279281 scale ,
280- ( rasterSize , scaleAtTime ) => ( time : number ) => {
281- const [ scaleX , scaleY ] = scaleAtTime ( time ) ;
282- const renderWidth = rasterSize [ 0 ] ;
283- const renderHeight = rasterSize [ 1 ] ;
284- const clippingPlaneRight = renderWidth / 2 / scaleX ;
285- const clippingPlaneTop = renderHeight / 2 / scaleY ;
286-
287- return {
288- renderWidth,
289- renderHeight,
290- clippingPlaneRight,
291- clippingPlaneTop,
292- clippingPlaneLeft : - clippingPlaneRight ,
293- clippingPlaneBottom : - clippingPlaneTop ,
294- } ;
295- }
282+ ( rasterSize , scaleAtTime ) =>
283+ /**
284+ * memoizing this for object reference equality.
285+ */
286+ defaultMemoize ( ( time : number ) => {
287+ const [ scaleX , scaleY ] = scaleAtTime ( time ) ;
288+ const renderWidth = rasterSize [ 0 ] ;
289+ const renderHeight = rasterSize [ 1 ] ;
290+ const clippingPlaneRight = renderWidth / 2 / scaleX ;
291+ const clippingPlaneTop = renderHeight / 2 / scaleY ;
292+
293+ return {
294+ renderWidth,
295+ renderHeight,
296+ clippingPlaneRight,
297+ clippingPlaneTop,
298+ clippingPlaneLeft : - clippingPlaneRight ,
299+ clippingPlaneBottom : - clippingPlaneTop ,
300+ } ;
301+ } )
296302) ;
297303
298304/**
@@ -323,7 +329,10 @@ export const translation: (state: CameraState) => (time: number) => Vector2 = cr
323329 scale ,
324330 ( state ) => state . animation ,
325331 ( panning , translationNotCountingCurrentPanning , scaleAtTime , animation ) => {
326- return ( time : number ) => {
332+ /**
333+ * Memoizing this for object reference equality.
334+ */
335+ return defaultMemoize ( ( time : number ) => {
327336 const [ scaleX , scaleY ] = scaleAtTime ( time ) ;
328337 if ( animation !== undefined && animationIsActive ( animation , time ) ) {
329338 return vector2 . lerp (
@@ -343,7 +352,7 @@ export const translation: (state: CameraState) => (time: number) => Vector2 = cr
343352 } else {
344353 return translationNotCountingCurrentPanning ;
345354 }
346- } ;
355+ } ) ;
347356 }
348357) ;
349358
@@ -357,7 +366,10 @@ export const inverseProjectionMatrix: (
357366 clippingPlanes ,
358367 translation ,
359368 ( clippingPlanesAtTime , translationAtTime ) => {
360- return ( time : number ) => {
369+ /**
370+ * Memoizing this for object reference equality (and reduced memory churn.)
371+ */
372+ return defaultMemoize ( ( time : number ) => {
361373 const {
362374 renderWidth,
363375 renderHeight,
@@ -404,7 +416,7 @@ export const inverseProjectionMatrix: (
404416 translateForCamera ,
405417 multiply ( scaleToClippingPlaneDimensions , multiply ( invertY , screenToNDC ) )
406418 ) ;
407- } ;
419+ } ) ;
408420 }
409421) ;
410422
@@ -415,7 +427,8 @@ export const viewableBoundingBox: (state: CameraState) => (time: number) => AABB
415427 clippingPlanes ,
416428 inverseProjectionMatrix ,
417429 ( clippingPlanesAtTime , matrixAtTime ) => {
418- return ( time : number ) => {
430+ // memoizing this so the AABB returned will be the same object reference if called with the same `time`.
431+ return defaultMemoize ( ( time : number ) => {
419432 const { renderWidth, renderHeight } = clippingPlanesAtTime ( time ) ;
420433 const matrix = matrixAtTime ( time ) ;
421434 const bottomLeftCorner : Vector2 = [ 0 , renderHeight ] ;
@@ -424,7 +437,7 @@ export const viewableBoundingBox: (state: CameraState) => (time: number) => AABB
424437 minimum : vector2 . applyMatrix3 ( bottomLeftCorner , matrix ) ,
425438 maximum : vector2 . applyMatrix3 ( topRightCorner , matrix ) ,
426439 } ;
427- } ;
440+ } ) ;
428441 }
429442) ;
430443
@@ -436,6 +449,8 @@ export const projectionMatrix: (state: CameraState) => (time: number) => Matrix3
436449 clippingPlanes ,
437450 translation ,
438451 ( clippingPlanesAtTime , translationAtTime ) => {
452+ // memoizing this so the matrix returned will be the same object reference if called with the same `time`.
453+ // this should also save on some memory allocation
439454 return defaultMemoize ( ( time : number ) => {
440455 const {
441456 renderWidth,
0 commit comments