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

Side by Side Diff: src/pathops/SkDConicLineIntersection.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 2015 Google Inc. 2 * Copyright 2015 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 "SkPathOpsConic.h" 8 #include "SkPathOpsConic.h"
9 #include "SkPathOpsCurve.h"
9 #include "SkPathOpsLine.h" 10 #include "SkPathOpsLine.h"
10 11
11 class LineConicIntersections { 12 class LineConicIntersections {
12 public: 13 public:
13 enum PinTPoint { 14 enum PinTPoint {
14 kPointUninitialized, 15 kPointUninitialized,
15 kPointInitialized 16 kPointInitialized
16 }; 17 };
17 18
18 LineConicIntersections(const SkDConic& c, const SkDLine& l, SkIntersections* i) 19 LineConicIntersections(const SkDConic& c, const SkDLine& l, SkIntersections* i)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 double conicT = (double) (cIndex >> 1); 193 double conicT = (double) (cIndex >> 1);
193 if (fIntersections->hasT(conicT)) { 194 if (fIntersections->hasT(conicT)) {
194 continue; 195 continue;
195 } 196 }
196 double lineT = fLine->nearPoint(fConic[cIndex], nullptr); 197 double lineT = fLine->nearPoint(fConic[cIndex], nullptr);
197 if (lineT < 0) { 198 if (lineT < 0) {
198 continue; 199 continue;
199 } 200 }
200 fIntersections->insert(conicT, lineT, fConic[cIndex]); 201 fIntersections->insert(conicT, lineT, fConic[cIndex]);
201 } 202 }
202 // FIXME: see if line end is nearly on conic 203 addLineNearEndPoints();
204 }
205
206 void addLineNearEndPoints() {
207 for (int lIndex = 0; lIndex < 2; ++lIndex) {
208 double lineT = (double) lIndex;
209 if (fIntersections->hasOppT(lineT)) {
210 continue;
211 }
212 double conicT = ((SkDCurve*) &fConic)->nearPoint(SkPath::kConic_Verb ,
213 (*fLine)[lIndex], (*fLine)[!lIndex]);
214 if (conicT < 0) {
215 continue;
216 }
217 fIntersections->insert(conicT, lineT, (*fLine)[lIndex]);
218 }
203 } 219 }
204 220
205 void addExactHorizontalEndPoints(double left, double right, double y) { 221 void addExactHorizontalEndPoints(double left, double right, double y) {
206 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) { 222 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) {
207 double lineT = SkDLine::ExactPointH(fConic[cIndex], left, right, y); 223 double lineT = SkDLine::ExactPointH(fConic[cIndex], left, right, y);
208 if (lineT < 0) { 224 if (lineT < 0) {
209 continue; 225 continue;
210 } 226 }
211 double conicT = (double) (cIndex >> 1); 227 double conicT = (double) (cIndex >> 1);
212 fIntersections->insert(conicT, lineT, fConic[cIndex]); 228 fIntersections->insert(conicT, lineT, fConic[cIndex]);
213 } 229 }
214 } 230 }
215 231
216 void addNearHorizontalEndPoints(double left, double right, double y) { 232 void addNearHorizontalEndPoints(double left, double right, double y) {
217 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) { 233 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) {
218 double conicT = (double) (cIndex >> 1); 234 double conicT = (double) (cIndex >> 1);
219 if (fIntersections->hasT(conicT)) { 235 if (fIntersections->hasT(conicT)) {
220 continue; 236 continue;
221 } 237 }
222 double lineT = SkDLine::NearPointH(fConic[cIndex], left, right, y); 238 double lineT = SkDLine::NearPointH(fConic[cIndex], left, right, y);
223 if (lineT < 0) { 239 if (lineT < 0) {
224 continue; 240 continue;
225 } 241 }
226 fIntersections->insert(conicT, lineT, fConic[cIndex]); 242 fIntersections->insert(conicT, lineT, fConic[cIndex]);
227 } 243 }
228 // FIXME: see if line end is nearly on conic 244 addLineNearEndPoints();
herb_g 2016/07/18 15:13:38 this->?
caryclark 2016/07/18 15:55:49 Done.
229 } 245 }
230 246
231 void addExactVerticalEndPoints(double top, double bottom, double x) { 247 void addExactVerticalEndPoints(double top, double bottom, double x) {
232 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) { 248 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) {
233 double lineT = SkDLine::ExactPointV(fConic[cIndex], top, bottom, x); 249 double lineT = SkDLine::ExactPointV(fConic[cIndex], top, bottom, x);
234 if (lineT < 0) { 250 if (lineT < 0) {
235 continue; 251 continue;
236 } 252 }
237 double conicT = (double) (cIndex >> 1); 253 double conicT = (double) (cIndex >> 1);
238 fIntersections->insert(conicT, lineT, fConic[cIndex]); 254 fIntersections->insert(conicT, lineT, fConic[cIndex]);
239 } 255 }
240 } 256 }
241 257
242 void addNearVerticalEndPoints(double top, double bottom, double x) { 258 void addNearVerticalEndPoints(double top, double bottom, double x) {
243 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) { 259 for (int cIndex = 0; cIndex < SkDConic::kPointCount; cIndex += SkDConic: :kPointLast) {
244 double conicT = (double) (cIndex >> 1); 260 double conicT = (double) (cIndex >> 1);
245 if (fIntersections->hasT(conicT)) { 261 if (fIntersections->hasT(conicT)) {
246 continue; 262 continue;
247 } 263 }
248 double lineT = SkDLine::NearPointV(fConic[cIndex], top, bottom, x); 264 double lineT = SkDLine::NearPointV(fConic[cIndex], top, bottom, x);
249 if (lineT < 0) { 265 if (lineT < 0) {
250 continue; 266 continue;
251 } 267 }
252 fIntersections->insert(conicT, lineT, fConic[cIndex]); 268 fIntersections->insert(conicT, lineT, fConic[cIndex]);
253 } 269 }
254 // FIXME: see if line end is nearly on conic 270 addLineNearEndPoints();
255 } 271 }
256 272
257 double findLineT(double t) { 273 double findLineT(double t) {
258 SkDPoint xy = fConic.ptAtT(t); 274 SkDPoint xy = fConic.ptAtT(t);
259 double dx = (*fLine)[1].fX - (*fLine)[0].fX; 275 double dx = (*fLine)[1].fX - (*fLine)[0].fX;
260 double dy = (*fLine)[1].fY - (*fLine)[0].fY; 276 double dy = (*fLine)[1].fY - (*fLine)[0].fY;
261 if (fabs(dx) > fabs(dy)) { 277 if (fabs(dx) > fabs(dy)) {
262 return (xy.fX - (*fLine)[0].fX) / dx; 278 return (xy.fX - (*fLine)[0].fX) / dx;
263 } 279 }
264 return (xy.fY - (*fLine)[0].fY) / dy; 280 return (xy.fY - (*fLine)[0].fY) / dy;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 377
362 int SkIntersections::HorizontalIntercept(const SkDConic& conic, SkScalar y, doub le* roots) { 378 int SkIntersections::HorizontalIntercept(const SkDConic& conic, SkScalar y, doub le* roots) {
363 LineConicIntersections c(conic); 379 LineConicIntersections c(conic);
364 return c.horizontalIntersect(y, roots); 380 return c.horizontalIntersect(y, roots);
365 } 381 }
366 382
367 int SkIntersections::VerticalIntercept(const SkDConic& conic, SkScalar x, double * roots) { 383 int SkIntersections::VerticalIntercept(const SkDConic& conic, SkScalar x, double * roots) {
368 LineConicIntersections c(conic); 384 LineConicIntersections c(conic);
369 return c.verticalIntersect(x, roots); 385 return c.verticalIntersect(x, roots);
370 } 386 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698