[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / gfx / geometry / rect_f.cc
blob44c08aafaff5506edc621ba9fe4d632600d68f90
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
3 // found in the LICENSE file.
5 #include "ui/gfx/geometry/rect_f.h"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h"
11 #include "ui/gfx/geometry/insets_f.h"
12 #include "ui/gfx/geometry/rect_base_impl.h"
13 #include "ui/gfx/geometry/safe_integer_conversions.h"
15 namespace gfx {
17 template class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF, float>;
19 typedef class RectBase<RectF, PointF, SizeF, InsetsF, Vector2dF,
20 float> RectBaseT;
22 bool RectF::IsExpressibleAsRect() const {
23 return IsExpressibleAsInt(x()) && IsExpressibleAsInt(y()) &&
24 IsExpressibleAsInt(width()) && IsExpressibleAsInt(height()) &&
25 IsExpressibleAsInt(right()) && IsExpressibleAsInt(bottom());
28 std::string RectF::ToString() const {
29 return base::StringPrintf("%s %s",
30 origin().ToString().c_str(),
31 size().ToString().c_str());
34 RectF IntersectRects(const RectF& a, const RectF& b) {
35 RectF result = a;
36 result.Intersect(b);
37 return result;
40 RectF UnionRects(const RectF& a, const RectF& b) {
41 RectF result = a;
42 result.Union(b);
43 return result;
46 RectF SubtractRects(const RectF& a, const RectF& b) {
47 RectF result = a;
48 result.Subtract(b);
49 return result;
52 RectF BoundingRect(const PointF& p1, const PointF& p2) {
53 float rx = std::min(p1.x(), p2.x());
54 float ry = std::min(p1.y(), p2.y());
55 float rr = std::max(p1.x(), p2.x());
56 float rb = std::max(p1.y(), p2.y());
57 return RectF(rx, ry, rr - rx, rb - ry);
60 } // namespace gfx