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

Side by Side Diff: src/pathops/SkPathOpsTSect.h

Issue 1097293002: fix valgrind uninitialized var error (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 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 7
8 #include "SkChunkAlloc.h" 8 #include "SkChunkAlloc.h"
9 #include "SkPathOpsBounds.h" 9 #include "SkPathOpsBounds.h"
10 #include "SkPathOpsRect.h" 10 #include "SkPathOpsRect.h"
11 #include "SkIntersections.h" 11 #include "SkIntersections.h"
12 #include "SkTSort.h" 12 #include "SkTSort.h"
13 13
14 /* TCurve and OppCurve are one of { SkDQuadratic, SkDConic, SkDCubic } */ 14 /* TCurve and OppCurve are one of { SkDQuadratic, SkDConic, SkDCubic } */
15 template<typename TCurve, typename OppCurve> 15 template<typename TCurve, typename OppCurve>
16 class SkTCoincident { 16 class SkTCoincident {
17 public: 17 public:
18 SkTCoincident() { 18 SkTCoincident() {
19 this->clear(); 19 this->init();
20 }
21
22 void clear() {
23 fPerpT = -1;
24 fCoincident = false;
25 }
26
27 void debugInit() {
28 this->clear();
29 fPerpPt.fX = fPerpPt.fY = SK_ScalarNaN;
30 } 20 }
31 21
32 void dump() const; 22 void dump() const;
33 23
34 bool isCoincident() const { 24 bool isCoincident() const {
35 return fCoincident; 25 return fCoincident;
36 } 26 }
37 27
38 void init() { 28 void init() {
39 this->clear(); 29 fPerpT = -1;
40 SkDEBUGCODE(fPerpPt.fX = fPerpPt.fY = SK_ScalarNaN); 30 fCoincident = false;
31 fPerpPt.fX = fPerpPt.fY = SK_ScalarNaN;
41 } 32 }
42 33
43 void markCoincident() { 34 void markCoincident() {
44 if (!fCoincident) { 35 if (!fCoincident) {
45 fPerpT = -1; 36 fPerpT = -1;
46 } 37 }
47 fCoincident = true; 38 fCoincident = true;
48 } 39 }
49 40
50 const SkDPoint& perpPt() const { 41 const SkDPoint& perpPt() const {
(...skipping 27 matching lines...) Expand all
78 public: 69 public:
79 void addBounded(SkTSpan<OppCurve, TCurve>* , SkChunkAlloc* ); 70 void addBounded(SkTSpan<OppCurve, TCurve>* , SkChunkAlloc* );
80 double closestBoundedT(const SkDPoint& pt) const; 71 double closestBoundedT(const SkDPoint& pt) const;
81 bool contains(double t) const; 72 bool contains(double t) const;
82 73
83 void debugInit() { 74 void debugInit() {
84 TCurve dummy; 75 TCurve dummy;
85 dummy.debugInit(); 76 dummy.debugInit();
86 init(dummy); 77 init(dummy);
87 initBounds(dummy); 78 initBounds(dummy);
88 fCoinStart.debugInit(); 79 fCoinStart.init();
89 fCoinEnd.debugInit(); 80 fCoinEnd.init();
90 } 81 }
91 82
92 const SkTSect<OppCurve, TCurve>* debugOpp() const; 83 const SkTSect<OppCurve, TCurve>* debugOpp() const;
93 const SkTSpan* debugSpan(int ) const; 84 const SkTSpan* debugSpan(int ) const;
94 const SkTSpan* debugT(double t) const; 85 const SkTSpan* debugT(double t) const;
95 #ifdef SK_DEBUG 86 #ifdef SK_DEBUG
96 bool debugIsBefore(const SkTSpan* span) const; 87 bool debugIsBefore(const SkTSpan* span) const;
97 #endif 88 #endif
98 void dump() const; 89 void dump() const;
99 void dumpBounded(int id) const; 90 void dumpBounded(int id) const;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 313
323 template<typename TCurve, typename OppCurve> 314 template<typename TCurve, typename OppCurve>
324 void SkTCoincident<TCurve, OppCurve>::setPerp(const TCurve& c1, double t, 315 void SkTCoincident<TCurve, OppCurve>::setPerp(const TCurve& c1, double t,
325 const SkDPoint& cPt, const OppCurve& c2) { 316 const SkDPoint& cPt, const OppCurve& c2) {
326 SkDVector dxdy = c1.dxdyAtT(t); 317 SkDVector dxdy = c1.dxdyAtT(t);
327 SkDLine perp = {{ cPt, {cPt.fX + dxdy.fY, cPt.fY - dxdy.fX} }}; 318 SkDLine perp = {{ cPt, {cPt.fX + dxdy.fY, cPt.fY - dxdy.fX} }};
328 SkIntersections i; 319 SkIntersections i;
329 int used = i.intersectRay(c2, perp); 320 int used = i.intersectRay(c2, perp);
330 // only keep closest 321 // only keep closest
331 if (used == 0 || used == 3) { 322 if (used == 0 || used == 3) {
332 this->clear(); 323 this->init();
333 return; 324 return;
334 } 325 }
335 fPerpT = i[0][0]; 326 fPerpT = i[0][0];
336 fPerpPt = i.pt(0); 327 fPerpPt = i.pt(0);
337 SkASSERT(used <= 2); 328 SkASSERT(used <= 2);
338 if (used == 2) { 329 if (used == 2) {
339 double distSq = (fPerpPt - cPt).lengthSquared(); 330 double distSq = (fPerpPt - cPt).lengthSquared();
340 double dist2Sq = (i.pt(1) - cPt).lengthSquared(); 331 double dist2Sq = (i.pt(1) - cPt).lengthSquared();
341 if (dist2Sq < distSq) { 332 if (dist2Sq < distSq) {
342 fPerpT = i[0][1]; 333 fPerpT = i[0][1];
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 do { 977 do {
987 if (!work->fHasPerp && !work->fCollapsed) { 978 if (!work->fHasPerp && !work->fCollapsed) {
988 if (prior) { 979 if (prior) {
989 work->fCoinStart = prior->fCoinEnd; 980 work->fCoinStart = prior->fCoinEnd;
990 } else { 981 } else {
991 work->fCoinStart.setPerp(fCurve, work->fStartT, work->fPart[0], opp); 982 work->fCoinStart.setPerp(fCurve, work->fStartT, work->fPart[0], opp);
992 } 983 }
993 if (work->fCoinStart.isCoincident()) { 984 if (work->fCoinStart.isCoincident()) {
994 double perpT = work->fCoinStart.perpT(); 985 double perpT = work->fCoinStart.perpT();
995 if (sect2->coincidentHasT(perpT)) { 986 if (sect2->coincidentHasT(perpT)) {
996 work->fCoinStart.clear(); 987 work->fCoinStart.init();
997 } else { 988 } else {
998 sect2->addForPerp(work, perpT); 989 sect2->addForPerp(work, perpT);
999 } 990 }
1000 } 991 }
1001 work->fCoinEnd.setPerp(fCurve, work->fEndT, work->fPart[TCurve::kPoi ntLast], opp); 992 work->fCoinEnd.setPerp(fCurve, work->fEndT, work->fPart[TCurve::kPoi ntLast], opp);
1002 if (work->fCoinEnd.isCoincident()) { 993 if (work->fCoinEnd.isCoincident()) {
1003 double perpT = work->fCoinEnd.perpT(); 994 double perpT = work->fCoinEnd.perpT();
1004 if (sect2->coincidentHasT(perpT)) { 995 if (sect2->coincidentHasT(perpT)) {
1005 work->fCoinEnd.clear(); 996 work->fCoinEnd.init();
1006 } else { 997 } else {
1007 sect2->addForPerp(work, perpT); 998 sect2->addForPerp(work, perpT);
1008 } 999 }
1009 } 1000 }
1010 work->fHasPerp = true; 1001 work->fHasPerp = true;
1011 } 1002 }
1012 if (work == last) { 1003 if (work == last) {
1013 break; 1004 break;
1014 } 1005 }
1015 prior = work; 1006 prior = work;
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 } else if (intersections->isCoincident(index + 1)) { 2086 } else if (intersections->isCoincident(index + 1)) {
2096 intersections->removeOne(index + 1); 2087 intersections->removeOne(index + 1);
2097 --last; 2088 --last;
2098 } else { 2089 } else {
2099 intersections->setCoincident(index++); 2090 intersections->setCoincident(index++);
2100 } 2091 }
2101 intersections->setCoincident(index); 2092 intersections->setCoincident(index);
2102 } 2093 }
2103 SkASSERT(intersections->used() <= TCurve::kMaxIntersections); 2094 SkASSERT(intersections->used() <= TCurve::kMaxIntersections);
2104 } 2095 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698