mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 952011 - Add gfx3DMatrix API for untransformed rects and points. r=bjacob
This commit is contained in:
parent
5ead3a7c0c
commit
7e18435a4d
@ -788,10 +788,9 @@ gfxRect gfx3DMatrix::ProjectRectBounds(const gfxRect& aRect) const
|
|||||||
gfxPoint points[4];
|
gfxPoint points[4];
|
||||||
|
|
||||||
points[0] = ProjectPoint(aRect.TopLeft());
|
points[0] = ProjectPoint(aRect.TopLeft());
|
||||||
points[1] = ProjectPoint(gfxPoint(aRect.X() + aRect.Width(), aRect.Y()));
|
points[1] = ProjectPoint(aRect.TopRight());
|
||||||
points[2] = ProjectPoint(gfxPoint(aRect.X(), aRect.Y() + aRect.Height()));
|
points[2] = ProjectPoint(aRect.BottomLeft());
|
||||||
points[3] = ProjectPoint(gfxPoint(aRect.X() + aRect.Width(),
|
points[3] = ProjectPoint(aRect.BottomRight());
|
||||||
aRect.Y() + aRect.Height()));
|
|
||||||
|
|
||||||
gfxFloat min_x, max_x;
|
gfxFloat min_x, max_x;
|
||||||
gfxFloat min_y, max_y;
|
gfxFloat min_y, max_y;
|
||||||
@ -809,6 +808,34 @@ gfxRect gfx3DMatrix::ProjectRectBounds(const gfxRect& aRect) const
|
|||||||
return gfxRect(min_x, min_y, max_x - min_x, max_y - min_y);
|
return gfxRect(min_x, min_y, max_x - min_x, max_y - min_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gfxRect gfx3DMatrix::UntransformBounds(const gfxRect& aRect, const gfxRect& aChildBounds) const
|
||||||
|
{
|
||||||
|
if (Is2D()) {
|
||||||
|
return Inverse().TransformBounds(aRect);
|
||||||
|
}
|
||||||
|
gfxRect bounds = TransformBounds(aChildBounds);
|
||||||
|
|
||||||
|
gfxRect rect = aRect.Intersect(bounds);
|
||||||
|
|
||||||
|
return Inverse().ProjectRectBounds(rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gfx3DMatrix::UntransformPoint(const gfxPoint& aPoint, const gfxRect& aChildBounds, gfxPoint* aOut) const
|
||||||
|
{
|
||||||
|
if (Is2D()) {
|
||||||
|
*aOut = Inverse().Transform(aPoint);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
gfxRect bounds = TransformBounds(aChildBounds);
|
||||||
|
|
||||||
|
if (!bounds.Contains(aPoint)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aOut = Inverse().ProjectPoint(aPoint);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
gfxPoint3D gfx3DMatrix::GetNormalVector() const
|
gfxPoint3D gfx3DMatrix::GetNormalVector() const
|
||||||
{
|
{
|
||||||
// Define a plane in transformed space as the transformations
|
// Define a plane in transformed space as the transformations
|
||||||
|
@ -250,6 +250,25 @@ public:
|
|||||||
gfxPoint ProjectPoint(const gfxPoint& aPoint) const;
|
gfxPoint ProjectPoint(const gfxPoint& aPoint) const;
|
||||||
gfxRect ProjectRectBounds(const gfxRect& aRect) const;
|
gfxRect ProjectRectBounds(const gfxRect& aRect) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms a point by the inverse of this matrix. In the case of perspective transforms, some screen
|
||||||
|
* points have no equivalent in the untransformed plane (if they exist past the vanishing point). To
|
||||||
|
* avoid this, we need to specify the bounds of the untransformed plane to restrict the search area.
|
||||||
|
*
|
||||||
|
* @param aPoint Point to untransform.
|
||||||
|
* @param aChildBounds Bounds of the untransformed plane.
|
||||||
|
* @param aOut Untransformed point.
|
||||||
|
* @return Returns true if a point was found within a ChildBounds, false otherwise.
|
||||||
|
*/
|
||||||
|
bool UntransformPoint(const gfxPoint& aPoint, const gfxRect& aChildBounds, gfxPoint* aOut) const;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as UntransformPoint, but untransforms a rect and returns the bounding rect of the result.
|
||||||
|
* Returns an empty rect if the result doesn't intersect aChildBounds.
|
||||||
|
*/
|
||||||
|
gfxRect UntransformBounds(const gfxRect& aRect, const gfxRect& aChildBounds) const;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inverts this matrix, if possible. Otherwise, the matrix is left
|
* Inverts this matrix, if possible. Otherwise, the matrix is left
|
||||||
|
Loading…
Reference in New Issue
Block a user