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