Loading libs/ui/include/ui/Rect.h +4 −6 Original line number Diff line number Diff line Loading @@ -74,12 +74,10 @@ public: } inline explicit Rect(const FloatRect& floatRect) { // Ideally we would use std::round, but we don't want to add an STL // dependency here, so we use an approximation left = static_cast<int32_t>(floatRect.left + 0.5f); top = static_cast<int32_t>(floatRect.top + 0.5f); right = static_cast<int32_t>(floatRect.right + 0.5f); bottom = static_cast<int32_t>(floatRect.bottom + 0.5f); left = static_cast<int32_t>(std::round(floatRect.left)); top = static_cast<int32_t>(std::round(floatRect.top)); right = static_cast<int32_t>(std::round(floatRect.right)); bottom = static_cast<int32_t>(std::round(floatRect.bottom)); } inline explicit Rect(const ui::Size& size) { Loading libs/ui/tests/Rect_test.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,16 @@ TEST(RectTest, constructFromFloatRect) { EXPECT_EQ(30, rect.right); EXPECT_EQ(40, rect.bottom); } EXPECT_EQ(Rect(0, 1, -1, 0), Rect(FloatRect(0.f, 1.f, -1.f, 0.f))); EXPECT_EQ(Rect(100000, 100000, -100000, -100000), Rect(FloatRect(100000.f, 100000.f, -100000.f, -100000.f))); // round down if < .5 EXPECT_EQ(Rect(0, 1, -1, 0), Rect(FloatRect(0.4f, 1.1f, -1.499f, 0.1f))); // round up if >= .5 EXPECT_EQ(Rect(20, 20, -20, -20), Rect(FloatRect(19.5f, 19.9f, -19.5f, -19.9f))); } TEST(RectTest, makeInvalid) { Loading Loading
libs/ui/include/ui/Rect.h +4 −6 Original line number Diff line number Diff line Loading @@ -74,12 +74,10 @@ public: } inline explicit Rect(const FloatRect& floatRect) { // Ideally we would use std::round, but we don't want to add an STL // dependency here, so we use an approximation left = static_cast<int32_t>(floatRect.left + 0.5f); top = static_cast<int32_t>(floatRect.top + 0.5f); right = static_cast<int32_t>(floatRect.right + 0.5f); bottom = static_cast<int32_t>(floatRect.bottom + 0.5f); left = static_cast<int32_t>(std::round(floatRect.left)); top = static_cast<int32_t>(std::round(floatRect.top)); right = static_cast<int32_t>(std::round(floatRect.right)); bottom = static_cast<int32_t>(std::round(floatRect.bottom)); } inline explicit Rect(const ui::Size& size) { Loading
libs/ui/tests/Rect_test.cpp +10 −0 Original line number Diff line number Diff line Loading @@ -99,6 +99,16 @@ TEST(RectTest, constructFromFloatRect) { EXPECT_EQ(30, rect.right); EXPECT_EQ(40, rect.bottom); } EXPECT_EQ(Rect(0, 1, -1, 0), Rect(FloatRect(0.f, 1.f, -1.f, 0.f))); EXPECT_EQ(Rect(100000, 100000, -100000, -100000), Rect(FloatRect(100000.f, 100000.f, -100000.f, -100000.f))); // round down if < .5 EXPECT_EQ(Rect(0, 1, -1, 0), Rect(FloatRect(0.4f, 1.1f, -1.499f, 0.1f))); // round up if >= .5 EXPECT_EQ(Rect(20, 20, -20, -20), Rect(FloatRect(19.5f, 19.9f, -19.5f, -19.9f))); } TEST(RectTest, makeInvalid) { Loading