OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 GFX_POINT_H_ | 5 #ifndef GFX_POINT_H_ |
6 #define GFX_POINT_H_ | 6 #define GFX_POINT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 bool operator==(const Point& rhs) const { | 68 bool operator==(const Point& rhs) const { |
69 return x_ == rhs.x_ && y_ == rhs.y_; | 69 return x_ == rhs.x_ && y_ == rhs.y_; |
70 } | 70 } |
71 | 71 |
72 bool operator!=(const Point& rhs) const { | 72 bool operator!=(const Point& rhs) const { |
73 return !(*this == rhs); | 73 return !(*this == rhs); |
74 } | 74 } |
75 | 75 |
| 76 // A point is less than another point if its y-value is closer |
| 77 // to the origin. If the y-values are the same, then point with |
| 78 // the x-value closer to the origin is considered less than the |
| 79 // other. |
| 80 // This comparison is required to use Points in sets, or sorted |
| 81 // vectors. |
| 82 bool operator<(const Point& rhs) const { |
| 83 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); |
| 84 } |
| 85 |
76 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
77 POINT ToPOINT() const; | 87 POINT ToPOINT() const; |
78 #elif defined(OS_MACOSX) | 88 #elif defined(OS_MACOSX) |
79 CGPoint ToCGPoint() const; | 89 CGPoint ToCGPoint() const; |
80 #endif | 90 #endif |
81 | 91 |
82 private: | 92 private: |
83 int x_; | 93 int x_; |
84 int y_; | 94 int y_; |
85 }; | 95 }; |
86 | 96 |
87 } // namespace gfx | 97 } // namespace gfx |
88 | 98 |
89 std::ostream& operator<<(std::ostream& out, const gfx::Point& p); | 99 std::ostream& operator<<(std::ostream& out, const gfx::Point& p); |
90 | 100 |
91 #endif // GFX_POINT_H_ | 101 #endif // GFX_POINT_H_ |
OLD | NEW |