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_GEOMETRY_VECTOR2D_H_ | 10 #ifndef UI_GFX_GEOMETRY_VECTOR2D_H_ |
11 #define UI_GFX_GEOMETRY_VECTOR2D_H_ | 11 #define UI_GFX_GEOMETRY_VECTOR2D_H_ |
12 | 12 |
| 13 #include <stdint.h> |
| 14 |
13 #include <iosfwd> | 15 #include <iosfwd> |
14 #include <string> | 16 #include <string> |
15 | 17 |
16 #include "base/basictypes.h" | |
17 #include "ui/gfx/geometry/vector2d_f.h" | 18 #include "ui/gfx/geometry/vector2d_f.h" |
18 #include "ui/gfx/gfx_export.h" | 19 #include "ui/gfx/gfx_export.h" |
19 | 20 |
20 namespace gfx { | 21 namespace gfx { |
21 | 22 |
22 class GFX_EXPORT Vector2d { | 23 class GFX_EXPORT Vector2d { |
23 public: | 24 public: |
24 Vector2d() : x_(0), y_(0) {} | 25 Vector2d() : x_(0), y_(0) {} |
25 Vector2d(int x, int y) : x_(x), y_(y) {} | 26 Vector2d(int x, int y) : x_(x), y_(y) {} |
26 | 27 |
(...skipping 20 matching lines...) Expand all Loading... |
47 } | 48 } |
48 | 49 |
49 void SetToMax(const Vector2d& other) { | 50 void SetToMax(const Vector2d& other) { |
50 x_ = x_ >= other.x_ ? x_ : other.x_; | 51 x_ = x_ >= other.x_ ? x_ : other.x_; |
51 y_ = y_ >= other.y_ ? y_ : other.y_; | 52 y_ = y_ >= other.y_ ? y_ : other.y_; |
52 } | 53 } |
53 | 54 |
54 // Gives the square of the diagonal length of the vector. Since this is | 55 // Gives the square of the diagonal length of the vector. Since this is |
55 // cheaper to compute than Length(), it is useful when you want to compare | 56 // cheaper to compute than Length(), it is useful when you want to compare |
56 // relative lengths of different vectors without needing the actual lengths. | 57 // relative lengths of different vectors without needing the actual lengths. |
57 int64 LengthSquared() const; | 58 int64_t LengthSquared() const; |
58 // Gives the diagonal length of the vector. | 59 // Gives the diagonal length of the vector. |
59 float Length() const; | 60 float Length() const; |
60 | 61 |
61 std::string ToString() const; | 62 std::string ToString() const; |
62 | 63 |
63 operator Vector2dF() const { | 64 operator Vector2dF() const { |
64 return Vector2dF(static_cast<float>(x()), static_cast<float>(y())); | 65 return Vector2dF(static_cast<float>(x()), static_cast<float>(y())); |
65 } | 66 } |
66 | 67 |
67 private: | 68 private: |
(...skipping 22 matching lines...) Expand all Loading... |
90 } | 91 } |
91 | 92 |
92 // This is declared here for use in gtest-based unit tests but is defined in | 93 // This is declared here for use in gtest-based unit tests but is defined in |
93 // the gfx_test_support target. Depend on that to use this in your unit test. | 94 // the gfx_test_support target. Depend on that to use this in your unit test. |
94 // This should not be used in production code - call ToString() instead. | 95 // This should not be used in production code - call ToString() instead. |
95 void PrintTo(const Vector2d& vector, ::std::ostream* os); | 96 void PrintTo(const Vector2d& vector, ::std::ostream* os); |
96 | 97 |
97 } // namespace gfx | 98 } // namespace gfx |
98 | 99 |
99 #endif // UI_GFX_GEOMETRY_VECTOR2D_H_ | 100 #endif // UI_GFX_GEOMETRY_VECTOR2D_H_ |
OLD | NEW |