| 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 <cmath> | 8 #include <cmath> |
| 9 #include <iosfwd> | 9 #include <iosfwd> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 14 #include "ui/gfx/gfx_export.h" | 14 #include "ui/gfx/gfx_export.h" |
| 15 | 15 |
| 16 namespace gfx { | 16 namespace gfx { |
| 17 | 17 |
| 18 // A floating version of gfx::Size. | 18 // A floating version of gfx::Size. |
| 19 class GFX_EXPORT SizeF { | 19 class GFX_EXPORT SizeF { |
| 20 public: | 20 public: |
| 21 SizeF() : width_(0.f), height_(0.f) {} | 21 constexpr SizeF() : width_(0.f), height_(0.f) {} |
| 22 SizeF(float width, float height) | 22 constexpr SizeF(float width, float height) |
| 23 : width_(fmaxf(0, width)), height_(fmaxf(0, height)) {} | 23 : width_((width < 0 || std::isnan(width)) ? 0 : width), |
| 24 ~SizeF() {} | 24 height_((height < 0 || std::isnan(height)) ? 0 : height) {} |
| 25 | 25 |
| 26 explicit SizeF(const Size& size) | 26 constexpr explicit SizeF(const Size& size) |
| 27 : SizeF(static_cast<float>(size.width()), | 27 : SizeF(static_cast<float>(size.width()), |
| 28 static_cast<float>(size.height())) {} | 28 static_cast<float>(size.height())) {} |
| 29 | 29 |
| 30 float width() const { return width_; } | 30 constexpr float width() const { return width_; } |
| 31 float height() const { return height_; } | 31 constexpr float height() const { return height_; } |
| 32 | 32 |
| 33 void set_width(float width) { width_ = fmaxf(0, width); } | 33 void set_width(float width) { width_ = fmaxf(0, width); } |
| 34 void set_height(float height) { height_ = fmaxf(0, height); } | 34 void set_height(float height) { height_ = fmaxf(0, height); } |
| 35 | 35 |
| 36 float GetArea() const; | 36 float GetArea() const; |
| 37 | 37 |
| 38 void SetSize(float width, float height) { | 38 void SetSize(float width, float height) { |
| 39 set_width(width); | 39 set_width(width); |
| 40 set_height(height); | 40 set_height(height); |
| 41 } | 41 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 // This is declared here for use in gtest-based unit tests but is defined in | 79 // This is declared here for use in gtest-based unit tests but is defined in |
| 80 // the gfx_test_support target. Depend on that to use this in your unit test. | 80 // the gfx_test_support target. Depend on that to use this in your unit test. |
| 81 // This should not be used in production code - call ToString() instead. | 81 // This should not be used in production code - call ToString() instead. |
| 82 void PrintTo(const SizeF& size, ::std::ostream* os); | 82 void PrintTo(const SizeF& size, ::std::ostream* os); |
| 83 | 83 |
| 84 } // namespace gfx | 84 } // namespace gfx |
| 85 | 85 |
| 86 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ | 86 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ |
| OLD | NEW |