[Webkit-unassigned] [Bug 30442] Add helper methods to determine whether a transformation matrix is only scaled or translated

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Oct 16 15:53:17 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=30442





--- Comment #4 from Chris Marrin <cmarrin at apple.com>  2009-10-16 15:53:17 PDT ---
(From update of attachment 41327)
> diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
> +    bool isScaleOnly() const
> +    {
> +        return (m12() == 0 && m13() == 0 && m14() == 0 &&
> +                m21() == 0 && m23() == 0 && m24() == 0 &&
> +                m31() == 0 && m32() == 0 && m34() == 0 &&
> +                m41() == 0 && m42() == 0 && m43() == 0);
> +    }

If your purpose is to be able to go into optimized code paths, you probably
want to make sure m44 is 1 in isScaleOnly() since scaling the 'w' component
will certainly cause any optimizations I can think of to fail. You should
probably make sure the diagonals are not 0 for the same reason. 

> +
> +    bool isTranslationOnly() const
> +    {
> +        return (m11() == 1 && m12() == 0 && m13() == 0 && m14() == 0 &&
> +                m21() == 0 && m22() == 1 && m23() == 0 && m24() == 0 &&
> +                m31() == 0 && m32() == 0 && m33() == 1 && m34() == 0);
> +    }

Similar to above, you probably don't want to allow a value other than 1 in m44
here.

> +
> +    bool isScaleAndTranslationOnly() const
> +    {
> +        return (m12() == 0 && m13() == 0 && m14() == 0 &&
> +                m21() == 0 && m23() == 0 && m24() == 0 &&
> +                m31() == 0 && m32() == 0 && m34() == 0);
> +    }
> +

Same comments above apply here.

In general I'm a little uncomfortable with adding functions that have no
immediate purpose. If you're thinking of optimizations on rectangle tests maybe
it would be better to add some bounds checking methods that operate on a passed
in FloatRect or FloatQuad and do the optimizations there.









> +    // Check if a 2D rectangle (IntRect or FloatRect) will still be a rectangle
> +    // after the transformation, i.e. it won't be rotated or skewed.
> +    bool mapsRectToRect() const
> +    {
> +        return (m_matrix[0][1] == 0 && m_matrix[0][3] == 0 &&
> +                m_matrix[1][0] == 0 && m_matrix[1][3] == 0);
> +    }
> +

But a rotated rectangle is still a rectangle. And it's very possible that a
matrix that returned true from the above function would still not preserve
rectangularity. For instance, something other than 1 in [3][3] would fail. It
seems like you are trying to create a low-level function that serves a very
specific purpose but it's not clear what that purpose is. If what you want is
some optimized way to do bounds or intersection checking, perhaps it would be
better to add that function to TransformationMatrix rather than a function like
this.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list