| OLD | NEW |
| 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 Loading... |
| 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) { | 43 void ClampToUpperBound(const Vector2d& max) { |
| 44 x_ = x_ <= max.x_ ? x_ : max.x_; | 44 x_ = x_ <= max.x_ ? x_ : max.x_; |
| 45 y_ = y_ <= max.y_ ? y_ : max.y_; | 45 y_ = y_ <= max.y_ ? y_ : max.y_; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void ClampToMin(const Vector2d& min) { | 48 void ClampToLowerBound(const Vector2d& min) { |
| 49 x_ = x_ >= min.x_ ? x_ : min.x_; | 49 x_ = x_ >= min.x_ ? x_ : min.x_; |
| 50 y_ = y_ >= min.y_ ? y_ : min.y_; | 50 y_ = y_ >= min.y_ ? y_ : min.y_; |
| 51 } | 51 } |
| 52 | 52 |
| 53 // 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 |
| 54 // 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 |
| 55 // relative lengths of different vectors without needing the actual lengths. | 55 // relative lengths of different vectors without needing the actual lengths. |
| 56 int64 LengthSquared() const; | 56 int64 LengthSquared() const; |
| 57 // Gives the diagonal length of the vector. | 57 // Gives the diagonal length of the vector. |
| 58 float Length() const; | 58 float Length() const; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 82 | 82 |
| 83 inline Vector2d operator-(const Vector2d& lhs, const Vector2d& rhs) { | 83 inline Vector2d operator-(const Vector2d& lhs, const Vector2d& rhs) { |
| 84 Vector2d result = lhs; | 84 Vector2d result = lhs; |
| 85 result.Add(-rhs); | 85 result.Add(-rhs); |
| 86 return result; | 86 return result; |
| 87 } | 87 } |
| 88 | 88 |
| 89 } // namespace gfx | 89 } // namespace gfx |
| 90 | 90 |
| 91 #endif // UI_GFX_VECTOR2D_H_ | 91 #endif // UI_GFX_VECTOR2D_H_ |
| OLD | NEW |