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

Side by Side Diff: cc/base/scale_translate2d.h

Issue 2555363004: [6/6] git cl format (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | cc/blink/web_content_layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_BASE_SCALE_TRANSLATE2D_H_ 5 #ifndef CC_BASE_SCALE_TRANSLATE2D_H_
6 #define CC_BASE_SCALE_TRANSLATE2D_H_ 6 #define CC_BASE_SCALE_TRANSLATE2D_H_
7 7
8 #include "ui/gfx/geometry/rect_f.h" 8 #include "ui/gfx/geometry/rect_f.h"
9 #include "ui/gfx/geometry/vector2d_f.h" 9 #include "ui/gfx/geometry/vector2d_f.h"
10 10
11 class SkCanvas; 11 class SkCanvas;
12 12
13 namespace cc { 13 namespace cc {
14 14
15 class ScaleTranslate2d { 15 class ScaleTranslate2d {
16 public: 16 public:
17 constexpr ScaleTranslate2d() : scale_(1.f) { } 17 constexpr ScaleTranslate2d() : scale_(1.f) {}
18 constexpr ScaleTranslate2d(float scale, const gfx::Vector2dF& translation) 18 constexpr ScaleTranslate2d(float scale, const gfx::Vector2dF& translation)
19 : scale_(scale), translation_(translation) {} 19 : scale_(scale), translation_(translation) {}
20 20
21 bool operator==(const ScaleTranslate2d& other) const { 21 bool operator==(const ScaleTranslate2d& other) const {
22 return scale_ == other.scale_ && translation_ == other.translation_; 22 return scale_ == other.scale_ && translation_ == other.translation_;
23 } 23 }
24 bool operator!=(const ScaleTranslate2d& other) const { 24 bool operator!=(const ScaleTranslate2d& other) const {
25 return !(*this == other); 25 return !(*this == other);
26 } 26 }
27 27
28 static ScaleTranslate2d PreScale(const ScaleTranslate2d& t, float scale) { 28 static ScaleTranslate2d PreScale(const ScaleTranslate2d& t, float scale) {
29 return ScaleTranslate2d(t.scale_ * scale, t.translation_); 29 return ScaleTranslate2d(t.scale_ * scale, t.translation_);
30 } 30 }
31 void PreScale(float scale) { *this = PreScale(*this, scale); } 31 void PreScale(float scale) { *this = PreScale(*this, scale); }
32 32
33 static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) { 33 static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) {
34 return ScaleTranslate2d(t.scale_ * scale, 34 return ScaleTranslate2d(t.scale_ * scale,
35 gfx::ScaleVector2d(t.translation_, scale)); 35 gfx::ScaleVector2d(t.translation_, scale));
36 } 36 }
37 void PostScale(float scale) { *this = PostScale(*this, scale); } 37 void PostScale(float scale) { *this = PostScale(*this, scale); }
38 38
39 static ScaleTranslate2d PreTranslate(const ScaleTranslate2d& t, 39 static ScaleTranslate2d PreTranslate(const ScaleTranslate2d& t,
40 const gfx::Vector2dF& translation) { 40 const gfx::Vector2dF& translation) {
41 return ScaleTranslate2d( 41 return ScaleTranslate2d(
42 t.scale_, 42 t.scale_, gfx::ScaleVector2d(translation, t.scale_) + t.translation_);
43 gfx::ScaleVector2d(translation, t.scale_) + t.translation_);
44 } 43 }
45 void PreTranslate(const gfx::Vector2dF& translation) { 44 void PreTranslate(const gfx::Vector2dF& translation) {
46 *this = PreTranslate(*this, translation); 45 *this = PreTranslate(*this, translation);
47 } 46 }
48 47
49 static ScaleTranslate2d PostTranslate(const ScaleTranslate2d& t, 48 static ScaleTranslate2d PostTranslate(const ScaleTranslate2d& t,
50 const gfx::Vector2dF& translation) { 49 const gfx::Vector2dF& translation) {
51 return ScaleTranslate2d(t.scale_, t.translation_ + translation); 50 return ScaleTranslate2d(t.scale_, t.translation_ + translation);
52 } 51 }
53 void PostTranslate(const gfx::Vector2dF& translation) { 52 void PostTranslate(const gfx::Vector2dF& translation) {
54 *this = PostTranslate(*this, translation); 53 *this = PostTranslate(*this, translation);
55 } 54 }
56 55
57 static ScaleTranslate2d Concat(const ScaleTranslate2d& post, 56 static ScaleTranslate2d Concat(const ScaleTranslate2d& post,
58 const ScaleTranslate2d& pre) { 57 const ScaleTranslate2d& pre) {
59 return ScaleTranslate2d( 58 return ScaleTranslate2d(
60 pre.scale_ * post.scale_, 59 pre.scale_ * post.scale_,
61 gfx::ScaleVector2d(pre.translation_, post.scale_) + 60 gfx::ScaleVector2d(pre.translation_, post.scale_) + post.translation_);
62 post.translation_);
63 } 61 }
64 void PreConcat(const ScaleTranslate2d& other) { 62 void PreConcat(const ScaleTranslate2d& other) {
65 *this = Concat(*this, other); 63 *this = Concat(*this, other);
66 } 64 }
67 void PostConcat(const ScaleTranslate2d& other) { 65 void PostConcat(const ScaleTranslate2d& other) {
68 *this = Concat(other, *this); 66 *this = Concat(other, *this);
69 } 67 }
70 68
71 static ScaleTranslate2d Inverse(const ScaleTranslate2d& t) { 69 static ScaleTranslate2d Inverse(const ScaleTranslate2d& t) {
72 return ScaleTranslate2d( 70 return ScaleTranslate2d(1 / t.scale_,
73 1 / t.scale_, 71 gfx::ScaleVector2d(-t.translation_, 1 / t.scale_));
74 gfx::ScaleVector2d(-t.translation_, 1 / t.scale_));
75 } 72 }
76 void Invert() { *this = Inverse(*this); } 73 void Invert() { *this = Inverse(*this); }
77 74
78 gfx::PointF TransformPoint(const gfx::PointF& p) const { 75 gfx::PointF TransformPoint(const gfx::PointF& p) const {
79 return gfx::ScalePoint(p, scale_) + translation_; 76 return gfx::ScalePoint(p, scale_) + translation_;
80 } 77 }
81 gfx::PointF TransformPointReverse(const gfx::PointF& p) const { 78 gfx::PointF TransformPointReverse(const gfx::PointF& p) const {
82 return gfx::ScalePoint(p - translation_, 1.f / scale_); 79 return gfx::ScalePoint(p - translation_, 1.f / scale_);
83 } 80 }
84 81
(...skipping 14 matching lines...) Expand all
99 private: 96 private:
100 // Scale is applied before translation, i.e. 97 // Scale is applied before translation, i.e.
101 // this->Transform(p) == scale_ * p + translation_ 98 // this->Transform(p) == scale_ * p + translation_
102 float scale_; 99 float scale_;
103 gfx::Vector2dF translation_; 100 gfx::Vector2dF translation_;
104 }; 101 };
105 102
106 } // namespace cc 103 } // namespace cc
107 104
108 #endif // CC_BASE_SCALE_TRANSLATE2D_H_ 105 #endif // CC_BASE_SCALE_TRANSLATE2D_H_
OLDNEW
« no previous file with comments | « no previous file | cc/blink/web_content_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698