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..2283163c8ae91a7fcfb32a500545dc923b256535 100644 |
--- a/ui/gfx/geometry/size_f.h |
+++ b/ui/gfx/geometry/size_f.h |
@@ -19,7 +19,7 @@ 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_(clamp(width)), height_(clamp(height)) {} |
constexpr explicit SizeF(const Size& size) |
: SizeF(static_cast<float>(size.width()), |
@@ -28,8 +28,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_ = clamp(width); } |
+ void set_height(float height) { height_ = clamp(height); } |
float GetArea() const; |
@@ -43,7 +43,7 @@ class GFX_EXPORT SizeF { |
void SetToMin(const SizeF& other); |
void SetToMax(const SizeF& other); |
- bool IsEmpty() const { return !width() || !height(); } |
+ bool IsEmpty() const { return !height_ || !width_; } |
void Scale(float scale) { |
Scale(scale, scale); |
@@ -58,6 +58,9 @@ class GFX_EXPORT SizeF { |
private: |
float width_; |
float height_; |
+ static constexpr float kTrivial = 8.f * std::numeric_limits<float>::epsilon(); |
+ static constexpr float clamp(float f) { return f > kTrivial ? f : 0.f; } |
+ friend float SizeFPrivateMatch(); // Test access to the kTrivial constant. |
danakj
2017/03/28 18:00:20
make friends the first thing in the private block
Peter Mayo
2017/03/28 20:11:21
Done.
|
}; |
inline bool operator==(const SizeF& lhs, const SizeF& rhs) { |