Chromium Code Reviews| OLD | NEW |
|---|---|
| 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() | 20 constexpr BoxF() |
| 21 : width_(0.f), | 21 : width_(0.f), |
| 22 height_(0.f), | 22 height_(0.f), |
| 23 depth_(0.f) {} | 23 depth_(0.f) {} |
| 24 | 24 |
| 25 BoxF(float width, float height, float depth) | 25 constexpr BoxF(float width, float height, float depth) |
| 26 : width_(width < 0 ? 0 : width), | 26 : width_(width < 0 ? 0 : width), |
| 27 height_(height < 0 ? 0 : height), | 27 height_(height < 0 ? 0 : height), |
| 28 depth_(depth < 0 ? 0 : depth) {} | 28 depth_(depth < 0 ? 0 : depth) {} |
| 29 | 29 |
| 30 BoxF(float x, float y, float z, float width, float height, float depth) | 30 constexpr BoxF(float x, |
| 31 float y, | |
| 32 float z, | |
| 33 float width, | |
| 34 float height, | |
| 35 float depth) | |
| 31 : origin_(x, y, z), | 36 : origin_(x, y, z), |
| 32 width_(width < 0 ? 0 : width), | 37 width_(width < 0 ? 0 : width), |
| 33 height_(height < 0 ? 0 : height), | 38 height_(height < 0 ? 0 : height), |
| 34 depth_(depth < 0 ? 0 : depth) {} | 39 depth_(depth < 0 ? 0 : depth) {} |
| 35 | 40 |
| 36 BoxF(const Point3F& origin, float width, float height, float depth) | 41 constexpr BoxF(const Point3F& origin, float width, float height, float depth) |
| 37 : origin_(origin), | 42 : origin_(origin), |
| 38 width_(width < 0 ? 0 : width), | 43 width_(width < 0 ? 0 : width), |
| 39 height_(height < 0 ? 0 : height), | 44 height_(height < 0 ? 0 : height), |
| 40 depth_(depth < 0 ? 0 : depth) {} | 45 depth_(depth < 0 ? 0 : depth) {} |
| 41 | 46 |
| 42 ~BoxF() {} | |
| 43 | |
| 44 // Scales all three axes by the given scale. | 47 // Scales all three axes by the given scale. |
| 45 void Scale(float scale) { | 48 void Scale(float scale) { |
| 46 Scale(scale, scale, scale); | 49 Scale(scale, scale, scale); |
| 47 } | 50 } |
| 48 | 51 |
| 49 // Scales each axis by the corresponding given scale. | 52 // Scales each axis by the corresponding given scale. |
| 50 void Scale(float x_scale, float y_scale, float z_scale) { | 53 void Scale(float x_scale, float y_scale, float z_scale) { |
| 51 origin_.Scale(x_scale, y_scale, z_scale); | 54 origin_.Scale(x_scale, y_scale, z_scale); |
| 52 set_size(width_ * x_scale, height_ * y_scale, depth_ * z_scale); | 55 set_size(width_ * x_scale, height_ * y_scale, depth_ * z_scale); |
| 53 } | 56 } |
| 54 | 57 |
| 55 // Moves the box by the specified distance in each dimension. | 58 // Moves the box by the specified distance in each dimension. |
| 56 void operator+=(const Vector3dF& offset) { | 59 void operator+=(const Vector3dF& offset) { |
| 57 origin_ += offset; | 60 origin_ += offset; |
| 58 } | 61 } |
| 59 | 62 |
| 60 // Returns true if the box has no interior points. | 63 // Returns true if the box has no interior points. |
| 61 bool IsEmpty() const; | 64 bool IsEmpty() const; |
| 62 | 65 |
| 63 // Computes the union of this box with the given box. The union is the | 66 // Computes the union of this box with the given box. The union is the |
| 64 // smallest box that contains both boxes. | 67 // smallest box that contains both boxes. |
| 65 void Union(const BoxF& box); | 68 void Union(const BoxF& box); |
| 66 | 69 |
| 67 std::string ToString() const; | 70 std::string ToString() const; |
| 68 | 71 |
| 69 float x() const { return origin_.x(); } | 72 constexpr float x() const { return origin_.x(); } |
|
danakj
2016/06/10 00:36:47
is this constexpr and const not redundant? Why is
vmpstr
2016/06/10 00:46:15
I think in C++14, non-static constexpr member func
Peter Kasting
2016/06/10 05:50:06
No, they're not redundant. Originally, constexpr
| |
| 70 void set_x(float x) { origin_.set_x(x); } | 73 void set_x(float x) { origin_.set_x(x); } |
| 71 | 74 |
| 72 float y() const { return origin_.y(); } | 75 constexpr float y() const { return origin_.y(); } |
| 73 void set_y(float y) { origin_.set_y(y); } | 76 void set_y(float y) { origin_.set_y(y); } |
| 74 | 77 |
| 75 float z() const { return origin_.z(); } | 78 constexpr float z() const { return origin_.z(); } |
| 76 void set_z(float z) { origin_.set_z(z); } | 79 void set_z(float z) { origin_.set_z(z); } |
| 77 | 80 |
| 78 float width() const { return width_; } | 81 constexpr float width() const { return width_; } |
| 79 void set_width(float width) { width_ = width < 0 ? 0 : width; } | 82 void set_width(float width) { width_ = width < 0 ? 0 : width; } |
| 80 | 83 |
| 81 float height() const { return height_; } | 84 constexpr float height() const { return height_; } |
| 82 void set_height(float height) { height_ = height < 0 ? 0 : height; } | 85 void set_height(float height) { height_ = height < 0 ? 0 : height; } |
| 83 | 86 |
| 84 float depth() const { return depth_; } | 87 constexpr float depth() const { return depth_; } |
| 85 void set_depth(float depth) { depth_ = depth < 0 ? 0 : depth; } | 88 void set_depth(float depth) { depth_ = depth < 0 ? 0 : depth; } |
| 86 | 89 |
| 87 float right() const { return x() + width(); } | 90 constexpr float right() const { return x() + width(); } |
| 88 float bottom() const { return y() + height(); } | 91 constexpr float bottom() const { return y() + height(); } |
| 89 float front() const { return z() + depth(); } | 92 constexpr float front() const { return z() + depth(); } |
| 90 | 93 |
| 91 void set_size(float width, float height, float depth) { | 94 void set_size(float width, float height, float depth) { |
| 92 width_ = width < 0 ? 0 : width; | 95 width_ = width < 0 ? 0 : width; |
| 93 height_ = height < 0 ? 0 : height; | 96 height_ = height < 0 ? 0 : height; |
| 94 depth_ = depth < 0 ? 0 : depth; | 97 depth_ = depth < 0 ? 0 : depth; |
| 95 } | 98 } |
| 96 | 99 |
| 97 const Point3F& origin() const { return origin_; } | 100 constexpr const Point3F& origin() const { return origin_; } |
| 98 void set_origin(const Point3F& origin) { origin_ = origin; } | 101 void set_origin(const Point3F& origin) { origin_ = origin; } |
| 99 | 102 |
| 100 // Expands |this| to contain the given point, if necessary. Please note, even | 103 // Expands |this| to contain the given point, if necessary. Please note, even |
| 101 // if |this| is empty, after the function |this| will continue to contain its | 104 // if |this| is empty, after the function |this| will continue to contain its |
| 102 // |origin_|. | 105 // |origin_|. |
| 103 void ExpandTo(const Point3F& point); | 106 void ExpandTo(const Point3F& point); |
| 104 | 107 |
| 105 // Expands |this| to contain the given box, if necessary. Please note, even | 108 // Expands |this| to contain the given box, if necessary. Please note, even |
| 106 // if |this| is empty, after the function |this| will continue to contain its | 109 // if |this| is empty, after the function |this| will continue to contain its |
| 107 // |origin_|. | 110 // |origin_|. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 } | 162 } |
| 160 | 163 |
| 161 // This is declared here for use in gtest-based unit tests but is defined in | 164 // This is declared here for use in gtest-based unit tests but is defined in |
| 162 // the gfx_test_support target. Depend on that to use this in your unit test. | 165 // the gfx_test_support target. Depend on that to use this in your unit test. |
| 163 // This should not be used in production code - call ToString() instead. | 166 // This should not be used in production code - call ToString() instead. |
| 164 void PrintTo(const BoxF& box, ::std::ostream* os); | 167 void PrintTo(const BoxF& box, ::std::ostream* os); |
| 165 | 168 |
| 166 } // namespace gfx | 169 } // namespace gfx |
| 167 | 170 |
| 168 #endif // UI_GFX_GEOMETRY_BOX_F_H_ | 171 #endif // UI_GFX_GEOMETRY_BOX_F_H_ |
| OLD | NEW |