summaryrefslogtreecommitdiffstats
path: root/ui/gfx/transform.cc
diff options
context:
space:
mode:
authorvollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-11 19:10:50 +0000
committervollick@chromium.org <vollick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-11 19:10:50 +0000
commitf4d2b9010b399a4c764a5f23ba0c1493448bdd78 (patch)
tree0a5b96c1bf7181124f129accf441269430bb3b39 /ui/gfx/transform.cc
parent3bf40cb9a94a83969e1ce1a9570951e79ca0c81e (diff)
downloadchromium_src-f4d2b9010b399a4c764a5f23ba0c1493448bdd78.zip
chromium_src-f4d2b9010b399a4c764a5f23ba0c1493448bdd78.tar.gz
chromium_src-f4d2b9010b399a4c764a5f23ba0c1493448bdd78.tar.bz2
Add gfx::Transform::TransformBox and TransformBoxReverse
These new functions do what you'd expect (they transform the given box and return the tightest axis align box containing the transformed result). I've also added tests for Transform::TransformRect and TransformRectReverse and updated their comments. Seems like this class has gotten a bit stale. R=ajuma@chromium.org BUG=None Review URL: https://codereview.chromium.org/26116004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228215 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/transform.cc')
-rw-r--r--ui/gfx/transform.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
index ac62006..59e6a60 100644
--- a/ui/gfx/transform.cc
+++ b/ui/gfx/transform.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/strings/stringprintf.h"
+#include "ui/gfx/box_f.h"
#include "ui/gfx/point.h"
#include "ui/gfx/point3_f.h"
#include "ui/gfx/rect.h"
@@ -428,6 +429,33 @@ bool Transform::TransformRectReverse(RectF* rect) const {
return true;
}
+void Transform::TransformBox(BoxF* box) const {
+ BoxF bounds;
+ bool first_point = true;
+ for (int corner = 0; corner < 8; ++corner) {
+ gfx::Point3F point = box->origin();
+ point += gfx::Vector3dF(corner & 1 ? box->width() : 0.f,
+ corner & 2 ? box->height() : 0.f,
+ corner & 4 ? box->depth() : 0.f);
+ TransformPoint(&point);
+ if (first_point) {
+ bounds.set_origin(point);
+ first_point = false;
+ } else {
+ bounds.ExpandTo(point);
+ }
+ }
+ *box = bounds;
+}
+
+bool Transform::TransformBoxReverse(BoxF* box) const {
+ gfx::Transform inverse = *this;
+ if (!GetInverse(&inverse))
+ return false;
+ inverse.TransformBox(box);
+ return true;
+}
+
bool Transform::Blend(const Transform& from, double progress) {
DecomposedTransform to_decomp;
DecomposedTransform from_decomp;