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_GEOMETRY_POINT_F_H_ | 5 #ifndef UI_GFX_GEOMETRY_POINT_F_H_ |
6 #define UI_GFX_GEOMETRY_POINT_F_H_ | 6 #define UI_GFX_GEOMETRY_POINT_F_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
| 10 #include <tuple> |
10 | 11 |
11 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
12 #include "ui/gfx/geometry/vector2d_f.h" | 13 #include "ui/gfx/geometry/vector2d_f.h" |
13 #include "ui/gfx/gfx_export.h" | 14 #include "ui/gfx/gfx_export.h" |
14 | 15 |
15 namespace gfx { | 16 namespace gfx { |
16 | 17 |
17 // A floating version of gfx::Point. | 18 // A floating version of gfx::Point. |
18 class GFX_EXPORT PointF { | 19 class GFX_EXPORT PointF { |
19 public: | 20 public: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 57 |
57 Vector2dF OffsetFromOrigin() const { return Vector2dF(x_, y_); } | 58 Vector2dF OffsetFromOrigin() const { return Vector2dF(x_, y_); } |
58 | 59 |
59 // A point is less than another point if its y-value is closer | 60 // A point is less than another point if its y-value is closer |
60 // to the origin. If the y-values are the same, then point with | 61 // to the origin. If the y-values are the same, then point with |
61 // the x-value closer to the origin is considered less than the | 62 // the x-value closer to the origin is considered less than the |
62 // other. | 63 // other. |
63 // This comparison is required to use PointF in sets, or sorted | 64 // This comparison is required to use PointF in sets, or sorted |
64 // vectors. | 65 // vectors. |
65 bool operator<(const PointF& rhs) const { | 66 bool operator<(const PointF& rhs) const { |
66 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); | 67 return std::tie(y_, x_) < std::tie(rhs.y_, rhs.x_); |
67 } | 68 } |
68 | 69 |
69 void Scale(float scale) { | 70 void Scale(float scale) { |
70 Scale(scale, scale); | 71 Scale(scale, scale); |
71 } | 72 } |
72 | 73 |
73 void Scale(float x_scale, float y_scale) { | 74 void Scale(float x_scale, float y_scale) { |
74 SetPoint(x() * x_scale, y() * y_scale); | 75 SetPoint(x() * x_scale, y() * y_scale); |
75 } | 76 } |
76 | 77 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 } | 118 } |
118 | 119 |
119 // This is declared here for use in gtest-based unit tests but is defined in | 120 // This is declared here for use in gtest-based unit tests but is defined in |
120 // the gfx_test_support target. Depend on that to use this in your unit test. | 121 // the gfx_test_support target. Depend on that to use this in your unit test. |
121 // This should not be used in production code - call ToString() instead. | 122 // This should not be used in production code - call ToString() instead. |
122 void PrintTo(const PointF& point, ::std::ostream* os); | 123 void PrintTo(const PointF& point, ::std::ostream* os); |
123 | 124 |
124 } // namespace gfx | 125 } // namespace gfx |
125 | 126 |
126 #endif // UI_GFX_GEOMETRY_POINT_F_H_ | 127 #endif // UI_GFX_GEOMETRY_POINT_F_H_ |
OLD | NEW |