OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkRect.h" | 10 #include "SkRect.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 if (fLeft < left) fLeft = left; | 107 if (fLeft < left) fLeft = left; |
108 if (fTop < top) fTop = top; | 108 if (fTop < top) fTop = top; |
109 if (fRight > right) fRight = right; | 109 if (fRight > right) fRight = right; |
110 if (fBottom > bottom) fBottom = bottom; | 110 if (fBottom > bottom) fBottom = bottom; |
111 return true; | 111 return true; |
112 } | 112 } |
113 return false; | 113 return false; |
114 } | 114 } |
115 | 115 |
116 bool SkRect::intersect(const SkRect& r) { | 116 bool SkRect::intersect(const SkRect& r) { |
117 SkASSERT(&r); | |
118 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom); | 117 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom); |
119 } | 118 } |
120 | 119 |
121 bool SkRect::intersect2(const SkRect& r) { | 120 bool SkRect::intersect2(const SkRect& r) { |
122 SkASSERT(&r); | |
123 SkScalar L = SkMaxScalar(fLeft, r.fLeft); | 121 SkScalar L = SkMaxScalar(fLeft, r.fLeft); |
124 SkScalar R = SkMinScalar(fRight, r.fRight); | 122 SkScalar R = SkMinScalar(fRight, r.fRight); |
125 if (L >= R) { | 123 if (L >= R) { |
126 return false; | 124 return false; |
127 } | 125 } |
128 SkScalar T = SkMaxScalar(fTop, r.fTop); | 126 SkScalar T = SkMaxScalar(fTop, r.fTop); |
129 SkScalar B = SkMinScalar(fBottom, r.fBottom); | 127 SkScalar B = SkMinScalar(fBottom, r.fBottom); |
130 if (T >= B) { | 128 if (T >= B) { |
131 return false; | 129 return false; |
132 } | 130 } |
133 this->set(L, T, R, B); | 131 this->set(L, T, R, B); |
134 return true; | 132 return true; |
135 } | 133 } |
136 | 134 |
137 bool SkRect::intersect(const SkRect& a, const SkRect& b) { | 135 bool SkRect::intersect(const SkRect& a, const SkRect& b) { |
138 SkASSERT(&a && &b); | |
139 | 136 |
140 if (!a.isEmpty() && !b.isEmpty() && | 137 if (!a.isEmpty() && !b.isEmpty() && |
141 a.fLeft < b.fRight && b.fLeft < a.fRight && | 138 a.fLeft < b.fRight && b.fLeft < a.fRight && |
142 a.fTop < b.fBottom && b.fTop < a.fBottom) { | 139 a.fTop < b.fBottom && b.fTop < a.fBottom) { |
143 fLeft = SkMaxScalar(a.fLeft, b.fLeft); | 140 fLeft = SkMaxScalar(a.fLeft, b.fLeft); |
144 fTop = SkMaxScalar(a.fTop, b.fTop); | 141 fTop = SkMaxScalar(a.fTop, b.fTop); |
145 fRight = SkMinScalar(a.fRight, b.fRight); | 142 fRight = SkMinScalar(a.fRight, b.fRight); |
146 fBottom = SkMinScalar(a.fBottom, b.fBottom); | 143 fBottom = SkMinScalar(a.fBottom, b.fBottom); |
147 return true; | 144 return true; |
148 } | 145 } |
(...skipping 10 matching lines...) Expand all Loading... |
159 // if we are empty, just assign | 156 // if we are empty, just assign |
160 if (fLeft >= fRight || fTop >= fBottom) { | 157 if (fLeft >= fRight || fTop >= fBottom) { |
161 this->set(left, top, right, bottom); | 158 this->set(left, top, right, bottom); |
162 } else { | 159 } else { |
163 if (left < fLeft) fLeft = left; | 160 if (left < fLeft) fLeft = left; |
164 if (top < fTop) fTop = top; | 161 if (top < fTop) fTop = top; |
165 if (right > fRight) fRight = right; | 162 if (right > fRight) fRight = right; |
166 if (bottom > fBottom) fBottom = bottom; | 163 if (bottom > fBottom) fBottom = bottom; |
167 } | 164 } |
168 } | 165 } |
OLD | NEW |