OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
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 #include "SkIntersections.h" | 7 #include "SkIntersections.h" |
8 #include "SkLineParameters.h" | 8 #include "SkLineParameters.h" |
9 #include "SkPathOpsCubic.h" | 9 #include "SkPathOpsCubic.h" |
10 #include "SkPathOpsQuad.h" | 10 #include "SkPathOpsQuad.h" |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 double dx = interp_quad_coords(&fPts[0].fX, (t1 + t2) / 2); | 245 double dx = interp_quad_coords(&fPts[0].fX, (t1 + t2) / 2); |
246 double dy = interp_quad_coords(&fPts[0].fY, (t1 + t2) / 2); | 246 double dy = interp_quad_coords(&fPts[0].fY, (t1 + t2) / 2); |
247 b.fX = 2 * dx - (a.fX + c.fX) / 2; | 247 b.fX = 2 * dx - (a.fX + c.fX) / 2; |
248 b.fY = 2 * dy - (a.fY + c.fY) / 2; | 248 b.fY = 2 * dy - (a.fY + c.fY) / 2; |
249 #else | 249 #else |
250 SkDQuad sub = subDivide(t1, t2); | 250 SkDQuad sub = subDivide(t1, t2); |
251 SkDLine b0 = {{a, sub[1] + (a - sub[0])}}; | 251 SkDLine b0 = {{a, sub[1] + (a - sub[0])}}; |
252 SkDLine b1 = {{c, sub[1] + (c - sub[2])}}; | 252 SkDLine b1 = {{c, sub[1] + (c - sub[2])}}; |
253 SkIntersections i; | 253 SkIntersections i; |
254 i.intersectRay(b0, b1); | 254 i.intersectRay(b0, b1); |
255 if (i.used() == 1) { | 255 if (i.used() == 1 && i[0][0] >= 0 && i[1][0] >= 0) { |
256 b = i.pt(0); | 256 b = i.pt(0); |
257 } else { | 257 } else { |
258 SkASSERT(i.used() == 2 || i.used() == 0); | 258 SkASSERT(i.used() <= 2); |
259 b = SkDPoint::Mid(b0[1], b1[1]); | 259 b = SkDPoint::Mid(b0[1], b1[1]); |
260 } | 260 } |
261 #endif | 261 #endif |
262 if (t1 == 0 || t2 == 0) { | 262 if (t1 == 0 || t2 == 0) { |
263 align(0, &b); | 263 align(0, &b); |
264 } | 264 } |
265 if (t1 == 1 || t2 == 1) { | 265 if (t1 == 1 || t2 == 1) { |
266 align(2, &b); | 266 align(2, &b); |
267 } | 267 } |
268 if (precisely_subdivide_equal(b.fX, a.fX)) { | 268 if (AlmostBequalUlps(b.fX, a.fX)) { |
269 b.fX = a.fX; | 269 b.fX = a.fX; |
270 } else if (precisely_subdivide_equal(b.fX, c.fX)) { | 270 } else if (AlmostBequalUlps(b.fX, c.fX)) { |
271 b.fX = c.fX; | 271 b.fX = c.fX; |
272 } | 272 } |
273 if (precisely_subdivide_equal(b.fY, a.fY)) { | 273 if (AlmostBequalUlps(b.fY, a.fY)) { |
274 b.fY = a.fY; | 274 b.fY = a.fY; |
275 } else if (precisely_subdivide_equal(b.fY, c.fY)) { | 275 } else if (AlmostBequalUlps(b.fY, c.fY)) { |
276 b.fY = c.fY; | 276 b.fY = c.fY; |
277 } | 277 } |
278 return b; | 278 return b; |
279 } | 279 } |
280 | 280 |
281 /* classic one t subdivision */ | 281 /* classic one t subdivision */ |
282 static void interp_quad_coords(const double* src, double* dst, double t) { | 282 static void interp_quad_coords(const double* src, double* dst, double t) { |
283 double ab = SkDInterp(src[0], src[2], t); | 283 double ab = SkDInterp(src[0], src[2], t); |
284 double bc = SkDInterp(src[2], src[4], t); | 284 double bc = SkDInterp(src[2], src[4], t); |
285 dst[0] = src[0]; | 285 dst[0] = src[0]; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 * c = C | 333 * c = C |
334 */ | 334 */ |
335 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) { | 335 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) { |
336 *a = quad[0]; // a = A | 336 *a = quad[0]; // a = A |
337 *b = 2 * quad[2]; // b = 2*B | 337 *b = 2 * quad[2]; // b = 2*B |
338 *c = quad[4]; // c = C | 338 *c = quad[4]; // c = C |
339 *b -= *c; // b = 2*B - C | 339 *b -= *c; // b = 2*B - C |
340 *a -= *b; // a = A - 2*B + C | 340 *a -= *b; // a = A - 2*B + C |
341 *b -= *c; // b = 2*B - 2*C | 341 *b -= *c; // b = 2*B - 2*C |
342 } | 342 } |
343 | |
344 #ifdef SK_DEBUG | |
345 void SkDQuad::dump() { | |
346 SkDebugf("{{"); | |
347 int index = 0; | |
348 do { | |
349 fPts[index].dump(); | |
350 SkDebugf(", "); | |
351 } while (++index < 2); | |
352 fPts[index].dump(); | |
353 SkDebugf("}}\n"); | |
354 } | |
355 #endif | |
OLD | NEW |