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.h"
13 #include "base/logging.h"
14 #include "base/strings/stringprintf.h"
15 #include "ui/gfx/geometry/insets.h"
16 #include "ui/gfx/geometry/rect_base_impl.h"
20 template class RectBase
<Rect
, Point
, Size
, Insets
, Vector2d
, int>;
22 typedef class RectBase
<Rect
, Point
, Size
, Insets
, Vector2d
, int> RectBaseT
;
25 Rect::Rect(const RECT
& r
)
26 : RectBaseT(gfx::Point(r
.left
, r
.top
)) {
27 set_width(std::abs(r
.right
- r
.left
));
28 set_height(std::abs(r
.bottom
- r
.top
));
30 #elif defined(OS_MACOSX)
31 Rect::Rect(const CGRect
& r
)
32 : RectBaseT(gfx::Point(r
.origin
.x
, r
.origin
.y
)) {
33 set_width(r
.size
.width
);
34 set_height(r
.size
.height
);
39 RECT
Rect::ToRECT() const {
47 #elif defined(OS_MACOSX)
48 CGRect
Rect::ToCGRect() const {
49 return CGRectMake(x(), y(), width(), height());
53 std::string
Rect::ToString() const {
54 return base::StringPrintf("%s %s",
55 origin().ToString().c_str(),
56 size().ToString().c_str());
59 Rect
operator+(const Rect
& lhs
, const Vector2d
& rhs
) {
65 Rect
operator-(const Rect
& lhs
, const Vector2d
& rhs
) {
71 Rect
IntersectRects(const Rect
& a
, const Rect
& b
) {
77 Rect
UnionRects(const Rect
& a
, const Rect
& b
) {
83 Rect
SubtractRects(const Rect
& a
, const Rect
& b
) {
89 Rect
BoundingRect(const Point
& p1
, const Point
& p2
) {
90 int rx
= std::min(p1
.x(), p2
.x());
91 int ry
= std::min(p1
.y(), p2
.y());
92 int rr
= std::max(p1
.x(), p2
.x());
93 int rb
= std::max(p1
.y(), p2
.y());
94 return Rect(rx
, ry
, rr
- rx
, rb
- ry
);