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

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

Issue 2051343002: Make various gfx classes more amenable to use as compile-time constants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Delete destructor Created 4 years, 6 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 | « no previous file | ui/gfx/geometry/insets.h » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_BOX_F_H_ 5 #ifndef UI_GFX_GEOMETRY_BOX_F_H_
6 #define UI_GFX_GEOMETRY_BOX_F_H_ 6 #define UI_GFX_GEOMETRY_BOX_F_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 10
11 #include "ui/gfx/geometry/point3_f.h" 11 #include "ui/gfx/geometry/point3_f.h"
12 #include "ui/gfx/geometry/vector3d_f.h" 12 #include "ui/gfx/geometry/vector3d_f.h"
13 13
14 namespace gfx { 14 namespace gfx {
15 15
16 // A 3d version of gfx::RectF, with the positive z-axis pointed towards 16 // A 3d version of gfx::RectF, with the positive z-axis pointed towards
17 // the camera. 17 // the camera.
18 class GFX_EXPORT BoxF { 18 class GFX_EXPORT BoxF {
19 public: 19 public:
20 BoxF() : BoxF(0, 0, 0) {} 20 constexpr BoxF() : BoxF(0, 0, 0) {}
21 BoxF(float width, float height, float depth) 21 constexpr BoxF(float width, float height, float depth)
22 : BoxF(0, 0, 0, width, height, depth) {} 22 : BoxF(0, 0, 0, width, height, depth) {}
23 BoxF(float x, float y, float z, float width, float height, float depth) 23 constexpr BoxF(float x,
24 float y,
25 float z,
26 float width,
27 float height,
28 float depth)
24 : BoxF(Point3F(x, y, z), width, height, depth) {} 29 : BoxF(Point3F(x, y, z), width, height, depth) {}
25 BoxF(const Point3F& origin, float width, float height, float depth) 30 constexpr BoxF(const Point3F& origin, float width, float height, float depth)
26 : origin_(origin), 31 : origin_(origin),
27 width_(width >= 0 ? width : 0), 32 width_(width >= 0 ? width : 0),
28 height_(height >= 0 ? height : 0), 33 height_(height >= 0 ? height : 0),
29 depth_(depth >= 0 ? depth : 0) {} 34 depth_(depth >= 0 ? depth : 0) {}
30 35
31 ~BoxF() {}
32
33 // Scales all three axes by the given scale. 36 // Scales all three axes by the given scale.
34 void Scale(float scale) { 37 void Scale(float scale) {
35 Scale(scale, scale, scale); 38 Scale(scale, scale, scale);
36 } 39 }
37 40
38 // Scales each axis by the corresponding given scale. 41 // Scales each axis by the corresponding given scale.
39 void Scale(float x_scale, float y_scale, float z_scale) { 42 void Scale(float x_scale, float y_scale, float z_scale) {
40 origin_.Scale(x_scale, y_scale, z_scale); 43 origin_.Scale(x_scale, y_scale, z_scale);
41 set_size(width_ * x_scale, height_ * y_scale, depth_ * z_scale); 44 set_size(width_ * x_scale, height_ * y_scale, depth_ * z_scale);
42 } 45 }
43 46
44 // Moves the box by the specified distance in each dimension. 47 // Moves the box by the specified distance in each dimension.
45 void operator+=(const Vector3dF& offset) { 48 void operator+=(const Vector3dF& offset) {
46 origin_ += offset; 49 origin_ += offset;
47 } 50 }
48 51
49 // Returns true if the box has no interior points. 52 // Returns true if the box has no interior points.
50 bool IsEmpty() const; 53 bool IsEmpty() const;
51 54
52 // Computes the union of this box with the given box. The union is the 55 // Computes the union of this box with the given box. The union is the
53 // smallest box that contains both boxes. 56 // smallest box that contains both boxes.
54 void Union(const BoxF& box); 57 void Union(const BoxF& box);
55 58
56 std::string ToString() const; 59 std::string ToString() const;
57 60
58 float x() const { return origin_.x(); } 61 constexpr float x() const { return origin_.x(); }
59 void set_x(float x) { origin_.set_x(x); } 62 void set_x(float x) { origin_.set_x(x); }
60 63
61 float y() const { return origin_.y(); } 64 constexpr float y() const { return origin_.y(); }
62 void set_y(float y) { origin_.set_y(y); } 65 void set_y(float y) { origin_.set_y(y); }
63 66
64 float z() const { return origin_.z(); } 67 constexpr float z() const { return origin_.z(); }
65 void set_z(float z) { origin_.set_z(z); } 68 void set_z(float z) { origin_.set_z(z); }
66 69
67 float width() const { return width_; } 70 constexpr float width() const { return width_; }
68 void set_width(float width) { width_ = width < 0 ? 0 : width; } 71 void set_width(float width) { width_ = width < 0 ? 0 : width; }
69 72
70 float height() const { return height_; } 73 constexpr float height() const { return height_; }
71 void set_height(float height) { height_ = height < 0 ? 0 : height; } 74 void set_height(float height) { height_ = height < 0 ? 0 : height; }
72 75
73 float depth() const { return depth_; } 76 constexpr float depth() const { return depth_; }
74 void set_depth(float depth) { depth_ = depth < 0 ? 0 : depth; } 77 void set_depth(float depth) { depth_ = depth < 0 ? 0 : depth; }
75 78
76 float right() const { return x() + width(); } 79 constexpr float right() const { return x() + width(); }
77 float bottom() const { return y() + height(); } 80 constexpr float bottom() const { return y() + height(); }
78 float front() const { return z() + depth(); } 81 constexpr float front() const { return z() + depth(); }
79 82
80 void set_size(float width, float height, float depth) { 83 void set_size(float width, float height, float depth) {
81 width_ = width < 0 ? 0 : width; 84 width_ = width < 0 ? 0 : width;
82 height_ = height < 0 ? 0 : height; 85 height_ = height < 0 ? 0 : height;
83 depth_ = depth < 0 ? 0 : depth; 86 depth_ = depth < 0 ? 0 : depth;
84 } 87 }
85 88
86 const Point3F& origin() const { return origin_; } 89 constexpr const Point3F& origin() const { return origin_; }
87 void set_origin(const Point3F& origin) { origin_ = origin; } 90 void set_origin(const Point3F& origin) { origin_ = origin; }
88 91
89 // Expands |this| to contain the given point, if necessary. Please note, even 92 // Expands |this| to contain the given point, if necessary. Please note, even
90 // if |this| is empty, after the function |this| will continue to contain its 93 // if |this| is empty, after the function |this| will continue to contain its
91 // |origin_|. 94 // |origin_|.
92 void ExpandTo(const Point3F& point); 95 void ExpandTo(const Point3F& point);
93 96
94 // Expands |this| to contain the given box, if necessary. Please note, even 97 // Expands |this| to contain the given box, if necessary. Please note, even
95 // if |this| is empty, after the function |this| will continue to contain its 98 // if |this| is empty, after the function |this| will continue to contain its
96 // |origin_|. 99 // |origin_|.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 151 }
149 152
150 // This is declared here for use in gtest-based unit tests but is defined in 153 // This is declared here for use in gtest-based unit tests but is defined in
151 // the gfx_test_support target. Depend on that to use this in your unit test. 154 // the gfx_test_support target. Depend on that to use this in your unit test.
152 // This should not be used in production code - call ToString() instead. 155 // This should not be used in production code - call ToString() instead.
153 void PrintTo(const BoxF& box, ::std::ostream* os); 156 void PrintTo(const BoxF& box, ::std::ostream* os);
154 157
155 } // namespace gfx 158 } // namespace gfx
156 159
157 #endif // UI_GFX_GEOMETRY_BOX_F_H_ 160 #endif // UI_GFX_GEOMETRY_BOX_F_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/geometry/insets.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698