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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/services/geometry/cpp/geometry_util.h" 5 #include "mojo/services/geometry/cpp/geometry_util.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <limits>
10
9 namespace mojo { 11 namespace mojo {
10 12
11 static const float kIdentityMatrix[]{ 13 static const float kIdentityMatrix[]{
12 1.f, 0.f, 0.f, 0.f, // comments to prevent 14 1.f, 0.f, 0.f, 0.f, // comments to prevent
13 0.f, 1.f, 0.f, 0.f, // auto formatter reflow 15 0.f, 1.f, 0.f, 0.f, // auto formatter reflow
14 0.f, 0.f, 1.f, 0.f, // 16 0.f, 0.f, 1.f, 0.f, //
15 0.f, 0.f, 0.f, 1.f}; 17 0.f, 0.f, 0.f, 1.f};
16 18
17 void SetIdentityTransform(Transform* transform) { 19 void SetIdentityTransform(Transform* transform) {
18 transform->matrix.resize(16u); 20 transform->matrix.resize(16u);
19 memcpy(transform->matrix.data(), kIdentityMatrix, sizeof(kIdentityMatrix)); 21 memcpy(transform->matrix.data(), kIdentityMatrix, sizeof(kIdentityMatrix));
20 } 22 }
21 23
22 void SetTranslationTransform(Transform* transform, float x, float y, float z) { 24 void SetTranslationTransform(Transform* transform, float x, float y, float z) {
23 SetIdentityTransform(transform); 25 SetIdentityTransform(transform);
24 transform->matrix[3] = x; 26 transform->matrix[3] = x;
25 transform->matrix[7] = y; 27 transform->matrix[7] = y;
26 transform->matrix[11] = z; 28 transform->matrix[11] = z;
27 } 29 }
28 30
29 Point TransformPoint(const Transform& transform, const Point& point) { 31 PointF TransformPoint(const Transform& transform, const PointF& point) {
30 // TODO(jeffbrown): If w is 0, then the point should be at infinity. 32 PointF result;
31 // Also, we should perhaps be using PointF here rather than Point.
32 float w = transform.matrix[12] * point.x + transform.matrix[13] * point.y + 33 float w = transform.matrix[12] * point.x + transform.matrix[13] * point.y +
33 transform.matrix[15]; 34 transform.matrix[15];
34 if (!w) 35 if (w) {
35 w = 1.f / w; 36 w = 1.f / w;
36 37 result.x = (transform.matrix[0] * point.x + transform.matrix[1] * point.y +
37 Point result; 38 transform.matrix[3]) *
38 result.x = (transform.matrix[0] * point.x + transform.matrix[1] * point.y + 39 w;
39 transform.matrix[3]) * 40 result.y = (transform.matrix[4] * point.x + transform.matrix[5] * point.y +
40 w; 41 transform.matrix[7]) *
41 result.y = (transform.matrix[4] * point.x + transform.matrix[5] * point.y + 42 w;
42 transform.matrix[7]) * 43 } else {
43 w; 44 result.x = std::numeric_limits<float>::infinity();
45 result.y = std::numeric_limits<float>::infinity();
46 }
44 return result; 47 return result;
45 } 48 }
46 49
47 } // namespace mojo 50 } // namespace mojo
OLDNEW
« 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