Chromium Code Reviews| 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_SIMPLE_MATRIX_H_ | |
| 6 #define REMOTING_CLIENT_SIMPLE_MATRIX_H_ | |
|
joedow
2017/04/28 21:29:53
Maybe just call this matrix? It isn't clear why i
Yuwei
2017/04/28 23:53:41
I called it simple because it only needs 3 paramet
| |
| 7 | |
| 8 #include "remoting/client/viewport_geometry.h" | |
| 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 SimpleMatrix { | |
|
Yuwei
2017/04/28 02:10:51
It's possible to use Skia to do matrix calculation
joedow
2017/04/28 21:29:53
I think saving ~1MB is a good reason since our pac
| |
| 17 public: | |
| 18 SimpleMatrix(float scale, const Vector2D& offset); | |
| 19 | |
| 20 ~SimpleMatrix(); | |
| 21 | |
| 22 // Applies the matrix on the point and returns the result. | |
| 23 Point MapPoint(const Point& point) const; | |
| 24 | |
| 25 // Applies the matrix on the vector and returns the result. This only scales | |
| 26 // the vector and does not apply offset. | |
| 27 Vector2D MapVector(const Vector2D& vector) const; | |
| 28 | |
| 29 // Sets the scale factor, with the pivot point at (0, 0). This WON'T affect | |
| 30 // the offset. | |
| 31 void SetScale(float scale); | |
| 32 | |
| 33 // Returns the scale of this matrix. | |
| 34 float GetScale() const; | |
| 35 | |
| 36 // Adjust the matrix M to M' such that: | |
| 37 // M * p_a = p_b => M' * p_a = scale * (p_b - pivot) + pivot | |
| 38 void PostScale(const Point& pivot, float scale); | |
| 39 | |
| 40 // Applies translation to the matrix. | |
| 41 // M * p_a = p_b => M' * p_a = p_b + delta | |
| 42 void PostTranslate(const Vector2D& delta); | |
| 43 | |
| 44 // Returns the inverse of this matrix. | |
| 45 SimpleMatrix Invert() const; | |
| 46 | |
| 47 // Converts to the 3x3 matrix array. | |
| 48 std::array<float, 9> ToMatrixArray() const; | |
| 49 | |
| 50 private: | |
| 51 float scale_; | |
| 52 Vector2D offset_; | |
| 53 }; | |
| 54 | |
| 55 } // namespace remoting | |
| 56 | |
| 57 #endif // REMOTING_CLIENT_SIMPLE_MATRIX_H_ | |
| OLD | NEW |