Index: ui/gfx/geometry/size_f.h |
diff --git a/ui/gfx/geometry/size_f.h b/ui/gfx/geometry/size_f.h |
index 9d1bb5d7e3ed6c18d4ff3d3193a510ae85c70c48..1009ac47df61420c6ebd298bf0c016d153bfc241 100644 |
--- a/ui/gfx/geometry/size_f.h |
+++ b/ui/gfx/geometry/size_f.h |
@@ -14,12 +14,15 @@ |
namespace gfx { |
+static constexpr float kTrivial = 8.f * std::numeric_limits<float>::epsilon(); |
+ |
// A floating version of gfx::Size. |
class GFX_EXPORT SizeF { |
public: |
constexpr SizeF() : width_(0.f), height_(0.f) {} |
constexpr SizeF(float width, float height) |
- : width_(width >= 0 ? width : 0), height_(height >= 0 ? height : 0) {} |
+ : width_(width >= kTrivial ? width : 0.f), |
+ height_(height >= kTrivial ? height : 0.f) {} |
constexpr explicit SizeF(const Size& size) |
: SizeF(static_cast<float>(size.width()), |
@@ -28,8 +31,8 @@ class GFX_EXPORT SizeF { |
constexpr float width() const { return width_; } |
constexpr float height() const { return height_; } |
- void set_width(float width) { width_ = fmaxf(0, width); } |
- void set_height(float height) { height_ = fmaxf(0, height); } |
+ void set_width(float width) { width_ = width >= kTrivial ? width : 0.f; } |
+ void set_height(float height) { height_ = height >= kTrivial ? height : 0.f; } |
float GetArea() const; |
@@ -43,7 +46,9 @@ class GFX_EXPORT SizeF { |
void SetToMin(const SizeF& other); |
void SetToMax(const SizeF& other); |
- bool IsEmpty() const { return !width() || !height(); } |
+ bool HasHeight() const { return height() > kTrivial; } |
danakj
2017/03/21 16:16:36
How would height be < kTrivial? This is now just c
Peter Mayo
2017/03/21 16:45:57
The best thing about these is that they make it cl
danakj
2017/03/21 17:42:05
I think I'm okay with clamping at the setters. But
Peter Mayo
2017/03/23 19:29:22
Dana Wrote:
Peter Mayo
2017/03/23 19:29:22
I think the decision as to whether HasHeight() is
|
+ bool HasWidth() const { return width() > kTrivial; } |
+ bool IsEmpty() const { return !HasHeight() || !HasWidth(); } |
void Scale(float scale) { |
Scale(scale, scale); |