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 #ifndef UI_GFX_POINT_BASE_H_ | 5 #ifndef UI_GFX_POINT_BASE_H_ |
6 #define UI_GFX_POINT_BASE_H_ | 6 #define UI_GFX_POINT_BASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 void operator+=(const VectorClass& vector) { | 36 void operator+=(const VectorClass& vector) { |
37 Offset(vector.x(), vector.y()); | 37 Offset(vector.x(), vector.y()); |
38 } | 38 } |
39 | 39 |
40 void operator-=(const VectorClass& vector) { | 40 void operator-=(const VectorClass& vector) { |
41 Offset(-vector.x(), -vector.y()); | 41 Offset(-vector.x(), -vector.y()); |
42 } | 42 } |
43 | 43 |
| 44 void ClampToMax(const Class& max) { |
| 45 x_ = x_ <= max.x_ ? x_ : max.x_; |
| 46 y_ = y_ <= max.y_ ? y_ : max.y_; |
| 47 } |
| 48 |
| 49 void ClampToMin(const Class& min) { |
| 50 x_ = x_ >= min.x_ ? x_ : min.x_; |
| 51 y_ = y_ >= min.y_ ? y_ : min.y_; |
| 52 } |
| 53 |
44 bool IsOrigin() const { | 54 bool IsOrigin() const { |
45 return x_ == 0 && y_ == 0; | 55 return x_ == 0 && y_ == 0; |
46 } | 56 } |
47 | 57 |
48 VectorClass OffsetFromOrigin() const { | 58 VectorClass OffsetFromOrigin() const { |
49 return VectorClass(x_, y_); | 59 return VectorClass(x_, y_); |
50 } | 60 } |
51 | 61 |
52 VectorClass OffsetFrom(const Class& other) const { | 62 VectorClass OffsetFrom(const Class& other) const { |
53 return VectorClass(x_ - other.x_, y_ - other.y_); | 63 return VectorClass(x_ - other.x_, y_ - other.y_); |
(...skipping 16 matching lines...) Expand all Loading... |
70 ~PointBase() {} | 80 ~PointBase() {} |
71 | 81 |
72 private: | 82 private: |
73 Type x_; | 83 Type x_; |
74 Type y_; | 84 Type y_; |
75 }; | 85 }; |
76 | 86 |
77 } // namespace gfx | 87 } // namespace gfx |
78 | 88 |
79 #endif // UI_GFX_POINT_BASE_H_ | 89 #endif // UI_GFX_POINT_BASE_H_ |
OLD | NEW |