import * as THREE from 'three' ; import { mat4InvertCompat } from './mat4InvertCompat' ; export class Matrix4InverseCache { /**
     * The target matrix.
     */ public readonly matrix : THREE . Matrix4 ; /**
     * A cache of inverse of current matrix.
     */ private readonly _inverseCache = new THREE . Matrix4 ( ) ; /**
     * A flag that makes it want to recalculate its  _inverseCache .
     * Will be set `true` when `elements` are mutated and be used in `getInverse`.
      private _shouldUpdateInverse = true ; /**
     * The original of `matrix.elements`
     */ private readonly _originalElements : number [ ] ; /**
     * Inverse of given matrix.
     * Note that it will return its internal private instance.
     * Make sure copying this before mutate this.
     */ public get inverse ( ) : THREE . Matrix4 { if ( this . _shouldUpdateInverse ) { mat4InvertCompat ( this . _inverseCache . copy ( this . matrix ) ) ; this . _shouldUpdateInverse = false ; } return this . _inverseCache ; } public constructor ( matrix ) { this . matrix = matrix ; const handler = { set : ( obj , prop , newVal ) => { this . _shouldUpdateInverse = true ; obj [ prop ] = newVal ; return true ; } , } ; this . _originalElements = matrix . elements ; matrix . elements = new Proxy ( matrix . elements , handler ) ; } public revert ( ) { this . matrix . elements = this . _originalElements ; } }