Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(845)

Side by Side Diff: ui/gfx/geometry/point_f.h

Issue 642343003: gfx: De-templatize the gfx::Point and gfx::PointF classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: inlines-point: rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/point_base.h ('k') | ui/gfx/geometry/point_f.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
11 #include "ui/gfx/geometry/point_base.h"
12 #include "ui/gfx/geometry/vector2d_f.h" 11 #include "ui/gfx/geometry/vector2d_f.h"
13 #include "ui/gfx/gfx_export.h" 12 #include "ui/gfx/gfx_export.h"
14 13
15 namespace gfx { 14 namespace gfx {
16 15
17 // A floating version of gfx::Point. 16 // A floating version of gfx::Point.
18 class GFX_EXPORT PointF : public PointBase<PointF, float, Vector2dF> { 17 class GFX_EXPORT PointF {
19 public: 18 public:
20 PointF() : PointBase<PointF, float, Vector2dF>(0, 0) {} 19 PointF() : x_(0.f), y_(0.f) {}
21 PointF(float x, float y) : PointBase<PointF, float, Vector2dF>(x, y) {} 20 PointF(float x, float y) : x_(x), y_(y) {}
22 ~PointF() {} 21 ~PointF() {}
23 22
23 float x() const { return x_; }
24 float y() const { return y_; }
25 void set_x(float x) { x_ = x; }
26 void set_y(float y) { y_ = y; }
27
28 void SetPoint(float x, float y) {
29 x_ = x;
30 y_ = y;
31 }
32
33 void Offset(float delta_x, float delta_y) {
34 x_ += delta_x;
35 y_ += delta_y;
36 }
37
38 void operator+=(const Vector2dF& vector) {
39 x_ += vector.x();
40 y_ += vector.y();
41 }
42
43 void operator-=(const Vector2dF& vector) {
44 x_ -= vector.x();
45 y_ -= vector.y();
46 }
47
48 void SetToMin(const PointF& other);
49 void SetToMax(const PointF& other);
50
51 bool IsOrigin() const { return x_ == 0 && y_ == 0; }
52
53 Vector2dF OffsetFromOrigin() const { return Vector2dF(x_, y_); }
54
55 // A point is less than another point if its y-value is closer
56 // to the origin. If the y-values are the same, then point with
57 // the x-value closer to the origin is considered less than the
58 // other.
59 // This comparison is required to use PointF in sets, or sorted
60 // vectors.
61 bool operator<(const PointF& rhs) const {
62 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
63 }
64
24 void Scale(float scale) { 65 void Scale(float scale) {
25 Scale(scale, scale); 66 Scale(scale, scale);
26 } 67 }
27 68
28 void Scale(float x_scale, float y_scale) { 69 void Scale(float x_scale, float y_scale) {
29 SetPoint(x() * x_scale, y() * y_scale); 70 SetPoint(x() * x_scale, y() * y_scale);
30 } 71 }
31 72
32 // Returns a string representation of point. 73 // Returns a string representation of point.
33 std::string ToString() const; 74 std::string ToString() const;
75
76 private:
77 float x_;
78 float y_;
34 }; 79 };
35 80
36 inline bool operator==(const PointF& lhs, const PointF& rhs) { 81 inline bool operator==(const PointF& lhs, const PointF& rhs) {
37 return lhs.x() == rhs.x() && lhs.y() == rhs.y(); 82 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
38 } 83 }
39 84
40 inline bool operator!=(const PointF& lhs, const PointF& rhs) { 85 inline bool operator!=(const PointF& lhs, const PointF& rhs) {
41 return !(lhs == rhs); 86 return !(lhs == rhs);
42 } 87 }
43 88
(...skipping 16 matching lines...) Expand all
60 inline PointF PointAtOffsetFromOrigin(const Vector2dF& offset_from_origin) { 105 inline PointF PointAtOffsetFromOrigin(const Vector2dF& offset_from_origin) {
61 return PointF(offset_from_origin.x(), offset_from_origin.y()); 106 return PointF(offset_from_origin.x(), offset_from_origin.y());
62 } 107 }
63 108
64 GFX_EXPORT PointF ScalePoint(const PointF& p, float x_scale, float y_scale); 109 GFX_EXPORT PointF ScalePoint(const PointF& p, float x_scale, float y_scale);
65 110
66 inline PointF ScalePoint(const PointF& p, float scale) { 111 inline PointF ScalePoint(const PointF& p, float scale) {
67 return ScalePoint(p, scale, scale); 112 return ScalePoint(p, scale, scale);
68 } 113 }
69 114
70 #if !defined(COMPILER_MSVC) && !defined(__native_client__)
71 extern template class PointBase<PointF, float, Vector2dF>;
72 #endif
73
74 // This is declared here for use in gtest-based unit tests but is defined in 115 // This is declared here for use in gtest-based unit tests but is defined in
75 // the gfx_test_support target. Depend on that to use this in your unit test. 116 // the gfx_test_support target. Depend on that to use this in your unit test.
76 // This should not be used in production code - call ToString() instead. 117 // This should not be used in production code - call ToString() instead.
77 void PrintTo(const PointF& point, ::std::ostream* os); 118 void PrintTo(const PointF& point, ::std::ostream* os);
78 119
79 } // namespace gfx 120 } // namespace gfx
80 121
81 #endif // UI_GFX_GEOMETRY_POINT_F_H_ 122 #endif // UI_GFX_GEOMETRY_POINT_F_H_
OLDNEW
« no previous file with comments | « ui/gfx/geometry/point_base.h ('k') | ui/gfx/geometry/point_f.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698