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 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_VECTOR3D_F_H_ | 10 #ifndef UI_GFX_VECTOR3D_F_H_ |
(...skipping 26 matching lines...) Expand all Loading... |
37 bool IsZero() const; | 37 bool IsZero() const; |
38 | 38 |
39 // Add the components of the |other| vector to the current vector. | 39 // Add the components of the |other| vector to the current vector. |
40 void Add(const Vector3dF& other); | 40 void Add(const Vector3dF& other); |
41 // Subtract the components of the |other| vector from the current vector. | 41 // Subtract the components of the |other| vector from the current vector. |
42 void Subtract(const Vector3dF& other); | 42 void Subtract(const Vector3dF& other); |
43 | 43 |
44 void operator+=(const Vector3dF& other) { Add(other); } | 44 void operator+=(const Vector3dF& other) { Add(other); } |
45 void operator-=(const Vector3dF& other) { Subtract(other); } | 45 void operator-=(const Vector3dF& other) { Subtract(other); } |
46 | 46 |
| 47 void ClampToMax(const Vector3dF& max) { |
| 48 x_ = x_ <= max.x_ ? x_ : max.x_; |
| 49 y_ = y_ <= max.y_ ? y_ : max.y_; |
| 50 z_ = z_ <= max.z_ ? z_ : max.z_; |
| 51 } |
| 52 |
| 53 void ClampToMin(const Vector3dF& min) { |
| 54 x_ = x_ >= min.x_ ? x_ : min.x_; |
| 55 y_ = y_ >= min.y_ ? y_ : min.y_; |
| 56 z_ = z_ >= min.z_ ? z_ : min.z_; |
| 57 } |
| 58 |
47 // Gives the square of the diagonal length of the vector. | 59 // Gives the square of the diagonal length of the vector. |
48 double LengthSquared() const; | 60 double LengthSquared() const; |
49 // Gives the diagonal length of the vector. | 61 // Gives the diagonal length of the vector. |
50 float Length() const; | 62 float Length() const; |
51 | 63 |
52 // Scale all components of the vector by |scale|. | 64 // Scale all components of the vector by |scale|. |
53 void Scale(float scale) { Scale(scale, scale, scale); } | 65 void Scale(float scale) { Scale(scale, scale, scale); } |
54 // Scale the each component of the vector by the given scale factors. | 66 // Scale the each component of the vector by the given scale factors. |
55 void Scale(float x_scale, float y_scale, float z_scale); | 67 void Scale(float x_scale, float y_scale, float z_scale); |
56 | 68 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return result; | 104 return result; |
93 } | 105 } |
94 | 106 |
95 // Return the dot product of two vectors. | 107 // Return the dot product of two vectors. |
96 UI_EXPORT float DotProduct(const Vector3dF& lhs, const Vector3dF& rhs); | 108 UI_EXPORT float DotProduct(const Vector3dF& lhs, const Vector3dF& rhs); |
97 | 109 |
98 | 110 |
99 } // namespace gfx | 111 } // namespace gfx |
100 | 112 |
101 #endif // UI_GFX_VECTOR3D_F_H_ | 113 #endif // UI_GFX_VECTOR3D_F_H_ |
OLD | NEW |