OLD | NEW |
1 // Another approach is to start with the implicit form of one curve and solve | 1 // Another approach is to start with the implicit form of one curve and solve |
2 // (seek implicit coefficients in QuadraticParameter.cpp | 2 // (seek implicit coefficients in QuadraticParameter.cpp |
3 // by substituting in the parametric form of the other. | 3 // by substituting in the parametric form of the other. |
4 // The downside of this approach is that early rejects are difficult to come by. | 4 // The downside of this approach is that early rejects are difficult to come by. |
5 // http://planetmath.org/encyclopedia/GaloisTheoreticDerivationOfTheQuarticFormu
la.html#step | 5 // http://planetmath.org/encyclopedia/GaloisTheoreticDerivationOfTheQuarticFormu
la.html#step |
6 | 6 |
7 | 7 |
8 #include "SkDQuadImplicit.h" | 8 #include "SkDQuadImplicit.h" |
9 #include "SkIntersections.h" | 9 #include "SkIntersections.h" |
10 #include "SkPathOpsLine.h" | 10 #include "SkPathOpsLine.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 static bool add_intercept(const SkDQuad& q1, const SkDQuad& q2, double tMin, dou
ble tMax, | 120 static bool add_intercept(const SkDQuad& q1, const SkDQuad& q2, double tMin, dou
ble tMax, |
121 SkIntersections* i, bool* subDivide) { | 121 SkIntersections* i, bool* subDivide) { |
122 double tMid = (tMin + tMax) / 2; | 122 double tMid = (tMin + tMax) / 2; |
123 SkDPoint mid = q2.xyAtT(tMid); | 123 SkDPoint mid = q2.xyAtT(tMid); |
124 SkDLine line; | 124 SkDLine line; |
125 line[0] = line[1] = mid; | 125 line[0] = line[1] = mid; |
126 SkDVector dxdy = q2.dxdyAtT(tMid); | 126 SkDVector dxdy = q2.dxdyAtT(tMid); |
127 line[0] -= dxdy; | 127 line[0] -= dxdy; |
128 line[1] += dxdy; | 128 line[1] += dxdy; |
129 SkIntersections rootTs; | 129 SkIntersections rootTs; |
| 130 rootTs.allowNear(false); |
130 int roots = rootTs.intersect(q1, line); | 131 int roots = rootTs.intersect(q1, line); |
131 if (roots == 0) { | 132 if (roots == 0) { |
132 if (subDivide) { | 133 if (subDivide) { |
133 *subDivide = true; | 134 *subDivide = true; |
134 } | 135 } |
135 return true; | 136 return true; |
136 } | 137 } |
137 if (roots == 2) { | 138 if (roots == 2) { |
138 return false; | 139 return false; |
139 } | 140 } |
140 SkDPoint pt2 = q1.xyAtT(rootTs[0][0]); | 141 SkDPoint pt2 = q1.xyAtT(rootTs[0][0]); |
141 if (!pt2.approximatelyEqualHalf(mid)) { | 142 if (!pt2.approximatelyEqualHalf(mid)) { |
142 return false; | 143 return false; |
143 } | 144 } |
144 i->insertSwap(rootTs[0][0], tMid, pt2); | 145 i->insertSwap(rootTs[0][0], tMid, pt2); |
145 return true; | 146 return true; |
146 } | 147 } |
147 | 148 |
148 static bool is_linear_inner(const SkDQuad& q1, double t1s, double t1e, const SkD
Quad& q2, | 149 static bool is_linear_inner(const SkDQuad& q1, double t1s, double t1e, const SkD
Quad& q2, |
149 double t2s, double t2e, SkIntersections* i, bool* su
bDivide) { | 150 double t2s, double t2e, SkIntersections* i, bool* su
bDivide) { |
150 SkDQuad hull = q1.subDivide(t1s, t1e); | 151 SkDQuad hull = q1.subDivide(t1s, t1e); |
151 SkDLine line = {{hull[2], hull[0]}}; | 152 SkDLine line = {{hull[2], hull[0]}}; |
152 const SkDLine* testLines[] = { &line, (const SkDLine*) &hull[0], (const SkDL
ine*) &hull[1] }; | 153 const SkDLine* testLines[] = { &line, (const SkDLine*) &hull[0], (const SkDL
ine*) &hull[1] }; |
153 const size_t kTestCount = SK_ARRAY_COUNT(testLines); | 154 const size_t kTestCount = SK_ARRAY_COUNT(testLines); |
154 SkSTArray<kTestCount * 2, double, true> tsFound; | 155 SkSTArray<kTestCount * 2, double, true> tsFound; |
155 for (size_t index = 0; index < kTestCount; ++index) { | 156 for (size_t index = 0; index < kTestCount; ++index) { |
156 SkIntersections rootTs; | 157 SkIntersections rootTs; |
| 158 rootTs.allowNear(false); |
157 int roots = rootTs.intersect(q2, *testLines[index]); | 159 int roots = rootTs.intersect(q2, *testLines[index]); |
158 for (int idx2 = 0; idx2 < roots; ++idx2) { | 160 for (int idx2 = 0; idx2 < roots; ++idx2) { |
159 double t = rootTs[0][idx2]; | 161 double t = rootTs[0][idx2]; |
160 #ifdef SK_DEBUG | 162 #ifdef SK_DEBUG |
161 SkDPoint qPt = q2.xyAtT(t); | 163 SkDPoint qPt = q2.xyAtT(t); |
162 SkDPoint lPt = testLines[index]->xyAtT(rootTs[1][idx2]); | 164 SkDPoint lPt = testLines[index]->xyAtT(rootTs[1][idx2]); |
163 SkASSERT(qPt.approximatelyEqual(lPt)); | 165 SkASSERT(qPt.approximatelyEqual(lPt)); |
164 #endif | 166 #endif |
165 if (approximately_negative(t - t2s) || approximately_positive(t - t2
e)) { | 167 if (approximately_negative(t - t2s) || approximately_positive(t - t2
e)) { |
166 continue; | 168 continue; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 } | 501 } |
500 if (lowestIndex < 0) { | 502 if (lowestIndex < 0) { |
501 break; | 503 break; |
502 } | 504 } |
503 insert(roots1Copy[lowestIndex], roots2Copy[closest[lowestIndex]], | 505 insert(roots1Copy[lowestIndex], roots2Copy[closest[lowestIndex]], |
504 pts1[lowestIndex]); | 506 pts1[lowestIndex]); |
505 closest[lowestIndex] = -1; | 507 closest[lowestIndex] = -1; |
506 } while (++used < r1Count); | 508 } while (++used < r1Count); |
507 return fUsed; | 509 return fUsed; |
508 } | 510 } |
OLD | NEW |