commit c2cf93cc4884e7b777f073a0a44465c16891ba3f
parent 455c0b0a8dc097948b9bd8cbb72bb62c683ce334
Author: Hiroyuki Ikezoe <hikezoe.birchill@mozilla.com>
Date: Fri, 3 Oct 2025 21:39:23 +0000
Bug 1992305 - Use std::numeric_limits::lowest() rather than std::numeric_limits::min(). r=gfx-reviewers,nical
For floating point min() returns minimum **positive** value.
Differential Revision: https://phabricator.services.mozilla.com/D267343
Diffstat:
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/gfx/2d/BaseRect.h b/gfx/2d/BaseRect.h
@@ -329,7 +329,7 @@ struct BaseRect {
x = limit - aDx < x ? limit : x + aDx;
width = (limit - aDx < x2 ? limit : x2 + aDx) - x;
} else {
- T limit = std::numeric_limits<T>::min();
+ T limit = std::numeric_limits<T>::lowest();
x = limit - aDx > x ? limit : x + aDx;
width = (limit - aDx > x2 ? limit : x2 + aDx) - x;
}
@@ -341,7 +341,7 @@ struct BaseRect {
y = limit - aDy < y ? limit : y + aDy;
height = (limit - aDy < y2 ? limit : y2 + aDy) - y;
} else {
- T limit = std::numeric_limits<T>::min();
+ T limit = std::numeric_limits<T>::lowest();
y = limit - aDy > y ? limit : y + aDy;
height = (limit - aDy > y2 ? limit : y2 + aDy) - y;
}
diff --git a/gfx/tests/gtest/TestRect.cpp b/gfx/tests/gtest/TestRect.cpp
@@ -711,3 +711,26 @@ TEST(Gfx, ClampPoint)
EXPECT_EQ(Empty.ClampPoint(IntPoint(1, -1)), IntPoint(0, 0));
EXPECT_EQ(Empty.ClampPoint(IntPoint(1, 1)), IntPoint(0, 0));
}
+
+TEST(Gfx, SafeMoveBy)
+{
+ IntRect intRect(0, 0, 10, 10);
+ intRect.SafeMoveByX(10);
+ intRect.SafeMoveByY(10);
+ EXPECT_EQ(intRect, IntRect(10, 10, 10, 10));
+
+ intRect = IntRect(0, 0, 10, 10);
+ intRect.SafeMoveByX(-10);
+ intRect.SafeMoveByY(-10);
+ EXPECT_EQ(intRect, IntRect(-10, -10, 10, 10));
+
+ Rect rect(0, 0, 10, 10);
+ rect.SafeMoveByX(10);
+ rect.SafeMoveByY(10);
+ EXPECT_EQ(rect, Rect(10, 10, 10, 10));
+
+ rect = Rect(0, 0, 10, 10);
+ rect.SafeMoveByX(-10);
+ rect.SafeMoveByY(-10);
+ EXPECT_EQ(rect, Rect(-10, -10, 10, 10));
+}