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

Side by Side Diff: remoting/client/simple_matrix.cc

Issue 2843373005: [Remoting Client] DesktopViewport Implementation (Closed)
Patch Set: Fix Created 3 years, 7 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/client/simple_matrix.h"
6
7 namespace remoting {
8
9 SimpleMatrix::SimpleMatrix(float scale, const Vector2D& offset)
10 : scale_(scale), offset_(offset) {}
11
12 SimpleMatrix::~SimpleMatrix() {}
13
14 Point SimpleMatrix::MapPoint(const Point& point) const {
15 float x = scale_ * point.x + offset_.x;
16 float y = scale_ * point.y + offset_.y;
17 return {x, y};
18 }
19
20 Vector2D SimpleMatrix::MapVector(const Vector2D& vector) const {
21 float x = scale_ * vector.x;
22 float y = scale_ * vector.y;
23 return {x, y};
24 }
25
26 void SimpleMatrix::SetScale(float scale) {
27 scale_ = scale;
28 }
29
30 float SimpleMatrix::GetScale() const {
31 return scale_;
32 }
33
34 void SimpleMatrix::PostScale(const Point& pivot, float scale) {
35 scale_ *= scale;
36 offset_.x += (1.f - scale) * pivot.x;
37 offset_.y += (1.f - scale) * pivot.y;
38 }
39
40 void SimpleMatrix::PostTranslate(const Vector2D& delta) {
41 offset_.x += delta.x;
42 offset_.y += delta.y;
43 }
44
45 SimpleMatrix SimpleMatrix::Invert() const {
46 return SimpleMatrix(1.f / scale_, {-offset_.x / scale_, -offset_.y / scale_});
47 }
48
49 std::array<float, 9> SimpleMatrix::ToMatrixArray() const {
50 return {{scale_, 0, offset_.x, // Row 1
51 0, scale_, offset_.y, // Row 2
52 0, 0, 1}};
53 }
54
55 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698