Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_BASE_SCALE_TRANSLATE2D_H_ | |
| 6 #define CC_BASE_SCALE_TRANSLATE2D_H_ | |
| 7 | |
| 8 #include "ui/gfx/geometry/rect_f.h" | |
| 9 #include "ui/gfx/geometry/vector2d_f.h" | |
| 10 | |
| 11 class SkCanvas; | |
| 12 | |
| 13 namespace cc { | |
| 14 | |
| 15 class ScaleTranslate2d { | |
|
enne (OOO)
2016/08/29 20:21:18
There are a lot of functions here. Which of these
| |
| 16 public: | |
| 17 constexpr ScaleTranslate2d() : pre_scale_(0.f) {} | |
| 18 constexpr ScaleTranslate2d(float pre_scale, const gfx::Vector2dF& translation) | |
| 19 : pre_scale_(pre_scale), translation_(translation) {} | |
| 20 | |
| 21 bool operator==(const ScaleTranslate2d& other) const { | |
| 22 return pre_scale_ == other.pre_scale_ && translation_ == other.translation_; | |
| 23 } | |
| 24 bool operator!=(const ScaleTranslate2d& other) const { | |
| 25 return !(*this == other); | |
| 26 } | |
| 27 | |
| 28 static ScaleTranslate2d PreScale(const ScaleTranslate2d& t, float scale) { | |
| 29 return ScaleTranslate2d(t.pre_scale_ * scale, t.translation_); | |
| 30 } | |
| 31 void PreScale(float scale) { *this = PreScale(*this, scale); } | |
| 32 | |
| 33 static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) { | |
| 34 return ScaleTranslate2d(t.pre_scale_ * scale, | |
| 35 gfx::ScaleVector2d(t.translation_, scale)); | |
| 36 } | |
| 37 void PostScale(float scale) { *this = PostScale(*this, scale); } | |
| 38 | |
| 39 static ScaleTranslate2d PreTranslate(const ScaleTranslate2d& t, | |
| 40 const gfx::Vector2dF& translation) { | |
| 41 return ScaleTranslate2d( | |
| 42 t.pre_scale_, | |
| 43 gfx::ScaleVector2d(translation, t.pre_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.pre_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.pre_scale_ * post.pre_scale_, | |
| 61 gfx::ScaleVector2d(pre.translation_, post.pre_scale_) + | |
| 62 post.translation_); | |
| 63 } | |
| 64 void PreConcat(const ScaleTranslate2d& other) { | |
| 65 *this = Concat(*this, other); | |
| 66 } | |
| 67 void PostConcat(const ScaleTranslate2d& other) { | |
| 68 *this = Concat(other, *this); | |
| 69 } | |
| 70 | |
| 71 static ScaleTranslate2d Inverse(const ScaleTranslate2d& t) { | |
| 72 return ScaleTranslate2d( | |
| 73 1.f / t.pre_scale_, | |
| 74 gfx::ScaleVector2d(-t.translation_, 1.f / t.pre_scale_)); | |
| 75 } | |
| 76 void Invert() { *this = Inverse(*this); } | |
| 77 | |
| 78 gfx::PointF Transform(const gfx::PointF& p) const { | |
| 79 return gfx::ScalePoint(p, pre_scale_) + translation_; | |
| 80 } | |
| 81 gfx::PointF TransformReverse(const gfx::PointF& p) const { | |
| 82 return gfx::ScalePoint(p - translation_, 1.f / pre_scale_); | |
| 83 } | |
| 84 | |
| 85 gfx::RectF Transform(const gfx::RectF& r) const { | |
|
enne (OOO)
2016/08/29 20:21:18
Would it make sense to make these functions match
| |
| 86 return gfx::ScaleRect(r, pre_scale_) + translation_; | |
| 87 } | |
| 88 gfx::RectF TransformReverse(const gfx::RectF& r) const { | |
| 89 return gfx::ScaleRect(r - translation_, 1.f / pre_scale_); | |
| 90 } | |
| 91 | |
| 92 void ApplyToCanvas(SkCanvas* canvas) const; | |
| 93 | |
| 94 float pre_scale() const { return pre_scale_; } | |
| 95 gfx::Vector2dF translation() const { return translation_; } | |
| 96 | |
| 97 private: | |
| 98 float pre_scale_; | |
|
enne (OOO)
2016/08/29 20:21:18
bikeshed: I'd just call this "scale" with comments
| |
| 99 gfx::Vector2dF translation_; | |
| 100 }; | |
| 101 | |
| 102 } // namespace cc | |
| 103 | |
| 104 #endif // CC_BASE_SCALE_TRANSLATE2D_H_ | |
| OLD | NEW |