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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 if (accum) { | 92 if (accum) { |
93 l = t = r = b = 0; | 93 l = t = r = b = 0; |
94 isFinite = false; | 94 isFinite = false; |
95 } | 95 } |
96 this->set(l, t, r, b); | 96 this->set(l, t, r, b); |
97 } | 97 } |
98 | 98 |
99 return isFinite; | 99 return isFinite; |
100 } | 100 } |
101 | 101 |
102 bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right, | 102 #define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \ |
103 SkScalar bottom) { | 103 SkScalar L = SkMaxScalar(al, bl); \ |
104 if (left < right && top < bottom && !this->isEmpty() && // check for empties | 104 SkScalar R = SkMinScalar(ar, br); \ |
105 fLeft < right && left < fRight && fTop < bottom && top < fBottom) | 105 SkScalar T = SkMaxScalar(at, bt); \ |
106 { | 106 SkScalar B = SkMinScalar(ab, bb); \ |
107 if (fLeft < left) fLeft = left; | 107 do { if (L >= R || T >= B) return false; } while (0) |
108 if (fTop < top) fTop = top; | 108 |
109 if (fRight > right) fRight = right; | 109 bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bot
tom) { |
110 if (fBottom > bottom) fBottom = bottom; | 110 CHECK_INTERSECT(left, top, right, bottom, fLeft, fTop, fRight, fBottom); |
111 return true; | 111 this->setLTRB(L, T, R, B); |
112 } | 112 return true; |
113 return false; | |
114 } | 113 } |
115 | 114 |
116 bool SkRect::intersect(const SkRect& r) { | 115 bool SkRect::intersect(const SkRect& r) { |
117 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom); | 116 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom); |
118 } | 117 } |
119 | 118 |
120 bool SkRect::intersect2(const SkRect& r) { | 119 bool SkRect::intersect(const SkRect& a, const SkRect& b) { |
121 SkScalar L = SkMaxScalar(fLeft, r.fLeft); | 120 CHECK_INTERSECT(a.fLeft, a.fTop, a.fRight, a.fBottom, b.fLeft, b.fTop, b.fRi
ght, b.fBottom); |
122 SkScalar R = SkMinScalar(fRight, r.fRight); | 121 this->setLTRB(L, T, R, B); |
123 if (L >= R) { | |
124 return false; | |
125 } | |
126 SkScalar T = SkMaxScalar(fTop, r.fTop); | |
127 SkScalar B = SkMinScalar(fBottom, r.fBottom); | |
128 if (T >= B) { | |
129 return false; | |
130 } | |
131 this->set(L, T, R, B); | |
132 return true; | 122 return true; |
133 } | 123 } |
134 | 124 |
135 bool SkRect::intersect(const SkRect& a, const SkRect& b) { | |
136 | |
137 if (!a.isEmpty() && !b.isEmpty() && | |
138 a.fLeft < b.fRight && b.fLeft < a.fRight && | |
139 a.fTop < b.fBottom && b.fTop < a.fBottom) { | |
140 fLeft = SkMaxScalar(a.fLeft, b.fLeft); | |
141 fTop = SkMaxScalar(a.fTop, b.fTop); | |
142 fRight = SkMinScalar(a.fRight, b.fRight); | |
143 fBottom = SkMinScalar(a.fBottom, b.fBottom); | |
144 return true; | |
145 } | |
146 return false; | |
147 } | |
148 | |
149 void SkRect::join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
{ | 125 void SkRect::join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
{ |
150 // do nothing if the params are empty | 126 // do nothing if the params are empty |
151 if (left >= right || top >= bottom) { | 127 if (left >= right || top >= bottom) { |
152 return; | 128 return; |
153 } | 129 } |
154 | 130 |
155 // if we are empty, just assign | 131 // if we are empty, just assign |
156 if (fLeft >= fRight || fTop >= fBottom) { | 132 if (fLeft >= fRight || fTop >= fBottom) { |
157 this->set(left, top, right, bottom); | 133 this->set(left, top, right, bottom); |
158 } else { | 134 } else { |
159 fLeft = SkMinScalar(fLeft, left); | 135 fLeft = SkMinScalar(fLeft, left); |
160 fTop = SkMinScalar(fTop, top); | 136 fTop = SkMinScalar(fTop, top); |
161 fRight = SkMaxScalar(fRight, right); | 137 fRight = SkMaxScalar(fRight, right); |
162 fBottom = SkMaxScalar(fBottom, bottom); | 138 fBottom = SkMaxScalar(fBottom, bottom); |
163 } | 139 } |
164 } | 140 } |
| 141 |
OLD | NEW |