| 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 #ifndef REMOTING_CLIENT_VIEW_MATRIX_H_ | |
| 6 #define REMOTING_CLIENT_VIEW_MATRIX_H_ | |
| 7 | |
| 8 #include <array> | |
| 9 | |
| 10 namespace remoting { | |
| 11 | |
| 12 // A 2D non-skew equally scaled transformation matrix. | |
| 13 // | SCALE, 0, OFFSET_X, | | |
| 14 // | 0, SCALE, OFFSET_Y, | | |
| 15 // | 0, 0, 1 | | |
| 16 class ViewMatrix { | |
| 17 public: | |
| 18 struct Vector2D { | |
| 19 float x; | |
| 20 float y; | |
| 21 }; | |
| 22 | |
| 23 // Same as Vector2D. This alias just serves as a context hint. | |
| 24 using Point = Vector2D; | |
| 25 | |
| 26 // Creates an empty matrix (0 scale and offsets). | |
| 27 ViewMatrix(); | |
| 28 | |
| 29 ViewMatrix(float scale, const Vector2D& offset); | |
| 30 | |
| 31 ~ViewMatrix(); | |
| 32 | |
| 33 // Applies the matrix on the point and returns the result. | |
| 34 Point MapPoint(const Point& point) const; | |
| 35 | |
| 36 // Applies the matrix on the vector and returns the result. This only scales | |
| 37 // the vector and does not apply offset. | |
| 38 Vector2D MapVector(const Vector2D& vector) const; | |
| 39 | |
| 40 // Sets the scale factor, with the pivot point at (0, 0). This WON'T affect | |
| 41 // the offset. | |
| 42 void SetScale(float scale); | |
| 43 | |
| 44 // Returns the scale of this matrix. | |
| 45 float GetScale() const; | |
| 46 | |
| 47 // Sets the offset. | |
| 48 void SetOffset(const Point& offset); | |
| 49 | |
| 50 // Adjust the matrix M to M' such that: | |
| 51 // M * p_a = p_b => M' * p_a = scale * (p_b - pivot) + pivot | |
| 52 void PostScale(const Point& pivot, float scale); | |
| 53 | |
| 54 // Applies translation to the matrix. | |
| 55 // M * p_a = p_b => M' * p_a = p_b + delta | |
| 56 void PostTranslate(const Vector2D& delta); | |
| 57 | |
| 58 // Returns the inverse of this matrix. | |
| 59 ViewMatrix Invert() const; | |
| 60 | |
| 61 // Returns true if the scale and offsets are both 0. | |
| 62 bool IsEmpty() const; | |
| 63 | |
| 64 // Converts to the 3x3 matrix array. | |
| 65 std::array<float, 9> ToMatrixArray() const; | |
| 66 | |
| 67 private: | |
| 68 float scale_; | |
| 69 Vector2D offset_; | |
| 70 }; | |
| 71 | |
| 72 } // namespace remoting | |
| 73 | |
| 74 #endif // REMOTING_CLIENT_VIEW_MATRIX_H_ | |
| OLD | NEW |