Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: ui/gfx/geometry/size_f.h

Issue 2749513011: Stabilize empty rect handling in EnclosingRect. (Closed)
Patch Set: Nits Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/geometry/rect_unittest.cc ('k') | ui/gfx/geometry/size_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0757ef6481a7d53e878c96bdb6168437355e83d7 100644
--- a/ui/gfx/geometry/size_f.h
+++ b/ui/gfx/geometry/size_f.h
@@ -9,17 +9,22 @@
#include <string>
#include "base/compiler_specific.h"
+#include "base/gtest_prod_util.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/gfx_export.h"
namespace gfx {
+FORWARD_DECLARE_TEST(SizeTest, TrivialDimensionTests);
+FORWARD_DECLARE_TEST(SizeTest, ClampsToZero);
+FORWARD_DECLARE_TEST(SizeTest, ConsistentClamping);
+
// 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_(clamp(width)), height_(clamp(height)) {}
constexpr explicit SizeF(const Size& size)
: SizeF(static_cast<float>(size.width()),
@@ -28,8 +33,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;
@@ -56,6 +61,14 @@ class GFX_EXPORT SizeF {
std::string ToString() const;
private:
+ FRIEND_TEST_ALL_PREFIXES(SizeTest, TrivialDimensionTests);
+ FRIEND_TEST_ALL_PREFIXES(SizeTest, ClampsToZero);
+ FRIEND_TEST_ALL_PREFIXES(SizeTest, ConsistentClamping);
+
+ static constexpr float kTrivial = 8.f * std::numeric_limits<float>::epsilon();
+
+ static constexpr float clamp(float f) { return f > kTrivial ? f : 0.f; }
+
float width_;
float height_;
};
« no previous file with comments | « ui/gfx/geometry/rect_unittest.cc ('k') | ui/gfx/geometry/size_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698