OLD | NEW |
(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 |
OLD | NEW |