OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
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 #include "SkLineClipper.h" | 8 #include "SkLineClipper.h" |
9 | 9 |
10 template <typename T> T pin_unsorted(T value, T limit0, T limit1) { | 10 template <typename T> T pin_unsorted(T value, T limit0, T limit1) { |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 const SkPoint pts[] = { | 166 const SkPoint pts[] = { |
167 { -540000, -720000 }, | 167 { -540000, -720000 }, |
168 { -9.10000017e-05f, 9.99999996e-13f } | 168 { -9.10000017e-05f, 9.99999996e-13f } |
169 }; | 169 }; |
170 float x = sect_with_horizontal(pts, 0); | 170 float x = sect_with_horizontal(pts, 0); |
171 SkASSERT(is_between_unsorted(x, pts[0].fX, pts[1].fX)); | 171 SkASSERT(is_between_unsorted(x, pts[0].fX, pts[1].fX)); |
172 } | 172 } |
173 #endif | 173 #endif |
174 | 174 |
175 int SkLineClipper::ClipLine(const SkPoint pts[], const SkRect& clip, | 175 int SkLineClipper::ClipLine(const SkPoint pts[], const SkRect& clip, |
176 SkPoint lines[], bool canClipToTheRight) { | 176 SkPoint lines[]) { |
177 #ifdef SK_DEBUG | 177 #ifdef SK_DEBUG |
178 { | 178 { |
179 static bool gOnce; | 179 static bool gOnce; |
180 if (!gOnce) { | 180 if (!gOnce) { |
181 sect_with_horizontal_test_for_pin_results(); | 181 sect_with_horizontal_test_for_pin_results(); |
182 gOnce = true; | 182 gOnce = true; |
183 } | 183 } |
184 } | 184 } |
185 #endif | 185 #endif |
186 | 186 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 index0 = 1; | 234 index0 = 1; |
235 index1 = 0; | 235 index1 = 0; |
236 reverse = true; | 236 reverse = true; |
237 } | 237 } |
238 | 238 |
239 if (tmp[index1].fX <= clip.fLeft) { // wholly to the left | 239 if (tmp[index1].fX <= clip.fLeft) { // wholly to the left |
240 tmp[0].fX = tmp[1].fX = clip.fLeft; | 240 tmp[0].fX = tmp[1].fX = clip.fLeft; |
241 result = tmp; | 241 result = tmp; |
242 reverse = false; | 242 reverse = false; |
243 } else if (tmp[index0].fX >= clip.fRight) { // wholly to the right | 243 } else if (tmp[index0].fX >= clip.fRight) { // wholly to the right |
244 if (canClipToTheRight) { | |
245 return 0; | |
246 } | |
247 tmp[0].fX = tmp[1].fX = clip.fRight; | 244 tmp[0].fX = tmp[1].fX = clip.fRight; |
248 result = tmp; | 245 result = tmp; |
249 reverse = false; | 246 reverse = false; |
250 } else { | 247 } else { |
251 result = resultStorage; | 248 result = resultStorage; |
252 SkPoint* r = result; | 249 SkPoint* r = result; |
253 | 250 |
254 if (tmp[index0].fX < clip.fLeft) { | 251 if (tmp[index0].fX < clip.fLeft) { |
255 r->set(clip.fLeft, tmp[index0].fY); | 252 r->set(clip.fLeft, tmp[index0].fY); |
256 r += 1; | 253 r += 1; |
(...skipping 20 matching lines...) Expand all Loading... |
277 if (reverse) { | 274 if (reverse) { |
278 // copy the pts in reverse order to maintain winding order | 275 // copy the pts in reverse order to maintain winding order |
279 for (int i = 0; i <= lineCount; i++) { | 276 for (int i = 0; i <= lineCount; i++) { |
280 lines[lineCount - i] = result[i]; | 277 lines[lineCount - i] = result[i]; |
281 } | 278 } |
282 } else { | 279 } else { |
283 memcpy(lines, result, (lineCount + 1) * sizeof(SkPoint)); | 280 memcpy(lines, result, (lineCount + 1) * sizeof(SkPoint)); |
284 } | 281 } |
285 return lineCount; | 282 return lineCount; |
286 } | 283 } |
OLD | NEW |