| OLD | NEW |
| 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_SIZE_F_H_ | 5 #ifndef UI_GFX_GEOMETRY_SIZE_F_H_ |
| 6 #define UI_GFX_GEOMETRY_SIZE_F_H_ | 6 #define UI_GFX_GEOMETRY_SIZE_F_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/gfx/gfx_export.h" | 13 #include "ui/gfx/gfx_export.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 | 16 |
| 17 static constexpr float kTrivial = 8.f * std::numeric_limits<float>::epsilon(); |
| 18 |
| 17 // A floating version of gfx::Size. | 19 // A floating version of gfx::Size. |
| 18 class GFX_EXPORT SizeF { | 20 class GFX_EXPORT SizeF { |
| 19 public: | 21 public: |
| 20 constexpr SizeF() : width_(0.f), height_(0.f) {} | 22 constexpr SizeF() : width_(0.f), height_(0.f) {} |
| 21 constexpr SizeF(float width, float height) | 23 constexpr SizeF(float width, float height) |
| 22 : width_(width >= 0 ? width : 0), height_(height >= 0 ? height : 0) {} | 24 : width_(width > kTrivial ? width : 0.f), |
| 25 height_(height > kTrivial ? height : 0.f) {} |
| 23 | 26 |
| 24 constexpr explicit SizeF(const Size& size) | 27 constexpr explicit SizeF(const Size& size) |
| 25 : SizeF(static_cast<float>(size.width()), | 28 : SizeF(static_cast<float>(size.width()), |
| 26 static_cast<float>(size.height())) {} | 29 static_cast<float>(size.height())) {} |
| 27 | 30 |
| 28 constexpr float width() const { return width_; } | 31 constexpr float width() const { return width_; } |
| 29 constexpr float height() const { return height_; } | 32 constexpr float height() const { return height_; } |
| 30 | 33 |
| 31 void set_width(float width) { width_ = fmaxf(0, width); } | 34 void set_width(float width) { width_ = width > kTrivial ? width : 0.f; } |
| 32 void set_height(float height) { height_ = fmaxf(0, height); } | 35 void set_height(float height) { height_ = height > kTrivial ? height : 0.f; } |
| 33 | 36 |
| 34 float GetArea() const; | 37 float GetArea() const; |
| 35 | 38 |
| 36 void SetSize(float width, float height) { | 39 void SetSize(float width, float height) { |
| 37 set_width(width); | 40 set_width(width); |
| 38 set_height(height); | 41 set_height(height); |
| 39 } | 42 } |
| 40 | 43 |
| 41 void Enlarge(float grow_width, float grow_height); | 44 void Enlarge(float grow_width, float grow_height); |
| 42 | 45 |
| 43 void SetToMin(const SizeF& other); | 46 void SetToMin(const SizeF& other); |
| 44 void SetToMax(const SizeF& other); | 47 void SetToMax(const SizeF& other); |
| 45 | 48 |
| 46 bool IsEmpty() const { return !width() || !height(); } | 49 bool IsEmpty() const { return !height_ || !width_; } |
| 47 | 50 |
| 48 void Scale(float scale) { | 51 void Scale(float scale) { |
| 49 Scale(scale, scale); | 52 Scale(scale, scale); |
| 50 } | 53 } |
| 51 | 54 |
| 52 void Scale(float x_scale, float y_scale) { | 55 void Scale(float x_scale, float y_scale) { |
| 53 SetSize(width() * x_scale, height() * y_scale); | 56 SetSize(width() * x_scale, height() * y_scale); |
| 54 } | 57 } |
| 55 | 58 |
| 56 std::string ToString() const; | 59 std::string ToString() const; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 75 } | 78 } |
| 76 | 79 |
| 77 // This is declared here for use in gtest-based unit tests but is defined in | 80 // This is declared here for use in gtest-based unit tests but is defined in |
| 78 // the //ui/gfx:test_support target. Depend on that to use this in your unit | 81 // the //ui/gfx:test_support target. Depend on that to use this in your unit |
| 79 // test. This should not be used in production code - call ToString() instead. | 82 // test. This should not be used in production code - call ToString() instead. |
| 80 void PrintTo(const SizeF& size, ::std::ostream* os); | 83 void PrintTo(const SizeF& size, ::std::ostream* os); |
| 81 | 84 |
| 82 } // namespace gfx | 85 } // namespace gfx |
| 83 | 86 |
| 84 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ | 87 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ |
| OLD | NEW |