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

Side by Side Diff: ui/gfx/point_base.h

Issue 11293194: ui: Prefer +/- operators to apply offsets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gfx:: Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/point.h ('k') | ui/gfx/point_f.h » ('j') | ui/gfx/rect.h » ('J')
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_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 10 matching lines...) Expand all
21 Type y() const { return y_; } 21 Type y() const { return y_; }
22 22
23 void SetPoint(Type x, Type y) { 23 void SetPoint(Type x, Type y) {
24 x_ = x; 24 x_ = x;
25 y_ = y; 25 y_ = y;
26 } 26 }
27 27
28 void set_x(Type x) { x_ = x; } 28 void set_x(Type x) { x_ = x; }
29 void set_y(Type y) { y_ = y; } 29 void set_y(Type y) { y_ = y; }
30 30
31 void Offset(Type delta_x, Type delta_y) { 31 void Offset(Type delta_x, Type delta_y) {
Peter Kasting 2012/11/09 22:02:36 Are we planning on nuking this in favor of the ope
danakj 2012/11/09 22:10:10 At first I was thinking yes definitely. But in my
32 x_ += delta_x; 32 x_ += delta_x;
33 y_ += delta_y; 33 y_ += delta_y;
34 } 34 }
35 35
36 void operator+=(const VectorClass& vector) { 36 void operator+=(const VectorClass& vector) {
37 Offset(vector.x(), vector.y()); 37 x_ += vector.x();
38 y_ += vector.y();
Peter Kasting 2012/11/09 22:02:36 I don't know whether these changes are much of a w
danakj 2012/11/09 22:10:10 Yeh, not super amazing, I agree. Basically, this
38 } 39 }
39 40
40 void operator-=(const VectorClass& vector) { 41 void operator-=(const VectorClass& vector) {
41 Offset(-vector.x(), -vector.y()); 42 x_ -= vector.x();
43 y_ -= vector.y();
42 } 44 }
43 45
44 bool IsOrigin() const { 46 bool IsOrigin() const {
45 return x_ == 0 && y_ == 0; 47 return x_ == 0 && y_ == 0;
46 } 48 }
47 49
48 VectorClass OffsetFromOrigin() const { 50 VectorClass OffsetFromOrigin() const {
49 return VectorClass(x_, y_); 51 return VectorClass(x_, y_);
50 } 52 }
51 53
52 VectorClass OffsetFrom(const Class& other) const {
53 return VectorClass(x_ - other.x_, y_ - other.y_);
54 }
55
56 // 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
57 // 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
58 // 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
59 // other. 57 // other.
60 // This comparison is required to use Point in sets, or sorted 58 // This comparison is required to use Point in sets, or sorted
61 // vectors. 59 // vectors.
62 bool operator<(const Class& rhs) const { 60 bool operator<(const Class& rhs) const {
63 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_); 61 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
64 } 62 }
65 63
66 protected: 64 protected:
67 PointBase(Type x, Type y) : x_(x), y_(y) {} 65 PointBase(Type x, Type y) : x_(x), y_(y) {}
68 // Destructor is intentionally made non virtual and protected. 66 // Destructor is intentionally made non virtual and protected.
69 // Do not make this public. 67 // Do not make this public.
70 ~PointBase() {} 68 ~PointBase() {}
71 69
72 private: 70 private:
73 Type x_; 71 Type x_;
74 Type y_; 72 Type y_;
75 }; 73 };
76 74
77 } // namespace gfx 75 } // namespace gfx
78 76
79 #endif // UI_GFX_POINT_BASE_H_ 77 #endif // UI_GFX_POINT_BASE_H_
OLDNEW
« no previous file with comments | « ui/gfx/point.h ('k') | ui/gfx/point_f.h » ('j') | ui/gfx/rect.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698