Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/platform/geometry/IntRect.cpp

Issue 25494003: Move geometry classes from core/platform/graphics to platform/geometry (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/platform/geometry/IntRect.h ('k') | Source/platform/geometry/IntRectExtent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/platform/graphics/IntRect.h" 27 #include "platform/geometry/IntRect.h"
28 28
29 #include "core/platform/graphics/FloatRect.h" 29 #include "platform/geometry/FloatRect.h"
30 #include "core/platform/graphics/LayoutRect.h" 30 #include "platform/geometry/LayoutRect.h"
31 #include "third_party/skia/include/core/SkRect.h" 31 #include "third_party/skia/include/core/SkRect.h"
32 32
33 #include <algorithm> 33 #include <algorithm>
34 34
35 using std::max;
36 using std::min;
37
38 namespace WebCore { 35 namespace WebCore {
39 36
40 IntRect::IntRect(const FloatRect& r) 37 IntRect::IntRect(const FloatRect& r)
41 : m_location(clampToInteger(r.x()), clampToInteger(r.y())) 38 : m_location(clampToInteger(r.x()), clampToInteger(r.y()))
42 , m_size(clampToInteger(r.width()), clampToInteger(r.height())) 39 , m_size(clampToInteger(r.width()), clampToInteger(r.height()))
43 { 40 {
44 } 41 }
45 42
46 IntRect::IntRect(const LayoutRect& r) 43 IntRect::IntRect(const LayoutRect& r)
47 : m_location(r.x(), r.y()) 44 : m_location(r.x(), r.y())
(...skipping 10 matching lines...) Expand all
58 } 55 }
59 56
60 bool IntRect::contains(const IntRect& other) const 57 bool IntRect::contains(const IntRect& other) const
61 { 58 {
62 return x() <= other.x() && maxX() >= other.maxX() 59 return x() <= other.x() && maxX() >= other.maxX()
63 && y() <= other.y() && maxY() >= other.maxY(); 60 && y() <= other.y() && maxY() >= other.maxY();
64 } 61 }
65 62
66 void IntRect::intersect(const IntRect& other) 63 void IntRect::intersect(const IntRect& other)
67 { 64 {
68 int l = max(x(), other.x()); 65 int left = std::max(x(), other.x());
69 int t = max(y(), other.y()); 66 int top = std::max(y(), other.y());
70 int r = min(maxX(), other.maxX()); 67 int right = std::min(maxX(), other.maxX());
71 int b = min(maxY(), other.maxY()); 68 int bottom = std::min(maxY(), other.maxY());
72 69
73 // Return a clean empty rectangle for non-intersecting cases. 70 // Return a clean empty rectangle for non-intersecting cases.
74 if (l >= r || t >= b) { 71 if (left >= right || top >= bottom) {
75 l = 0; 72 left = 0;
76 t = 0; 73 top = 0;
77 r = 0; 74 right = 0;
78 b = 0; 75 bottom = 0;
79 } 76 }
80 77
81 m_location.setX(l); 78 m_location.setX(left);
82 m_location.setY(t); 79 m_location.setY(top);
83 m_size.setWidth(r - l); 80 m_size.setWidth(right - left);
84 m_size.setHeight(b - t); 81 m_size.setHeight(bottom - top);
85 } 82 }
86 83
87 void IntRect::unite(const IntRect& other) 84 void IntRect::unite(const IntRect& other)
88 { 85 {
89 // Handle empty special cases first. 86 // Handle empty special cases first.
90 if (other.isEmpty()) 87 if (other.isEmpty())
91 return; 88 return;
92 if (isEmpty()) { 89 if (isEmpty()) {
93 *this = other; 90 *this = other;
94 return; 91 return;
95 } 92 }
96 93
97 int l = min(x(), other.x()); 94 int left = std::min(x(), other.x());
98 int t = min(y(), other.y()); 95 int top = std::min(y(), other.y());
99 int r = max(maxX(), other.maxX()); 96 int right = std::max(maxX(), other.maxX());
100 int b = max(maxY(), other.maxY()); 97 int bottom = std::max(maxY(), other.maxY());
101 98
102 m_location.setX(l); 99 m_location.setX(left);
103 m_location.setY(t); 100 m_location.setY(top);
104 m_size.setWidth(r - l); 101 m_size.setWidth(right - left);
105 m_size.setHeight(b - t); 102 m_size.setHeight(bottom - top);
106 } 103 }
107 104
108 void IntRect::uniteIfNonZero(const IntRect& other) 105 void IntRect::uniteIfNonZero(const IntRect& other)
109 { 106 {
110 // Handle empty special cases first. 107 // Handle empty special cases first.
111 if (!other.width() && !other.height()) 108 if (!other.width() && !other.height())
112 return; 109 return;
113 if (!width() && !height()) { 110 if (!width() && !height()) {
114 *this = other; 111 *this = other;
115 return; 112 return;
116 } 113 }
117 114
118 int left = min(x(), other.x()); 115 int left = std::min(x(), other.x());
119 int top = min(y(), other.y()); 116 int top = std::min(y(), other.y());
120 int right = max(maxX(), other.maxX()); 117 int right = std::max(maxX(), other.maxX());
121 int bottom = max(maxY(), other.maxY()); 118 int bottom = std::max(maxY(), other.maxY());
122 119
123 m_location.setX(left); 120 m_location.setX(left);
124 m_location.setY(top); 121 m_location.setY(top);
125 m_size.setWidth(right - left); 122 m_size.setWidth(right - left);
126 m_size.setHeight(bottom - top); 123 m_size.setHeight(bottom - top);
127 } 124 }
128 125
129 void IntRect::scale(float s) 126 void IntRect::scale(float s)
130 { 127 {
131 m_location.setX((int)(x() * s)); 128 m_location.setX((int)(x() * s));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 IntRect result; 165 IntRect result;
169 166
170 size_t count = rects.size(); 167 size_t count = rects.size();
171 for (size_t i = 0; i < count; ++i) 168 for (size_t i = 0; i < count; ++i)
172 result.unite(rects[i]); 169 result.unite(rects[i]);
173 170
174 return result; 171 return result;
175 } 172 }
176 173
177 } // namespace WebCore 174 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/geometry/IntRect.h ('k') | Source/platform/geometry/IntRectExtent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698