Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/pathops/SkPathOpsQuad.cpp

Issue 2128633003: pathops coincidence and security rewrite (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: require resulting t to be between 0 and 1 Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkPathOpsCurve.h" 10 #include "SkPathOpsCurve.h"
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 double one_t = 1 - t; 184 double one_t = 1 - t;
185 double a = one_t * one_t; 185 double a = one_t * one_t;
186 double b = 2 * one_t * t; 186 double b = 2 * one_t * t;
187 double c = t * t; 187 double c = t * t;
188 SkDPoint result = { a * fPts[0].fX + b * fPts[1].fX + c * fPts[2].fX, 188 SkDPoint result = { a * fPts[0].fX + b * fPts[1].fX + c * fPts[2].fX,
189 a * fPts[0].fY + b * fPts[1].fY + c * fPts[2].fY }; 189 a * fPts[0].fY + b * fPts[1].fY + c * fPts[2].fY };
190 return result; 190 return result;
191 } 191 }
192 192
193 static double interp_quad_coords(const double* src, double t) { 193 static double interp_quad_coords(const double* src, double t) {
194 if (0 == t) {
195 return src[0];
196 }
197 if (1 == t) {
198 return src[4];
199 }
194 double ab = SkDInterp(src[0], src[2], t); 200 double ab = SkDInterp(src[0], src[2], t);
195 double bc = SkDInterp(src[2], src[4], t); 201 double bc = SkDInterp(src[2], src[4], t);
196 double abc = SkDInterp(ab, bc, t); 202 double abc = SkDInterp(ab, bc, t);
197 return abc; 203 return abc;
198 } 204 }
199 205
200 bool SkDQuad::monotonicInX() const { 206 bool SkDQuad::monotonicInX() const {
201 return between(fPts[0].fX, fPts[1].fX, fPts[2].fX); 207 return between(fPts[0].fX, fPts[1].fX, fPts[2].fX);
202 } 208 }
203 209
(...skipping 17 matching lines...) Expand all
221 _12 = A/2 + B/2 227 _12 = A/2 + B/2
222 12_ = B/2 + C/2 228 12_ = B/2 + C/2
223 123 = A/4 + B/2 + C/4 229 123 = A/4 + B/2 + C/4
224 = D 230 = D
225 231
226 Group the known values on one side: 232 Group the known values on one side:
227 233
228 B = D*2 - A/2 - C/2 234 B = D*2 - A/2 - C/2
229 */ 235 */
230 236
231 // OPTIMIZE : special case either or both of t1 = 0, t2 = 1 237 // OPTIMIZE? : special case t1 = 1 && t2 = 0
232 SkDQuad SkDQuad::subDivide(double t1, double t2) const { 238 SkDQuad SkDQuad::subDivide(double t1, double t2) const {
239 if (0 == t1 && 1 == t2) {
240 return *this;
241 }
233 SkDQuad dst; 242 SkDQuad dst;
234 double ax = dst[0].fX = interp_quad_coords(&fPts[0].fX, t1); 243 double ax = dst[0].fX = interp_quad_coords(&fPts[0].fX, t1);
235 double ay = dst[0].fY = interp_quad_coords(&fPts[0].fY, t1); 244 double ay = dst[0].fY = interp_quad_coords(&fPts[0].fY, t1);
236 double dx = interp_quad_coords(&fPts[0].fX, (t1 + t2) / 2); 245 double dx = interp_quad_coords(&fPts[0].fX, (t1 + t2) / 2);
237 double dy = interp_quad_coords(&fPts[0].fY, (t1 + t2) / 2); 246 double dy = interp_quad_coords(&fPts[0].fY, (t1 + t2) / 2);
238 double cx = dst[2].fX = interp_quad_coords(&fPts[0].fX, t2); 247 double cx = dst[2].fX = interp_quad_coords(&fPts[0].fX, t2);
239 double cy = dst[2].fY = interp_quad_coords(&fPts[0].fY, t2); 248 double cy = dst[2].fY = interp_quad_coords(&fPts[0].fY, t2);
240 /* bx = */ dst[1].fX = 2 * dx - (ax + cx) / 2; 249 /* bx = */ dst[1].fX = 2 * dx - (ax + cx) / 2;
241 /* by = */ dst[1].fY = 2 * dy - (ay + cy) / 2; 250 /* by = */ dst[1].fY = 2 * dy - (ay + cy) / 2;
242 return dst; 251 return dst;
(...skipping 13 matching lines...) Expand all
256 SkDPoint b; 265 SkDPoint b;
257 SkDQuad sub = subDivide(t1, t2); 266 SkDQuad sub = subDivide(t1, t2);
258 SkDLine b0 = {{a, sub[1] + (a - sub[0])}}; 267 SkDLine b0 = {{a, sub[1] + (a - sub[0])}};
259 SkDLine b1 = {{c, sub[1] + (c - sub[2])}}; 268 SkDLine b1 = {{c, sub[1] + (c - sub[2])}};
260 SkIntersections i; 269 SkIntersections i;
261 i.intersectRay(b0, b1); 270 i.intersectRay(b0, b1);
262 if (i.used() == 1 && i[0][0] >= 0 && i[1][0] >= 0) { 271 if (i.used() == 1 && i[0][0] >= 0 && i[1][0] >= 0) {
263 b = i.pt(0); 272 b = i.pt(0);
264 } else { 273 } else {
265 SkASSERT(i.used() <= 2); 274 SkASSERT(i.used() <= 2);
266 b = SkDPoint::Mid(b0[1], b1[1]); 275 return SkDPoint::Mid(b0[1], b1[1]);
267 } 276 }
268 if (t1 == 0 || t2 == 0) { 277 if (t1 == 0 || t2 == 0) {
269 align(0, &b); 278 align(0, &b);
270 } 279 }
271 if (t1 == 1 || t2 == 1) { 280 if (t1 == 1 || t2 == 1) {
272 align(2, &b); 281 align(2, &b);
273 } 282 }
274 if (AlmostBequalUlps(b.fX, a.fX)) { 283 if (AlmostBequalUlps(b.fX, a.fX)) {
275 b.fX = a.fX; 284 b.fX = a.fX;
276 } else if (AlmostBequalUlps(b.fX, c.fX)) { 285 } else if (AlmostBequalUlps(b.fX, c.fX)) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 * c = C 351 * c = C
343 */ 352 */
344 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) { 353 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) {
345 *a = quad[0]; // a = A 354 *a = quad[0]; // a = A
346 *b = 2 * quad[2]; // b = 2*B 355 *b = 2 * quad[2]; // b = 2*B
347 *c = quad[4]; // c = C 356 *c = quad[4]; // c = C
348 *b -= *c; // b = 2*B - C 357 *b -= *c; // b = 2*B - C
349 *a -= *b; // a = A - 2*B + C 358 *a -= *b; // a = A - 2*B + C
350 *b -= *c; // b = 2*B - 2*C 359 *b -= *c; // b = 2*B - 2*C
351 } 360 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698