1 // Copyright 2015 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.
4 
5 #include "third_party/blink/renderer/platform/geometry/double_rect.h"
6 
7 #include "third_party/blink/renderer/platform/geometry/float_rect.h"
8 #include "third_party/blink/renderer/platform/geometry/int_rect.h"
9 #include "third_party/blink/renderer/platform/geometry/layout_rect.h"
10 #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
11 
12 namespace blink {
13 
DoubleRect(const IntRect & r)14 DoubleRect::DoubleRect(const IntRect& r)
15     : location_(r.Location()), size_(r.Size()) {}
16 
DoubleRect(const FloatRect & r)17 DoubleRect::DoubleRect(const FloatRect& r)
18     : location_(r.Location()), size_(r.Size()) {}
19 
DoubleRect(const LayoutRect & r)20 DoubleRect::DoubleRect(const LayoutRect& r)
21     : location_(r.Location()), size_(r.Size()) {}
22 
EnclosingIntRect(const DoubleRect & rect)23 IntRect EnclosingIntRect(const DoubleRect& rect) {
24   IntPoint location = FlooredIntPoint(rect.MinXMinYCorner());
25   IntPoint max_point = CeiledIntPoint(rect.MaxXMaxYCorner());
26 
27   return IntRect(location,
28                  IntSize(base::ClampSub(max_point.X(), location.X()),
29                          base::ClampSub(max_point.Y(), location.Y())));
30 }
31 
EnclosedIntRect(const DoubleRect & rect)32 IntRect EnclosedIntRect(const DoubleRect& rect) {
33   IntPoint location = CeiledIntPoint(rect.MinXMinYCorner());
34   IntPoint max_point = FlooredIntPoint(rect.MaxXMaxYCorner());
35   IntSize size = max_point - location;
36   size.ClampNegativeToZero();
37 
38   return IntRect(location, size);
39 }
40 
RoundedIntRect(const DoubleRect & rect)41 IntRect RoundedIntRect(const DoubleRect& rect) {
42   return IntRect(RoundedIntPoint(rect.Location()), RoundedIntSize(rect.Size()));
43 }
44 
Scale(float sx,float sy)45 void DoubleRect::Scale(float sx, float sy) {
46   location_.SetX(X() * sx);
47   location_.SetY(Y() * sy);
48   size_.SetWidth(Width() * sx);
49   size_.SetHeight(Height() * sy);
50 }
51 
operator <<(std::ostream & ostream,const DoubleRect & rect)52 std::ostream& operator<<(std::ostream& ostream, const DoubleRect& rect) {
53   return ostream << rect.ToString();
54 }
55 
ToString() const56 String DoubleRect::ToString() const {
57   return String::Format("%s %s", Location().ToString().Ascii().c_str(),
58                         Size().ToString().Ascii().c_str());
59 }
60 
61 }  // namespace blink
62