Index: cc/base/scale_translate2d.h |
diff --git a/cc/base/scale_translate2d.h b/cc/base/scale_translate2d.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e045f8cfd84446e8bad6eaf202ffcd9749517058 |
--- /dev/null |
+++ b/cc/base/scale_translate2d.h |
@@ -0,0 +1,106 @@ |
+// 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.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CC_BASE_SCALE_TRANSLATE2D_H_ |
+#define CC_BASE_SCALE_TRANSLATE2D_H_ |
+ |
+#include "cc/base/base_export.h" |
+#include "ui/gfx/geometry/rect_f.h" |
+#include "ui/gfx/geometry/vector2d_f.h" |
+ |
+class SkCanvas; |
+ |
+namespace cc { |
+ |
+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.
|
+ public: |
+ constexpr ScaleTranslate2d() : scale_(1.f) {} |
danakj
2017/03/29 16:16:37
= default
trchen
2017/03/29 22:59:56
Acknowledged.
|
+ constexpr ScaleTranslate2d(float scale, const gfx::Vector2dF& translation) |
+ : scale_(scale), translation_(translation) {} |
+ |
+ bool operator==(const ScaleTranslate2d& other) const { |
+ return scale_ == other.scale_ && translation_ == other.translation_; |
+ } |
+ bool operator!=(const ScaleTranslate2d& other) const { |
+ return !(*this == other); |
+ } |
+ |
+ 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
|
+ return ScaleTranslate2d(t.scale_ * scale, t.translation_); |
+ } |
+ 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.
|
+ |
+ static ScaleTranslate2d PostScale(const ScaleTranslate2d& t, float scale) { |
+ return ScaleTranslate2d(t.scale_ * scale, |
+ gfx::ScaleVector2d(t.translation_, scale)); |
+ } |
+ void PostScale(float scale) { *this = PostScale(*this, scale); } |
+ |
+ static ScaleTranslate2d PreTranslate(const ScaleTranslate2d& t, |
+ const gfx::Vector2dF& translation) { |
+ return ScaleTranslate2d( |
+ t.scale_, gfx::ScaleVector2d(translation, t.scale_) + t.translation_); |
+ } |
+ void PreTranslate(const gfx::Vector2dF& translation) { |
+ *this = PreTranslate(*this, translation); |
+ } |
+ |
+ static ScaleTranslate2d PostTranslate(const ScaleTranslate2d& t, |
+ const gfx::Vector2dF& translation) { |
+ return ScaleTranslate2d(t.scale_, t.translation_ + translation); |
+ } |
+ void PostTranslate(const gfx::Vector2dF& translation) { |
+ *this = PostTranslate(*this, translation); |
+ } |
+ |
+ static ScaleTranslate2d Concat(const ScaleTranslate2d& post, |
+ const ScaleTranslate2d& pre) { |
+ return ScaleTranslate2d( |
+ pre.scale_ * post.scale_, |
+ gfx::ScaleVector2d(pre.translation_, post.scale_) + post.translation_); |
+ } |
+ void PreConcat(const ScaleTranslate2d& other) { |
+ *this = Concat(*this, other); |
+ } |
+ void PostConcat(const ScaleTranslate2d& other) { |
+ *this = Concat(other, *this); |
+ } |
+ |
+ static ScaleTranslate2d Inverse(const ScaleTranslate2d& t) { |
+ return ScaleTranslate2d(1 / t.scale_, |
+ gfx::ScaleVector2d(-t.translation_, 1 / t.scale_)); |
+ } |
+ void Invert() { *this = Inverse(*this); } |
+ |
+ 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
|
+ return gfx::ScalePoint(p, scale_) + translation_; |
+ } |
+ gfx::PointF TransformPointReverse(const gfx::PointF& p) const { |
+ return gfx::ScalePoint(p - translation_, 1.f / scale_); |
+ } |
+ |
+ gfx::RectF TransformRect(const gfx::RectF& r) const { |
+ return gfx::ScaleRect(r, scale_) + translation_; |
+ } |
+ 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
|
+ return gfx::ScaleRect(r - translation_, 1.f / scale_); |
+ } |
+ |
+ 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
|
+ |
+ float scale() const { return scale_; } |
+ gfx::Vector2dF translation() const { return translation_; } |
+ |
+ std::string ToString() const { return "todo"; } |
+ |
+ private: |
+ // 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
|
+ // this->Transform(p) == scale_ * p + translation_ |
+ float scale_; |
danakj
2017/03/29 16:16:37
= 1.f
trchen
2017/03/29 22:59:56
Acknowledged.
|
+ gfx::Vector2dF translation_; |
+}; |
+ |
+} // namespace cc |
+ |
+#endif // CC_BASE_SCALE_TRANSLATE2D_H_ |