OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef UI_GFX_POINT_H_ |
6 #define UI_GFX_POINT_H_ | 6 #define UI_GFX_POINT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 copy.Offset(other.x_, other.y_); | 59 copy.Offset(other.x_, other.y_); |
60 return copy; | 60 return copy; |
61 } | 61 } |
62 | 62 |
63 Point Subtract(const Point& other) const { | 63 Point Subtract(const Point& other) const { |
64 Point copy = *this; | 64 Point copy = *this; |
65 copy.Offset(-other.x_, -other.y_); | 65 copy.Offset(-other.x_, -other.y_); |
66 return copy; | 66 return copy; |
67 } | 67 } |
68 | 68 |
| 69 Point Middle(const Point& other) const { |
| 70 return Point((x_ + other.x_) / 2, (y_ + other.y_) / 2); |
| 71 } |
| 72 |
69 bool operator==(const Point& rhs) const { | 73 bool operator==(const Point& rhs) const { |
70 return x_ == rhs.x_ && y_ == rhs.y_; | 74 return x_ == rhs.x_ && y_ == rhs.y_; |
71 } | 75 } |
72 | 76 |
73 bool operator!=(const Point& rhs) const { | 77 bool operator!=(const Point& rhs) const { |
74 return !(*this == rhs); | 78 return !(*this == rhs); |
75 } | 79 } |
76 | 80 |
77 // A point is less than another point if its y-value is closer | 81 // A point is less than another point if its y-value is closer |
78 // to the origin. If the y-values are the same, then point with | 82 // to the origin. If the y-values are the same, then point with |
(...skipping 15 matching lines...) Expand all Loading... |
94 std::string ToString() const; | 98 std::string ToString() const; |
95 | 99 |
96 private: | 100 private: |
97 int x_; | 101 int x_; |
98 int y_; | 102 int y_; |
99 }; | 103 }; |
100 | 104 |
101 } // namespace gfx | 105 } // namespace gfx |
102 | 106 |
103 #endif // UI_GFX_POINT_H_ | 107 #endif // UI_GFX_POINT_H_ |
OLD | NEW |