| 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 232 |
| 233 static const int kEpsilon = std::numeric_limits<int>::is_integer | 233 static const int kEpsilon = std::numeric_limits<int>::is_integer |
| 234 ? 1 | 234 ? 1 |
| 235 : std::numeric_limits<int>::epsilon(); | 235 : std::numeric_limits<int>::epsilon(); |
| 236 | 236 |
| 237 int x = std::max<int>(0, c.width() - width() - rect.width() + kEpsilon); | 237 int x = std::max<int>(0, c.width() - width() - rect.width() + kEpsilon); |
| 238 int y = std::max<int>(0, c.height() - height() - rect.height() + kEpsilon); | 238 int y = std::max<int>(0, c.height() - height() - rect.height() + kEpsilon); |
| 239 return x + y; | 239 return x + y; |
| 240 } | 240 } |
| 241 | 241 |
| 242 float Rect::MaxDistanceToCorners(const gfx::Point& point) const { |
| 243 const float distance_to_top_left = (origin() - point).Length(); |
| 244 const float distance_to_top_right = (top_right() - point).Length(); |
| 245 const float distance_to_bottom_left = (bottom_left() - point).Length(); |
| 246 const float distance_to_bottom_right = (bottom_right() - point).Length(); |
| 247 |
| 248 float largest_distance = |
| 249 std::max(distance_to_top_left, distance_to_top_right); |
| 250 largest_distance = std::max(largest_distance, distance_to_bottom_left); |
| 251 largest_distance = std::max(largest_distance, distance_to_bottom_right); |
| 252 return largest_distance; |
| 253 } |
| 254 |
| 242 std::string Rect::ToString() const { | 255 std::string Rect::ToString() const { |
| 243 return base::StringPrintf("%s %s", | 256 return base::StringPrintf("%s %s", |
| 244 origin().ToString().c_str(), | 257 origin().ToString().c_str(), |
| 245 size().ToString().c_str()); | 258 size().ToString().c_str()); |
| 246 } | 259 } |
| 247 | 260 |
| 248 bool Rect::ApproximatelyEqual(const Rect& rect, int tolerance) const { | 261 bool Rect::ApproximatelyEqual(const Rect& rect, int tolerance) const { |
| 249 return std::abs(x() - rect.x()) <= tolerance && | 262 return std::abs(x() - rect.x()) <= tolerance && |
| 250 std::abs(y() - rect.y()) <= tolerance && | 263 std::abs(y() - rect.y()) <= tolerance && |
| 251 std::abs(right() - rect.right()) <= tolerance && | 264 std::abs(right() - rect.right()) <= tolerance && |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 297 |
| 285 Rect BoundingRect(const Point& p1, const Point& p2) { | 298 Rect BoundingRect(const Point& p1, const Point& p2) { |
| 286 int rx = std::min(p1.x(), p2.x()); | 299 int rx = std::min(p1.x(), p2.x()); |
| 287 int ry = std::min(p1.y(), p2.y()); | 300 int ry = std::min(p1.y(), p2.y()); |
| 288 int rr = std::max(p1.x(), p2.x()); | 301 int rr = std::max(p1.x(), p2.x()); |
| 289 int rb = std::max(p1.y(), p2.y()); | 302 int rb = std::max(p1.y(), p2.y()); |
| 290 return Rect(rx, ry, rr - rx, rb - ry); | 303 return Rect(rx, ry, rr - rx, rb - ry); |
| 291 } | 304 } |
| 292 | 305 |
| 293 } // namespace gfx | 306 } // namespace gfx |
| OLD | NEW |