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

Side by Side Diff: ui/gfx/vector2d_f.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/vector2d.h ('k') | ui/gfx/vector2d_unittest.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 // Defines a simple float vector class. This class is used to indicate a 5 // Defines a simple float 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_F_H_ 10 #ifndef UI_GFX_VECTOR2D_F_H_
(...skipping 20 matching lines...) Expand all
31 bool IsZero() const; 31 bool IsZero() const;
32 32
33 // Add the components of the |other| vector to the current vector. 33 // Add the components of the |other| vector to the current vector.
34 void Add(const Vector2dF& other); 34 void Add(const Vector2dF& other);
35 // Subtract the components of the |other| vector from the current vector. 35 // Subtract the components of the |other| vector from the current vector.
36 void Subtract(const Vector2dF& other); 36 void Subtract(const Vector2dF& other);
37 37
38 void operator+=(const Vector2dF& other) { Add(other); } 38 void operator+=(const Vector2dF& other) { Add(other); }
39 void operator-=(const Vector2dF& other) { Subtract(other); } 39 void operator-=(const Vector2dF& other) { Subtract(other); }
40 40
41 void ClampToMax(const Vector2dF& max) {
42 x_ = x_ <= max.x_ ? x_ : max.x_;
43 y_ = y_ <= max.y_ ? y_ : max.y_;
44 }
45
46 void ClampToMin(const Vector2dF& min) {
47 x_ = x_ >= min.x_ ? x_ : min.x_;
48 y_ = y_ >= min.y_ ? y_ : min.y_;
49 }
50
41 // Gives the square of the diagonal length of the vector. 51 // Gives the square of the diagonal length of the vector.
42 double LengthSquared() const; 52 double LengthSquared() const;
43 // Gives the diagonal length of the vector. 53 // Gives the diagonal length of the vector.
44 float Length() const; 54 float Length() const;
45 55
46 // Scale the x and y components of the vector by |scale|. 56 // Scale the x and y components of the vector by |scale|.
47 void Scale(float scale) { Scale(scale, scale); } 57 void Scale(float scale) { Scale(scale, scale); }
48 // Scale the x and y components of the vector by |x_scale| and |y_scale| 58 // Scale the x and y components of the vector by |x_scale| and |y_scale|
49 // respectively. 59 // respectively.
50 void Scale(float x_scale, float y_scale); 60 void Scale(float x_scale, float y_scale);
(...skipping 27 matching lines...) Expand all
78 88
79 // Return the cross product of two vectors. 89 // Return the cross product of two vectors.
80 UI_EXPORT double CrossProduct(const Vector2dF& lhs, const Vector2dF& rhs); 90 UI_EXPORT double CrossProduct(const Vector2dF& lhs, const Vector2dF& rhs);
81 91
82 // Return the dot product of two vectors. 92 // Return the dot product of two vectors.
83 UI_EXPORT double DotProduct(const Vector2dF& lhs, const Vector2dF& rhs); 93 UI_EXPORT double DotProduct(const Vector2dF& lhs, const Vector2dF& rhs);
84 94
85 } // namespace gfx 95 } // namespace gfx
86 96
87 #endif // UI_GFX_VECTOR2D_F_H_ 97 #endif // UI_GFX_VECTOR2D_F_H_
OLDNEW
« no previous file with comments | « ui/gfx/vector2d.h ('k') | ui/gfx/vector2d_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698