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

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

Issue 11361186: ui: Add methods to clamp Sizes, Points, and Vectors from above or below. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/size_unittest.cc ('k') | ui/gfx/vector2d_f.h » ('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 // Defines a simple integer vector class. This class is used to indicate a 5 // Defines a simple integer vector class. This class is used to indicate a
6 // distance in two dimensions between two points. Subtracting two points should 6 // distance in two dimensions between two points. Subtracting two points should
7 // produce a vector, and adding a vector to a point produces the point at the 7 // produce a vector, and adding a vector to a point produces the point at the
8 // vector's distance from the original point. 8 // vector's distance from the original point.
9 9
10 #ifndef UI_GFX_VECTOR2D_H_ 10 #ifndef UI_GFX_VECTOR2D_H_
(...skipping 22 matching lines...) Expand all
33 bool IsZero() const; 33 bool IsZero() const;
34 34
35 // Add the components of the |other| vector to the current vector. 35 // Add the components of the |other| vector to the current vector.
36 void Add(const Vector2d& other); 36 void Add(const Vector2d& other);
37 // Subtract the components of the |other| vector from the current vector. 37 // Subtract the components of the |other| vector from the current vector.
38 void Subtract(const Vector2d& other); 38 void Subtract(const Vector2d& other);
39 39
40 void operator+=(const Vector2d& other) { Add(other); } 40 void operator+=(const Vector2d& other) { Add(other); }
41 void operator-=(const Vector2d& other) { Subtract(other); } 41 void operator-=(const Vector2d& other) { Subtract(other); }
42 42
43 void ClampToMax(const Vector2d& max) {
44 x_ = x_ <= max.x_ ? x_ : max.x_;
45 y_ = y_ <= max.y_ ? y_ : max.y_;
46 }
47
48 void ClampToMin(const Vector2d& min) {
49 x_ = x_ >= min.x_ ? x_ : min.x_;
50 y_ = y_ >= min.y_ ? y_ : min.y_;
51 }
52
43 // Gives the square of the diagonal length of the vector. Since this is 53 // Gives the square of the diagonal length of the vector. Since this is
44 // cheaper to compute than Length(), it is useful when you want to compare 54 // cheaper to compute than Length(), it is useful when you want to compare
45 // relative lengths of different vectors without needing the actual lengths. 55 // relative lengths of different vectors without needing the actual lengths.
46 int64 LengthSquared() const; 56 int64 LengthSquared() const;
47 // Gives the diagonal length of the vector. 57 // Gives the diagonal length of the vector.
48 float Length() const; 58 float Length() const;
49 59
50 std::string ToString() const; 60 std::string ToString() const;
51 61
52 operator Vector2dF() const { return Vector2dF(x_, y_); } 62 operator Vector2dF() const { return Vector2dF(x_, y_); }
(...skipping 19 matching lines...) Expand all
72 82
73 inline Vector2d operator-(const Vector2d& lhs, const Vector2d& rhs) { 83 inline Vector2d operator-(const Vector2d& lhs, const Vector2d& rhs) {
74 Vector2d result = lhs; 84 Vector2d result = lhs;
75 result.Add(-rhs); 85 result.Add(-rhs);
76 return result; 86 return result;
77 } 87 }
78 88
79 } // namespace gfx 89 } // namespace gfx
80 90
81 #endif // UI_GFX_VECTOR2D_H_ 91 #endif // UI_GFX_VECTOR2D_H_
OLDNEW
« no previous file with comments | « ui/gfx/size_unittest.cc ('k') | ui/gfx/vector2d_f.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698