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; |
} |