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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 const Class* orig = static_cast<const Class*>(this); | 44 const Class* orig = static_cast<const Class*>(this); |
45 Class copy = *orig; | 45 Class copy = *orig; |
46 copy.Offset(-other.x_, -other.y_); | 46 copy.Offset(-other.x_, -other.y_); |
47 return copy; | 47 return copy; |
48 } | 48 } |
49 | 49 |
50 Class Middle(const Class& other) const WARN_UNUSED_RESULT { | 50 Class Middle(const Class& other) const WARN_UNUSED_RESULT { |
51 return Class((x_ + other.x_) / 2, (y_ + other.y_) / 2); | 51 return Class((x_ + other.x_) / 2, (y_ + other.y_) / 2); |
52 } | 52 } |
53 | 53 |
54 bool operator==(const Class& rhs) const { | |
55 return x_ == rhs.x_ && y_ == rhs.y_; | |
56 } | |
57 | |
58 bool operator!=(const Class& rhs) const { | |
59 return !(*this == rhs); | |
60 } | |
61 | |
62 // A point is less than another point if its y-value is closer | 54 // A point is less than another point if its y-value is closer |
63 // to the origin. If the y-values are the same, then point with | 55 // to the origin. If the y-values are the same, then point with |
64 // the x-value closer to the origin is considered less than the | 56 // the x-value closer to the origin is considered less than the |
65 // other. | 57 // other. |
66 // This comparison is required to use Point in sets, or sorted | 58 // This comparison is required to use Point in sets, or sorted |
67 // vectors. | 59 // vectors. |
68 bool operator<(const Class& rhs) const { | 60 bool operator<(const Class& rhs) const { |
69 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); | 61 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); |
70 } | 62 } |
71 | 63 |
72 protected: | 64 protected: |
73 PointBase(Type x, Type y) : x_(x), y_(y) {} | 65 PointBase(Type x, Type y) : x_(x), y_(y) {} |
74 // Destructor is intentionally made non virtual and protected. | 66 // Destructor is intentionally made non virtual and protected. |
75 // Do not make this public. | 67 // Do not make this public. |
76 ~PointBase() {} | 68 ~PointBase() {} |
77 | 69 |
78 private: | 70 private: |
79 Type x_; | 71 Type x_; |
80 Type y_; | 72 Type y_; |
81 }; | 73 }; |
82 | 74 |
83 } // namespace gfx | 75 } // namespace gfx |
84 | 76 |
85 #endif // UI_GFX_POINT_BASE_H_ | 77 #endif // UI_GFX_POINT_BASE_H_ |
OLD | NEW |