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 "SkPathOpsCubic.h" | 8 #include "SkPathOpsCubic.h" |
9 #include "SkPathOpsLine.h" | 9 #include "SkPathOpsLine.h" |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 enum PinTPoint { | 79 enum PinTPoint { |
80 kPointUninitialized, | 80 kPointUninitialized, |
81 kPointInitialized | 81 kPointInitialized |
82 }; | 82 }; |
83 | 83 |
84 LineCubicIntersections(const SkDCubic& c, const SkDLine& l, SkIntersections*
i) | 84 LineCubicIntersections(const SkDCubic& c, const SkDLine& l, SkIntersections*
i) |
85 : fCubic(c) | 85 : fCubic(c) |
86 , fLine(l) | 86 , fLine(l) |
87 , fIntersections(i) | 87 , fIntersections(i) |
88 , fAllowNear(true) { | 88 , fAllowNear(true) { |
| 89 i->setMax(3); |
89 } | 90 } |
90 | 91 |
91 void allowNear(bool allow) { | 92 void allowNear(bool allow) { |
92 fAllowNear = allow; | 93 fAllowNear = allow; |
93 } | 94 } |
94 | 95 |
95 // see parallel routine in line quadratic intersections | 96 // see parallel routine in line quadratic intersections |
96 int intersectRay(double roots[3]) { | 97 int intersectRay(double roots[3]) { |
97 double adj = fLine[1].fX - fLine[0].fX; | 98 double adj = fLine[1].fX - fLine[0].fX; |
98 double opp = fLine[1].fY - fLine[0].fY; | 99 double opp = fLine[1].fY - fLine[0].fY; |
(...skipping 16 matching lines...) Expand all Loading... |
115 for (int index = 0; index < roots; ++index) { | 116 for (int index = 0; index < roots; ++index) { |
116 double cubicT = rootVals[index]; | 117 double cubicT = rootVals[index]; |
117 double lineT = findLineT(cubicT); | 118 double lineT = findLineT(cubicT); |
118 SkDPoint pt; | 119 SkDPoint pt; |
119 if (pinTs(&cubicT, &lineT, &pt, kPointUninitialized)) { | 120 if (pinTs(&cubicT, &lineT, &pt, kPointUninitialized)) { |
120 #if ONE_OFF_DEBUG | 121 #if ONE_OFF_DEBUG |
121 SkDPoint cPt = fCubic.ptAtT(cubicT); | 122 SkDPoint cPt = fCubic.ptAtT(cubicT); |
122 SkDebugf("%s pt=(%1.9g,%1.9g) cPt=(%1.9g,%1.9g)\n", __FUNCTION__
, pt.fX, pt.fY, | 123 SkDebugf("%s pt=(%1.9g,%1.9g) cPt=(%1.9g,%1.9g)\n", __FUNCTION__
, pt.fX, pt.fY, |
123 cPt.fX, cPt.fY); | 124 cPt.fX, cPt.fY); |
124 #endif | 125 #endif |
| 126 for (int inner = 0; inner < fIntersections->used(); ++inner) { |
| 127 if (fIntersections->pt(inner) != pt) { |
| 128 continue; |
| 129 } |
| 130 double existingCubicT = (*fIntersections)[0][inner]; |
| 131 if (cubicT == existingCubicT) { |
| 132 goto skipInsert; |
| 133 } |
| 134 // check if midway on cubic is also same point. If so, disca
rd this |
| 135 double cubicMidT = (existingCubicT + cubicT) / 2; |
| 136 SkDPoint cubicMidPt = fCubic.ptAtT(cubicMidT); |
| 137 if (cubicMidPt.approximatelyEqual(pt)) { |
| 138 goto skipInsert; |
| 139 } |
| 140 } |
125 fIntersections->insert(cubicT, lineT, pt); | 141 fIntersections->insert(cubicT, lineT, pt); |
| 142 skipInsert: |
| 143 ; |
126 } | 144 } |
127 } | 145 } |
128 return fIntersections->used(); | 146 return fIntersections->used(); |
129 } | 147 } |
130 | 148 |
131 int horizontalIntersect(double axisIntercept, double roots[3]) { | 149 int horizontalIntersect(double axisIntercept, double roots[3]) { |
132 double A, B, C, D; | 150 double A, B, C, D; |
133 SkDCubic::Coefficients(&fCubic[0].fY, &A, &B, &C, &D); | 151 SkDCubic::Coefficients(&fCubic[0].fY, &A, &B, &C, &D); |
134 D -= axisIntercept; | 152 D -= axisIntercept; |
135 return SkDCubic::RootsValidT(A, B, C, D, roots); | 153 return SkDCubic::RootsValidT(A, B, C, D, roots); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 } | 347 } |
330 | 348 |
331 int SkIntersections::intersectRay(const SkDCubic& cubic, const SkDLine& line) { | 349 int SkIntersections::intersectRay(const SkDCubic& cubic, const SkDLine& line) { |
332 LineCubicIntersections c(cubic, line, this); | 350 LineCubicIntersections c(cubic, line, this); |
333 fUsed = c.intersectRay(fT[0]); | 351 fUsed = c.intersectRay(fT[0]); |
334 for (int index = 0; index < fUsed; ++index) { | 352 for (int index = 0; index < fUsed; ++index) { |
335 fPt[index] = cubic.ptAtT(fT[0][index]); | 353 fPt[index] = cubic.ptAtT(fT[0][index]); |
336 } | 354 } |
337 return fUsed; | 355 return fUsed; |
338 } | 356 } |
OLD | NEW |