Chromium Code Reviews| 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 ? 0 : width), height_(height < 0 ? 0 : height) {} |
|
Peter Kasting
2016/06/10 00:19:19
This behavior will only differ when one of the pro
danakj
2016/06/10 00:36:48
Hm. https://bugs.chromium.org/p/chromium/issues/de
Peter Kasting
2016/06/10 05:50:06
Is there somewhere that covers how to do this/what
Peter Kasting
2016/06/10 07:03:18
...except on MSVC.
F___.
OK, going back to my ot
| |
| 24 ~SizeF() {} | |
| 25 | 24 |
| 26 explicit SizeF(const Size& size) | 25 constexpr explicit SizeF(const Size& size) |
| 27 : SizeF(static_cast<float>(size.width()), | 26 : SizeF(static_cast<float>(size.width()), |
| 28 static_cast<float>(size.height())) {} | 27 static_cast<float>(size.height())) {} |
| 29 | 28 |
| 30 float width() const { return width_; } | 29 constexpr float width() const { return width_; } |
| 31 float height() const { return height_; } | 30 constexpr float height() const { return height_; } |
| 32 | 31 |
| 33 void set_width(float width) { width_ = fmaxf(0, width); } | 32 void set_width(float width) { width_ = fmaxf(0, width); } |
| 34 void set_height(float height) { height_ = fmaxf(0, height); } | 33 void set_height(float height) { height_ = fmaxf(0, height); } |
| 35 | 34 |
| 36 float GetArea() const; | 35 float GetArea() const; |
| 37 | 36 |
| 38 void SetSize(float width, float height) { | 37 void SetSize(float width, float height) { |
| 39 set_width(width); | 38 set_width(width); |
| 40 set_height(height); | 39 set_height(height); |
| 41 } | 40 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 } | 76 } |
| 78 | 77 |
| 79 // This is declared here for use in gtest-based unit tests but is defined in | 78 // 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. | 79 // 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. | 80 // This should not be used in production code - call ToString() instead. |
| 82 void PrintTo(const SizeF& size, ::std::ostream* os); | 81 void PrintTo(const SizeF& size, ::std::ostream* os); |
| 83 | 82 |
| 84 } // namespace gfx | 83 } // namespace gfx |
| 85 | 84 |
| 86 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ | 85 #endif // UI_GFX_GEOMETRY_SIZE_F_H_ |
| OLD | NEW |