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

Side by Side Diff: mojo/services/geometry/cpp/geometry_util.cc

Issue 1776473005: Mozart: Implement basic input event dispatch with hit testing. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-7
Patch Set: 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
« no previous file with comments | « mojo/services/geometry/cpp/geometry_util.h ('k') | services/ui/input_manager/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 namespace mojo { 9 namespace mojo {
10 10
11 static const float kIdentityMatrix[]{ 11 static const float kIdentityMatrix[]{
12 1.f, 0.f, 0.f, 0.f, // comments to prevent 12 1.f, 0.f, 0.f, 0.f, // comments to prevent
13 0.f, 1.f, 0.f, 0.f, // auto formatter reflow 13 0.f, 1.f, 0.f, 0.f, // auto formatter reflow
14 0.f, 0.f, 1.f, 0.f, // 14 0.f, 0.f, 1.f, 0.f, //
15 0.f, 0.f, 0.f, 1.f}; 15 0.f, 0.f, 0.f, 1.f};
16 16
17 void SetIdentityTransform(Transform* transform) { 17 void SetIdentityTransform(Transform* transform) {
18 transform->matrix.resize(16u); 18 transform->matrix.resize(16u);
19 memcpy(transform->matrix.data(), kIdentityMatrix, sizeof(kIdentityMatrix)); 19 memcpy(transform->matrix.data(), kIdentityMatrix, sizeof(kIdentityMatrix));
20 } 20 }
21 21
22 void SetTranslationTransform(Transform* transform, float x, float y, float z) { 22 void SetTranslationTransform(Transform* transform, float x, float y, float z) {
23 SetIdentityTransform(transform); 23 SetIdentityTransform(transform);
24 transform->matrix[3] = x; 24 transform->matrix[3] = x;
25 transform->matrix[7] = y; 25 transform->matrix[7] = y;
26 transform->matrix[11] = z; 26 transform->matrix[11] = z;
27 } 27 }
28 28
29 Point TransformPoint(const Transform& transform, const Point& point) {
30 // TODO(jeffbrown): If w is 0, then the point should be at infinity.
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 transform.matrix[15];
34 if (!w)
35 w = 1.f / w;
36
37 Point result;
38 result.x = (transform.matrix[0] * point.x + transform.matrix[1] * point.y +
39 transform.matrix[3]) *
40 w;
41 result.y = (transform.matrix[4] * point.x + transform.matrix[5] * point.y +
42 transform.matrix[7]) *
43 w;
44 return result;
45 }
46
29 } // namespace mojo 47 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/geometry/cpp/geometry_util.h ('k') | services/ui/input_manager/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698