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> | 13 #include <stdint.h> |
14 | 14 |
15 #include <iosfwd> | 15 #include <iosfwd> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "ui/gfx/geometry/vector2d_f.h" | 18 #include "ui/gfx/geometry/vector2d_f.h" |
19 #include "ui/gfx/gfx_export.h" | 19 #include "ui/gfx/gfx_export.h" |
20 | 20 |
21 namespace gfx { | 21 namespace gfx { |
22 | 22 |
23 class GFX_EXPORT Vector2d { | 23 class GFX_EXPORT Vector2d { |
24 public: | 24 public: |
25 Vector2d() : x_(0), y_(0) {} | 25 constexpr Vector2d() : x_(0), y_(0) {} |
26 Vector2d(int x, int y) : x_(x), y_(y) {} | 26 constexpr Vector2d(int x, int y) : x_(x), y_(y) {} |
27 | 27 |
28 int x() const { return x_; } | 28 constexpr int x() const { return x_; } |
29 void set_x(int x) { x_ = x; } | 29 void set_x(int x) { x_ = x; } |
30 | 30 |
31 int y() const { return y_; } | 31 constexpr int y() const { return y_; } |
32 void set_y(int y) { y_ = y; } | 32 void set_y(int y) { y_ = y; } |
33 | 33 |
34 // True if both components of the vector are 0. | 34 // True if both components of the vector are 0. |
35 bool IsZero() const; | 35 bool IsZero() const; |
36 | 36 |
37 // Add the components of the |other| vector to the current vector. | 37 // Add the components of the |other| vector to the current vector. |
38 void Add(const Vector2d& other); | 38 void Add(const Vector2d& other); |
39 // Subtract the components of the |other| vector from the current vector. | 39 // Subtract the components of the |other| vector from the current vector. |
40 void Subtract(const Vector2d& other); | 40 void Subtract(const Vector2d& other); |
41 | 41 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 | 92 |
93 // 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 |
94 // 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. |
95 // This should not be used in production code - call ToString() instead. | 95 // This should not be used in production code - call ToString() instead. |
96 void PrintTo(const Vector2d& vector, ::std::ostream* os); | 96 void PrintTo(const Vector2d& vector, ::std::ostream* os); |
97 | 97 |
98 } // namespace gfx | 98 } // namespace gfx |
99 | 99 |
100 #endif // UI_GFX_GEOMETRY_VECTOR2D_H_ | 100 #endif // UI_GFX_GEOMETRY_VECTOR2D_H_ |
OLD | NEW |