OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkRect.h" | 8 #include "SkRect.h" |
9 | 9 |
| 10 bool SkIRect::contains(const SkRect& r) const { |
| 11 if (r.isEmpty() || this->isEmpty()) { |
| 12 return false; |
| 13 } |
| 14 // If r's coords are greater than the max int32_t, then they must be outside
this SkIRect. |
| 15 if (!r.canRound()) { |
| 16 return false; |
| 17 } |
| 18 // At this point, we can convert the SkRect to SkIRect and compare directly. |
| 19 return this->contains(r.roundOut()); |
| 20 } |
| 21 |
10 void SkIRect::join(int32_t left, int32_t top, int32_t right, int32_t bottom) { | 22 void SkIRect::join(int32_t left, int32_t top, int32_t right, int32_t bottom) { |
11 // do nothing if the params are empty | 23 // do nothing if the params are empty |
12 if (left >= right || top >= bottom) { | 24 if (left >= right || top >= bottom) { |
13 return; | 25 return; |
14 } | 26 } |
15 | 27 |
16 // if we are empty, just assign | 28 // if we are empty, just assign |
17 if (fLeft >= fRight || fTop >= fBottom) { | 29 if (fLeft >= fRight || fTop >= fBottom) { |
18 this->set(left, top, right, bottom); | 30 this->set(left, top, right, bottom); |
19 } else { | 31 } else { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (fLeft >= fRight || fTop >= fBottom) { | 147 if (fLeft >= fRight || fTop >= fBottom) { |
136 this->set(left, top, right, bottom); | 148 this->set(left, top, right, bottom); |
137 } else { | 149 } else { |
138 fLeft = SkMinScalar(fLeft, left); | 150 fLeft = SkMinScalar(fLeft, left); |
139 fTop = SkMinScalar(fTop, top); | 151 fTop = SkMinScalar(fTop, top); |
140 fRight = SkMaxScalar(fRight, right); | 152 fRight = SkMaxScalar(fRight, right); |
141 fBottom = SkMaxScalar(fBottom, bottom); | 153 fBottom = SkMaxScalar(fBottom, bottom); |
142 } | 154 } |
143 } | 155 } |
144 | 156 |
| 157 bool SkRect::canRound() const { |
| 158 if (fLeft < -SK_MaxS32Scalar || fTop < -SK_MaxS32Scalar || |
| 159 fRight > SK_MaxS32Scalar || fBottom > SK_MaxS32Scalar) { |
| 160 return false; |
| 161 } |
| 162 if (this->isEmpty()) { |
| 163 return fLeft < SK_MaxS32Scalar && fTop < SK_MaxS32Scalar && |
| 164 fRight > -SK_MaxS32Scalar && fBottom > -SK_MaxS32Scalar; |
| 165 } else { |
| 166 return true; |
| 167 } |
| 168 } |
| 169 |
145 ////////////////////////////////////////////////////////////////////////////////
//////////////// | 170 ////////////////////////////////////////////////////////////////////////////////
//////////////// |
146 | 171 |
147 #include "SkString.h" | 172 #include "SkString.h" |
148 #include "SkStringUtils.h" | 173 #include "SkStringUtils.h" |
149 | 174 |
150 static const char* set_scalar(SkString* storage, SkScalar value, SkScalarAsStrin
gType asType) { | 175 static const char* set_scalar(SkString* storage, SkScalar value, SkScalarAsStrin
gType asType) { |
151 storage->reset(); | 176 storage->reset(); |
152 SkAppendScalar(storage, value, asType); | 177 SkAppendScalar(storage, value, asType); |
153 return storage->c_str(); | 178 return storage->c_str(); |
154 } | 179 } |
(...skipping 12 matching lines...) Expand all Loading... |
167 SkString strL, strT, strR, strB; | 192 SkString strL, strT, strR, strB; |
168 SkAppendScalarDec(&strL, fLeft); | 193 SkAppendScalarDec(&strL, fLeft); |
169 SkAppendScalarDec(&strT, fTop); | 194 SkAppendScalarDec(&strT, fTop); |
170 SkAppendScalarDec(&strR, fRight); | 195 SkAppendScalarDec(&strR, fRight); |
171 SkAppendScalarDec(&strB, fBottom); | 196 SkAppendScalarDec(&strB, fBottom); |
172 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);", | 197 line.printf("SkRect::MakeLTRB(%s, %s, %s, %s);", |
173 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str()); | 198 strL.c_str(), strT.c_str(), strR.c_str(), strB.c_str()); |
174 } | 199 } |
175 SkDebugf("%s\n", line.c_str()); | 200 SkDebugf("%s\n", line.c_str()); |
176 } | 201 } |
OLD | NEW |