| 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/view_matrix.h" | |
| 6 | |
| 7 namespace remoting { | |
| 8 | |
| 9 ViewMatrix::ViewMatrix() : ViewMatrix(0.f, {0.f, 0.f}) {} | |
| 10 | |
| 11 ViewMatrix::ViewMatrix(float scale, const Vector2D& offset) | |
| 12 : scale_(scale), offset_(offset) {} | |
| 13 | |
| 14 ViewMatrix::~ViewMatrix() {} | |
| 15 | |
| 16 ViewMatrix::Point ViewMatrix::MapPoint(const Point& point) const { | |
| 17 float x = scale_ * point.x + offset_.x; | |
| 18 float y = scale_ * point.y + offset_.y; | |
| 19 return {x, y}; | |
| 20 } | |
| 21 | |
| 22 ViewMatrix::Vector2D ViewMatrix::MapVector(const Vector2D& vector) const { | |
| 23 float x = scale_ * vector.x; | |
| 24 float y = scale_ * vector.y; | |
| 25 return {x, y}; | |
| 26 } | |
| 27 | |
| 28 void ViewMatrix::SetScale(float scale) { | |
| 29 scale_ = scale; | |
| 30 } | |
| 31 | |
| 32 float ViewMatrix::GetScale() const { | |
| 33 return scale_; | |
| 34 } | |
| 35 | |
| 36 void ViewMatrix::SetOffset(const Point& offset) { | |
| 37 offset_ = offset; | |
| 38 } | |
| 39 | |
| 40 void ViewMatrix::PostScale(const Point& pivot, float scale) { | |
| 41 scale_ *= scale; | |
| 42 offset_.x *= scale; | |
| 43 offset_.x += (1.f - scale) * pivot.x; | |
| 44 offset_.y *= scale; | |
| 45 offset_.y += (1.f - scale) * pivot.y; | |
| 46 } | |
| 47 | |
| 48 void ViewMatrix::PostTranslate(const Vector2D& delta) { | |
| 49 offset_.x += delta.x; | |
| 50 offset_.y += delta.y; | |
| 51 } | |
| 52 | |
| 53 ViewMatrix ViewMatrix::Invert() const { | |
| 54 return ViewMatrix(1.f / scale_, {-offset_.x / scale_, -offset_.y / scale_}); | |
| 55 } | |
| 56 | |
| 57 std::array<float, 9> ViewMatrix::ToMatrixArray() const { | |
| 58 return {{scale_, 0, offset_.x, // Row 1 | |
| 59 0, scale_, offset_.y, // Row 2 | |
| 60 0, 0, 1}}; | |
| 61 } | |
| 62 | |
| 63 bool ViewMatrix::IsEmpty() const { | |
| 64 return scale_ == 0.f && offset_.x == 0.f && offset_.y == 0.f; | |
| 65 } | |
| 66 | |
| 67 } // namespace remoting | |
| OLD | NEW |