OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/geometry/rect.h" | 5 #include "ui/gfx/geometry/rect.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 124 matching lines...) Loading... | |
135 void Rect::Union(const Rect& rect) { | 135 void Rect::Union(const Rect& rect) { |
136 if (IsEmpty()) { | 136 if (IsEmpty()) { |
137 *this = rect; | 137 *this = rect; |
138 return; | 138 return; |
139 } | 139 } |
140 if (rect.IsEmpty()) | 140 if (rect.IsEmpty()) |
141 return; | 141 return; |
142 | 142 |
143 int rx = std::min(x(), rect.x()); | 143 int rx = std::min(x(), rect.x()); |
144 int ry = std::min(y(), rect.y()); | 144 int ry = std::min(y(), rect.y()); |
145 int rr = std::max(right(), rect.right()); | |
146 int rb = std::max(bottom(), rect.bottom()); | |
147 | 145 |
148 SetRect(rx, ry, rr - rx, rb - ry); | 146 // This is a temporary fix to avoid integer overflow, gfx::Rect is not |
147 // supposed to have instances whose right or bottom is greater than maximum | |
148 // integer. This hack should be removed if root cause is fixed. | |
danakj
2016/08/23 17:47:56
I'm not sure what this comment means, there are li
sunxd
2016/08/23 19:08:24
I'll remove this comment.
| |
149 int64_t right = static_cast<int64_t>(x()) + width(); | |
danakj
2016/08/23 17:47:56
why not just use right()? Does the rect already ha
sunxd
2016/08/23 19:08:24
It does not. Is there any difference between right
danakj
2016/08/23 19:25:12
No, I mean it just depends on the inputs. Neither
| |
150 int64_t rect_right = static_cast<int64_t>(rect.x()) + rect.width(); | |
danakj
2016/08/23 17:47:56
What performs better? int64_ts with (properly) sat
sunxd
2016/08/23 19:08:24
Hmm actually I have no idea which has a better per
danakj
2016/08/23 19:25:12
You could do a simple test to figure out what's be
| |
151 int64_t bottom = static_cast<int64_t>(y()) + height(); | |
152 int64_t rect_bottom = static_cast<int64_t>(rect.y()) + rect.height(); | |
153 | |
154 int64_t rr = std::max(right, rect_right); | |
155 int64_t rb = std::max(bottom, rect_bottom); | |
156 | |
157 SetRect(rx, ry, static_cast<int>(rr - rx), static_cast<int>(rb - ry)); | |
danakj
2016/08/23 17:47:56
Does static cast really do what you want?
http://
sunxd
2016/08/23 19:08:24
Working on tests.
| |
149 } | 158 } |
150 | 159 |
151 void Rect::Subtract(const Rect& rect) { | 160 void Rect::Subtract(const Rect& rect) { |
152 if (!Intersects(rect)) | 161 if (!Intersects(rect)) |
153 return; | 162 return; |
154 if (rect.Contains(*this)) { | 163 if (rect.Contains(*this)) { |
155 SetRect(0, 0, 0, 0); | 164 SetRect(0, 0, 0, 0); |
156 return; | 165 return; |
157 } | 166 } |
158 | 167 |
(...skipping 125 matching lines...) Loading... | |
284 | 293 |
285 Rect BoundingRect(const Point& p1, const Point& p2) { | 294 Rect BoundingRect(const Point& p1, const Point& p2) { |
286 int rx = std::min(p1.x(), p2.x()); | 295 int rx = std::min(p1.x(), p2.x()); |
287 int ry = std::min(p1.y(), p2.y()); | 296 int ry = std::min(p1.y(), p2.y()); |
288 int rr = std::max(p1.x(), p2.x()); | 297 int rr = std::max(p1.x(), p2.x()); |
289 int rb = std::max(p1.y(), p2.y()); | 298 int rb = std::max(p1.y(), p2.y()); |
290 return Rect(rx, ry, rr - rx, rb - ry); | 299 return Rect(rx, ry, rr - rx, rb - ry); |
291 } | 300 } |
292 | 301 |
293 } // namespace gfx | 302 } // namespace gfx |
OLD | NEW |