OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
danakj
2017/03/29 16:16:37
2017
trchen
2017/03/29 22:59:56
Acknowledged.
| |
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 CC_BASE_SCALE_TRANSLATE2D_H_ | |
6 #define CC_BASE_SCALE_TRANSLATE2D_H_ | |
7 | |
8 #include "cc/base/base_export.h" | |
9 #include "ui/gfx/geometry/rect_f.h" | |
10 #include "ui/gfx/geometry/vector2d_f.h" | |
11 | |
12 class SkCanvas; | |
13 | |
14 namespace cc { | |
15 | |
16 class CC_BASE_EXPORT ScaleTranslate2d { | |
enne (OOO)
2017/03/29 13:06:13
If you're going to add a geometry type, could you
danakj
2017/03/29 16:16:37
Please put a class-level comment on it explaining
trchen
2017/03/29 22:59:56
Acknowledged.
| |
17 public: | |
18 constexpr ScaleTranslate2d() : scale_(1.f) {} | |
danakj
2017/03/29 16:16:37
= default
trchen
2017/03/29 22:59:56
Acknowledged.
| |
19 constexpr ScaleTranslate2d(float scale, const gfx::Vector2dF& translation) | |
20 : scale_(scale), translation_(translation) {} | |
21 | |
22 bool operator==(const ScaleTranslate2d& other) const { | |
23 return scale_ == other.scale_ && translation_ == other.translation_; | |
24 } | |
25 bool operator!=(const ScaleTranslate2d& other) const { | |
26 return !(*this == other); | |
27 } | |
28 | |
29 static ScaleTranslate2d PreScale(const ScaleTranslate2d& t, float scale) { | |
danakj
2017/03/29 16:16:37
It would be nice to make these static methods into
trchen
2017/03/29 22:59:56
Acknowledged.
I will follow the existing conventi
| |
30 return ScaleTranslate2d(t.scale_ * scale, t.translation_); | |
31 } | |
32 void PreScale(float scale) { *this = PreScale(*this, scale); } | |
danakj
2017/03/29 16:16:37
This is maybe a nit, or maybe nicer if the statics
trchen
2017/03/29 22:59:56
Acknowledged.
| |
33 | |
34 static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) { | |
35 return ScaleTranslate2d(t.scale_ * scale, | |
36 gfx::ScaleVector2d(t.translation_, scale)); | |
37 } | |
38 void PostScale(float scale) { *this = PostScale(*this, scale); } | |
39 | |
40 static ScaleTranslate2d PreTranslate(const ScaleTranslate2d& t, | |
41 const gfx::Vector2dF& translation) { | |
42 return ScaleTranslate2d( | |
43 t.scale_, gfx::ScaleVector2d(translation, t.scale_) + t.translation_); | |
44 } | |
45 void PreTranslate(const gfx::Vector2dF& translation) { | |
46 *this = PreTranslate(*this, translation); | |
47 } | |
48 | |
49 static ScaleTranslate2d PostTranslate(const ScaleTranslate2d& t, | |
50 const gfx::Vector2dF& translation) { | |
51 return ScaleTranslate2d(t.scale_, t.translation_ + translation); | |
52 } | |
53 void PostTranslate(const gfx::Vector2dF& translation) { | |
54 *this = PostTranslate(*this, translation); | |
55 } | |
56 | |
57 static ScaleTranslate2d Concat(const ScaleTranslate2d& post, | |
58 const ScaleTranslate2d& pre) { | |
59 return ScaleTranslate2d( | |
60 pre.scale_ * post.scale_, | |
61 gfx::ScaleVector2d(pre.translation_, post.scale_) + post.translation_); | |
62 } | |
63 void PreConcat(const ScaleTranslate2d& other) { | |
64 *this = Concat(*this, other); | |
65 } | |
66 void PostConcat(const ScaleTranslate2d& other) { | |
67 *this = Concat(other, *this); | |
68 } | |
69 | |
70 static ScaleTranslate2d Inverse(const ScaleTranslate2d& t) { | |
71 return ScaleTranslate2d(1 / t.scale_, | |
72 gfx::ScaleVector2d(-t.translation_, 1 / t.scale_)); | |
73 } | |
74 void Invert() { *this = Inverse(*this); } | |
75 | |
76 gfx::PointF TransformPoint(const gfx::PointF& p) const { | |
danakj
2017/03/29 16:16:37
I'd say everything should be s/Transform/Map/g cuz
trchen
2017/03/29 22:59:56
Acknowledged. YYYYES! I was following gfx::Transfo
| |
77 return gfx::ScalePoint(p, scale_) + translation_; | |
78 } | |
79 gfx::PointF TransformPointReverse(const gfx::PointF& p) const { | |
80 return gfx::ScalePoint(p - translation_, 1.f / scale_); | |
81 } | |
82 | |
83 gfx::RectF TransformRect(const gfx::RectF& r) const { | |
84 return gfx::ScaleRect(r, scale_) + translation_; | |
85 } | |
86 gfx::RectF TransformRectReverse(const gfx::RectF& r) const { | |
enne (OOO)
2017/03/29 13:06:13
naming nit: Maybe InverseTransformRect, as it real
trchen
2017/03/29 22:59:56
Acknowledged. Was following gfx::Transform. Perhap
| |
87 return gfx::ScaleRect(r - translation_, 1.f / scale_); | |
88 } | |
89 | |
90 void ApplyToCanvas(SkCanvas* canvas) const; | |
danakj
2017/03/29 16:16:37
This seems like something that should not be part
trchen
2017/03/29 22:59:56
Agreed. Somewhere in ui/gfx? cc/base? skia/ext?
trchen
2017/03/30 20:56:05
It's only called once. Unrolled & removed this hel
| |
91 | |
92 float scale() const { return scale_; } | |
93 gfx::Vector2dF translation() const { return translation_; } | |
94 | |
95 std::string ToString() const { return "todo"; } | |
96 | |
97 private: | |
98 // Scale is applied before translation, i.e. | |
danakj
2017/03/29 16:16:37
This type of thing seems like it should be part of
trchen
2017/03/29 22:59:56
I think the opposite. At the class level all we kn
trchen
2017/03/30 20:56:05
Anyway, also added comments at the top about pre-s
| |
99 // this->Transform(p) == scale_ * p + translation_ | |
100 float scale_; | |
danakj
2017/03/29 16:16:37
= 1.f
trchen
2017/03/29 22:59:56
Acknowledged.
| |
101 gfx::Vector2dF translation_; | |
102 }; | |
103 | |
104 } // namespace cc | |
105 | |
106 #endif // CC_BASE_SCALE_TRANSLATE2D_H_ | |
OLD | NEW |