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) { | 47 void SetToMin(const Vector3dF& other) { |
48 x_ = x_ <= max.x_ ? x_ : max.x_; | 48 x_ = x_ <= other.x_ ? x_ : other.x_; |
49 y_ = y_ <= max.y_ ? y_ : max.y_; | 49 y_ = y_ <= other.y_ ? y_ : other.y_; |
50 z_ = z_ <= max.z_ ? z_ : max.z_; | 50 z_ = z_ <= other.z_ ? z_ : other.z_; |
51 } | 51 } |
52 | 52 |
53 void ClampToMin(const Vector3dF& min) { | 53 void SetToMax(const Vector3dF& other) { |
54 x_ = x_ >= min.x_ ? x_ : min.x_; | 54 x_ = x_ >= other.x_ ? x_ : other.x_; |
55 y_ = y_ >= min.y_ ? y_ : min.y_; | 55 y_ = y_ >= other.y_ ? y_ : other.y_; |
56 z_ = z_ >= min.z_ ? z_ : min.z_; | 56 z_ = z_ >= other.z_ ? z_ : other.z_; |
57 } | 57 } |
58 | 58 |
59 // Gives the square of the diagonal length of the vector. | 59 // Gives the square of the diagonal length of the vector. |
60 double LengthSquared() const; | 60 double LengthSquared() const; |
61 // Gives the diagonal length of the vector. | 61 // Gives the diagonal length of the vector. |
62 float Length() const; | 62 float Length() const; |
63 | 63 |
64 // Scale all components of the vector by |scale|. | 64 // Scale all components of the vector by |scale|. |
65 void Scale(float scale) { Scale(scale, scale, scale); } | 65 void Scale(float scale) { Scale(scale, scale, scale); } |
66 // 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. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 float z_scale); | 115 float z_scale); |
116 | 116 |
117 // Return a vector that is |v| scaled by the given scale factor. | 117 // Return a vector that is |v| scaled by the given scale factor. |
118 inline Vector3dF ScaleVector3d(const Vector3dF& v, float scale) { | 118 inline Vector3dF ScaleVector3d(const Vector3dF& v, float scale) { |
119 return ScaleVector3d(v, scale, scale, scale); | 119 return ScaleVector3d(v, scale, scale, scale); |
120 } | 120 } |
121 | 121 |
122 } // namespace gfx | 122 } // namespace gfx |
123 | 123 |
124 #endif // UI_GFX_VECTOR3D_F_H_ | 124 #endif // UI_GFX_VECTOR3D_F_H_ |
OLD | NEW |