On Fri, Jun 6, 2014 at 1:52 PM, Kip Gilbert <kgilb...@mozilla.com> wrote:
> > On 2014-06-06, 1:23 PM, Rik Cabanier wrote: > > >> >> >> On Fri, Jun 6, 2014 at 12:18 PM, Kip Gilbert <kgilb...@mozilla.com >> <mailto:kgilb...@mozilla.com>> wrote: >> >> Hello, >> >> From a game programmer's perspective, isIdentity would normally be >> used to cull out work. In these cases, it is expected that >> isIdentity will return true only when the matrix is exactly equal >> to the identity matrix. Due to the nature of floating point, the >> isIdentity will only likely be true when it has been initialized >> or assigned identity directly. This is what occurs in existing >> game / math libraries. >> >> >> Yes, this is why storing it as an internal flag is the correct solution. >> > Perhaps you wish to use an internal flag as an optimization? This is > usually not necessary as the comparison function will usually early-out > after the first row of comparisons. If the matrix class is implemented > with SIMD instructions, the comparison becomes even cheaper. There is > nothing inherently wrong with mirroring the equality with a separate flag; > however, this is potentially unneeded complexity. Since a DOMMatrix can be 2x3 or 4x4, it will store a pointer to either type: gfx::Matrix* mMatrix2D; gfx::Matrix4x4* mMatrix3D; The check then becomes: bool DOMMatrixReadOnly::maybeHasTransform() const { return (mMatrix2D != nullptr) || (mMatrix3D != nullptr); } If we allow some amount of tolerance in the comparison, the issue >> is of how much tolerance is right for a particular application. >> One application may benefit from having small amount of variance >> as it may be rotating items around a pivot that is close to their >> origins with units that are screen space coordinates; however, >> another application may use a pivot / origin that has a real-world >> relation to the objects represented in a scene. The same amount >> of variance that would allow an unnoticeable sub-pixel difference >> in the first case would result in an object not appearing at all >> in the second case. IMHO, acceptable level of tolerance is >> something that the platform should never dictate and that users of >> the library would never expect. It is considered safe to error on >> the side of returning false but never safe to return true when the >> value is not exactly identity. >> >> Another use case is physics calculation. The vast majority of >> simulated objects will be at their resting position until they are >> hit by a collider in which case their transform becomes >> non-identity. The moving objects live for a short time until they >> "respawn" in which case their transform is set back to the origin >> with the assignment of an identity matrix. Expensive calculations >> such as IK (Inverse Kinematics) chains are executed only on the >> objects that are not at rest and thus are transformed by a matrix >> that is not identity. >> >> tl;dr.. I would only see real-world benefit in a simple >> IsIdentity function which returns true only when the matrix is >> exactly identity. >> >> >> I agree. At this point, it's clear that isIdentity() is too confusing and >> doesn't do what its name implies. >> Let's go with roc's proposal and replace the API with 'maybeHasTransform'. >> >> I don't believe isIdentity to be confusing. For example, the Unity3D > Matrix4x4 class also has an "isIdentity" function: > > http://docs.unity3d.com/ScriptReference/Matrix4x4-isIdentity.html > > Given the estimated 2 million developers using Unity, there seems to be a > lack of issues raised about the "isIdentity" function. The issue is not that "isIdentity()" is confusing. The problem is that you shouldn't make decisions based on it. From earlier in the thread: The isIdentity() method has the same issue as was described about is2D() above: as matrices get computed, they are going to jump unpredicably between being exactly identity and not. People using isIdentity() to jump between code paths are going to get unexpected jumps between code paths i.e. typically performance cliffs, or worse if they start asserting that a matrix should or should not be exactly identity. For that reason, I would remove the isIdentity method. _______________________________________________ dev-platform mailing list dev-platform@lists.mozilla.org https://lists.mozilla.org/listinfo/dev-platform