Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1881)

Unified Diff: mojo/services/geometry/cpp/geometry_util.cc

Issue 1782733002: Mozart: The great RectF-ication. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-9
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/geometry/cpp/geometry_util.h ('k') | mojo/services/geometry/interfaces/geometry.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/geometry/cpp/geometry_util.cc
diff --git a/mojo/services/geometry/cpp/geometry_util.cc b/mojo/services/geometry/cpp/geometry_util.cc
index f81e0ea2c2acec5437d04522c32a873bd42008cd..b9b3007b877e1feafb8984a8c41bef2678f0f0ef 100644
--- a/mojo/services/geometry/cpp/geometry_util.cc
+++ b/mojo/services/geometry/cpp/geometry_util.cc
@@ -6,6 +6,8 @@
#include <string.h>
+#include <limits>
+
namespace mojo {
static const float kIdentityMatrix[]{
@@ -26,21 +28,22 @@ void SetTranslationTransform(Transform* transform, float x, float y, float z) {
transform->matrix[11] = z;
}
-Point TransformPoint(const Transform& transform, const Point& point) {
- // TODO(jeffbrown): If w is 0, then the point should be at infinity.
- // Also, we should perhaps be using PointF here rather than Point.
+PointF TransformPoint(const Transform& transform, const PointF& point) {
+ PointF result;
float w = transform.matrix[12] * point.x + transform.matrix[13] * point.y +
transform.matrix[15];
- if (!w)
+ if (w) {
w = 1.f / w;
-
- Point result;
- result.x = (transform.matrix[0] * point.x + transform.matrix[1] * point.y +
- transform.matrix[3]) *
- w;
- result.y = (transform.matrix[4] * point.x + transform.matrix[5] * point.y +
- transform.matrix[7]) *
- w;
+ result.x = (transform.matrix[0] * point.x + transform.matrix[1] * point.y +
+ transform.matrix[3]) *
+ w;
+ result.y = (transform.matrix[4] * point.x + transform.matrix[5] * point.y +
+ transform.matrix[7]) *
+ w;
+ } else {
+ result.x = std::numeric_limits<float>::infinity();
+ result.y = std::numeric_limits<float>::infinity();
+ }
return result;
}
« no previous file with comments | « mojo/services/geometry/cpp/geometry_util.h ('k') | mojo/services/geometry/interfaces/geometry.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698