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

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

Issue 23542056: path ops work in progress (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: verbose + mutex around file number access Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkPathOpsCommon.cpp ('k') | src/pathops/SkPathOpsDebug.h » ('j') | 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 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 "SkLineParameters.h" 7 #include "SkLineParameters.h"
8 #include "SkPathOpsCubic.h" 8 #include "SkPathOpsCubic.h"
9 #include "SkPathOpsLine.h" 9 #include "SkPathOpsLine.h"
10 #include "SkPathOpsQuad.h" 10 #include "SkPathOpsQuad.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 if (approximately_zero(s[i])) { 148 if (approximately_zero(s[i])) {
149 return num; 149 return num;
150 } 150 }
151 } 151 }
152 s[num++] = 0; 152 s[num++] = 0;
153 return num; 153 return num;
154 } 154 }
155 if (approximately_zero(A + B + C + D)) { // 1 is one root 155 if (approximately_zero(A + B + C + D)) { // 1 is one root
156 int num = SkDQuad::RootsReal(A, A + B, -D, s); 156 int num = SkDQuad::RootsReal(A, A + B, -D, s);
157 for (int i = 0; i < num; ++i) { 157 for (int i = 0; i < num; ++i) {
158 if (AlmostEqualUlps(s[i], 1)) { 158 if (AlmostDequalUlps(s[i], 1)) {
159 return num; 159 return num;
160 } 160 }
161 } 161 }
162 s[num++] = 1; 162 s[num++] = 1;
163 return num; 163 return num;
164 } 164 }
165 double a, b, c; 165 double a, b, c;
166 { 166 {
167 double invA = 1 / A; 167 double invA = 1 / A;
168 a = B * invA; 168 a = B * invA;
(...skipping 10 matching lines...) Expand all
179 double r; 179 double r;
180 double* roots = s; 180 double* roots = s;
181 if (R2MinusQ3 < 0) { // we have 3 real roots 181 if (R2MinusQ3 < 0) { // we have 3 real roots
182 double theta = acos(R / sqrt(Q3)); 182 double theta = acos(R / sqrt(Q3));
183 double neg2RootQ = -2 * sqrt(Q); 183 double neg2RootQ = -2 * sqrt(Q);
184 184
185 r = neg2RootQ * cos(theta / 3) - adiv3; 185 r = neg2RootQ * cos(theta / 3) - adiv3;
186 *roots++ = r; 186 *roots++ = r;
187 187
188 r = neg2RootQ * cos((theta + 2 * PI) / 3) - adiv3; 188 r = neg2RootQ * cos((theta + 2 * PI) / 3) - adiv3;
189 if (!AlmostEqualUlps(s[0], r)) { 189 if (!AlmostDequalUlps(s[0], r)) {
190 *roots++ = r; 190 *roots++ = r;
191 } 191 }
192 r = neg2RootQ * cos((theta - 2 * PI) / 3) - adiv3; 192 r = neg2RootQ * cos((theta - 2 * PI) / 3) - adiv3;
193 if (!AlmostEqualUlps(s[0], r) && (roots - s == 1 || !AlmostEqualUlps(s[1 ], r))) { 193 if (!AlmostDequalUlps(s[0], r) && (roots - s == 1 || !AlmostDequalUlps(s [1], r))) {
194 *roots++ = r; 194 *roots++ = r;
195 } 195 }
196 } else { // we have 1 real root 196 } else { // we have 1 real root
197 double sqrtR2MinusQ3 = sqrt(R2MinusQ3); 197 double sqrtR2MinusQ3 = sqrt(R2MinusQ3);
198 double A = fabs(R) + sqrtR2MinusQ3; 198 double A = fabs(R) + sqrtR2MinusQ3;
199 A = SkDCubeRoot(A); 199 A = SkDCubeRoot(A);
200 if (R > 0) { 200 if (R > 0) {
201 A = -A; 201 A = -A;
202 } 202 }
203 if (A != 0) { 203 if (A != 0) {
204 A += Q / A; 204 A += Q / A;
205 } 205 }
206 r = A - adiv3; 206 r = A - adiv3;
207 *roots++ = r; 207 *roots++ = r;
208 if (AlmostEqualUlps(R2, Q3)) { 208 if (AlmostDequalUlps(R2, Q3)) {
209 r = -A / 2 - adiv3; 209 r = -A / 2 - adiv3;
210 if (!AlmostEqualUlps(s[0], r)) { 210 if (!AlmostDequalUlps(s[0], r)) {
211 *roots++ = r; 211 *roots++ = r;
212 } 212 }
213 } 213 }
214 } 214 }
215 return static_cast<int>(roots - s); 215 return static_cast<int>(roots - s);
216 } 216 }
217 217
218 // from http://www.cs.sunysb.edu/~qin/courses/geometry/4.pdf 218 // from http://www.cs.sunysb.edu/~qin/courses/geometry/4.pdf
219 // c(t) = a(1-t)^3 + 3bt(1-t)^2 + 3c(1-t)t^2 + dt^3 219 // c(t) = a(1-t)^3 + 3bt(1-t)^2 + 3c(1-t)t^2 + dt^3
220 // c'(t) = -3a(1-t)^2 + 3b((1-t)^2 - 2t(1-t)) + 3c(2t(1-t) - t^2) + 3dt^2 220 // c'(t) = -3a(1-t)^2 + 3b((1-t)^2 - 2t(1-t)) + 3c(2t(1-t) - t^2) + 3dt^2
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 SkDebugf("{{"); 514 SkDebugf("{{");
515 int index = 0; 515 int index = 0;
516 do { 516 do {
517 fPts[index].dump(); 517 fPts[index].dump();
518 SkDebugf(", "); 518 SkDebugf(", ");
519 } while (++index < 3); 519 } while (++index < 3);
520 fPts[index].dump(); 520 fPts[index].dump();
521 SkDebugf("}}\n"); 521 SkDebugf("}}\n");
522 } 522 }
523 #endif 523 #endif
OLDNEW
« no previous file with comments | « src/pathops/SkPathOpsCommon.cpp ('k') | src/pathops/SkPathOpsDebug.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698