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

Side by Side Diff: ui/gfx/transform.h

Issue 2585263003: Avoid overflow when checking if a transform is integer translation. (Closed)
Patch Set: integer-transform 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 | ui/gfx/transform.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_GFX_TRANSFORM_H_ 5 #ifndef UI_GFX_TRANSFORM_H_
6 #define UI_GFX_TRANSFORM_H_ 6 #define UI_GFX_TRANSFORM_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 10
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 bool IsApproximatelyIdentityOrTranslation(SkMScalar tolerance) const; 133 bool IsApproximatelyIdentityOrTranslation(SkMScalar tolerance) const;
134 134
135 // Returns true if the matrix is either a positive scale and/or a translation. 135 // Returns true if the matrix is either a positive scale and/or a translation.
136 bool IsPositiveScaleOrTranslation() const { 136 bool IsPositiveScaleOrTranslation() const {
137 if (!IsScaleOrTranslation()) 137 if (!IsScaleOrTranslation())
138 return false; 138 return false;
139 return matrix_.get(0, 0) > 0.0 && matrix_.get(1, 1) > 0.0 && 139 return matrix_.get(0, 0) > 0.0 && matrix_.get(1, 1) > 0.0 &&
140 matrix_.get(2, 2) > 0.0; 140 matrix_.get(2, 2) > 0.0;
141 } 141 }
142 142
143 // Returns true if the matrix is either identity or pure, non-fractional 143 // Returns true if the matrix is identity or, if the matrix consists only
144 // translation. 144 // of a translation whose components can be represented as integers. Returns
145 // false if the translation contains a fractional component or is too large to
146 // fit in an integer.
145 bool IsIdentityOrIntegerTranslation() const; 147 bool IsIdentityOrIntegerTranslation() const;
146 148
147 // Returns true if the matrix had only scaling components. 149 // Returns true if the matrix had only scaling components.
148 bool IsScale2d() const { return matrix_.isScale(); } 150 bool IsScale2d() const { return matrix_.isScale(); }
149 151
150 // Returns true if the matrix is has only scaling and translation components. 152 // Returns true if the matrix is has only scaling and translation components.
151 bool IsScaleOrTranslation() const { return matrix_.isScaleTranslate(); } 153 bool IsScaleOrTranslation() const { return matrix_.isScaleTranslate(); }
152 154
153 // Returns true if axis-aligned 2d rects will remain axis-aligned after being 155 // Returns true if axis-aligned 2d rects will remain axis-aligned after being
154 // transformed by this matrix. 156 // transformed by this matrix.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 }; 281 };
280 282
281 // This is declared here for use in gtest-based unit tests but is defined in 283 // This is declared here for use in gtest-based unit tests but is defined in
282 // the //ui/gfx:test_support target. Depend on that to use this in your unit 284 // the //ui/gfx:test_support target. Depend on that to use this in your unit
283 // test. This should not be used in production code - call ToString() instead. 285 // test. This should not be used in production code - call ToString() instead.
284 void PrintTo(const Transform& transform, ::std::ostream* os); 286 void PrintTo(const Transform& transform, ::std::ostream* os);
285 287
286 } // namespace gfx 288 } // namespace gfx
287 289
288 #endif // UI_GFX_TRANSFORM_H_ 290 #endif // UI_GFX_TRANSFORM_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/transform.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698