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

Unified Diff: ui/gfx/geometry/rect.cc

Issue 2744423002: Handle large rects better. (Closed)
Patch Set: Handle large rects better. 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
Index: ui/gfx/geometry/rect.cc
diff --git a/ui/gfx/geometry/rect.cc b/ui/gfx/geometry/rect.cc
index f3c47b2b378e9b0bd8087330560a4b7541e6384d..1ebe16991f691ecc7f736bfff5f6c31f458f981e 100644
--- a/ui/gfx/geometry/rect.cc
+++ b/ui/gfx/geometry/rect.cc
@@ -157,8 +157,29 @@ void Rect::Union(const Rect& rect) {
int rb = std::max(bottom(), rect.bottom());
// Subtracting to get width/height might overflow integers, so clamp them.
- SetRect(rx, ry, base::SaturatedSubtraction(rr, rx),
- base::SaturatedSubtraction(rb, ry));
+ int rdx = base::SaturatedSubtraction(rr, rx);
+ int rdy = base::SaturatedSubtraction(rb, ry);
+
+ // clamping may move one side, choose to move the bigger by recomputing it.
+ // The computation of right is implicit, so this happens vacuosly.
+ // If Right is small, move left to width away.
+ // If Left is big(negative), move them both to keep the center.
+ if (rdx >= std::numeric_limits<int>::max() / 2) {
Peter Mayo 2017/03/14 18:35:59 Maybe just on equality.
+ if (base::SaturatedAbsolute(rr) < rdx / 2)
+ rx = rr - rdx;
+ else if (base::SaturatedAbsolute(rx) > rdx / 2)
+ rx = rx + rdx / 4;
+ }
+
+ // Same computation, other axis.
+ if (rdy >= std::numeric_limits<int>::max() / 2) {
+ if (base::SaturatedAbsolute(rb) < rdy / 2)
+ ry = rb - rdy;
+ else if (base::SaturatedAbsolute(ry) > rdy / 2)
+ ry = ry + rdy / 4;
+ }
+
+ SetRect(rx, ry, rdx, rdy);
}
void Rect::Subtract(const Rect& rect) {

Powered by Google App Engine
This is Rietveld 408576698