You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This makes it tricky to use a single DOMMatrix instance as an optimized cached value when avoiding mutation (instead of always creating new instances for calculations). For example, when we set the matrix back to identity, is2D should go back to true, that way any optimizations that rely on if (mat.is2D) can kick in again.
If we can add more methods to DOMMatrix, for example as we've begun to ideate in
one of them could be mat.toIdentity() or mat.reset() which can set the internal is2D value to back to true as well as restore the matrix back to an identity matrix.
The hand-rolled toIdentity function in my example cannot set the private is2D state back to true from the outside.
Besides adding DOMMatrix.toIdentity or DOMMatrix.reset, another possibility is to expand the set steps for m11 to m44 such that if they receive 0 or 1, they should check if isIdentity is true, and if so set is2D back to true. However this might be more expensive than relying on new isIdentity/reset method which will unconditionally set is2D back to true without checking all values many times. With the setter idea, it could be checking all values up to 16 times (16 times 16) when setting all 16 values back to default state.
The text was updated successfully, but these errors were encountered:
trusktr
changed the title
[geometry-1] There is no way to reset DOMMatrixis2D back to true when returning to identity.
[geometry-1] propose new DOMMatrix.reset method (no way to reset DOMMatrixis2D back to true when returning to identity)
Dec 28, 2024
There is currently no way to reset a matrix back to initial state.
For example, run this in any browser console:
The last assertion fails:
This makes it tricky to use a single
DOMMatrix
instance as an optimized cached value when avoiding mutation (instead of always creating new instances for calculations). For example, when we set the matrix back to identity,is2D
should go back totrue
, that way any optimizations that rely onif (mat.is2D)
can kick in again.If we can add more methods to
DOMMatrix
, for example as we've begun to ideate inone of them could be
mat.toIdentity()
ormat.reset()
which can set the internalis2D
value to back totrue
as well as restore the matrix back to an identity matrix.The hand-rolled
toIdentity
function in my example cannot set the privateis2D
state back totrue
from the outside.Besides adding
DOMMatrix.toIdentity
orDOMMatrix.reset
, another possibility is to expand theset
steps form11
tom44
such that if they receive0
or1
, they should check ifisIdentity
istrue
, and if so setis2D
back totrue
. However this might be more expensive than relying on newisIdentity
/reset
method which will unconditionally setis2D
back totrue
without checking all values many times. With the setter idea, it could be checking all values up to 16 times (16 times 16) when setting all 16 values back to default state.The text was updated successfully, but these errors were encountered: