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

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

Issue 1408923003: Revert of path ops: fix conic weight and partial coincidence (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/pathops/SkPathOpsConic.h ('k') | src/pathops/SkPathOpsCubic.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 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 "SkLineParameters.h" 8 #include "SkLineParameters.h"
9 #include "SkPathOpsConic.h" 9 #include "SkPathOpsConic.h"
10 #include "SkPathOpsCubic.h" 10 #include "SkPathOpsCubic.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return fPts[2]; 89 return fPts[2];
90 } 90 }
91 double denominator = conic_eval_denominator(fWeight, t); 91 double denominator = conic_eval_denominator(fWeight, t);
92 SkDPoint result = { 92 SkDPoint result = {
93 conic_eval_numerator(&fPts[0].fX, fWeight, t) / denominator, 93 conic_eval_numerator(&fPts[0].fX, fWeight, t) / denominator,
94 conic_eval_numerator(&fPts[0].fY, fWeight, t) / denominator 94 conic_eval_numerator(&fPts[0].fY, fWeight, t) / denominator
95 }; 95 };
96 return result; 96 return result;
97 } 97 }
98 98
99 /* see quad subdivide for point rationale */ 99 /* see quad subdivide for rationale */
100 /* w rationale : the mid point between t1 and t2 could be determined from the co mputed a/b/c
101 values if the computed w was known. Since we know the mid point at (t1+t2)/2, we'll assume
102 that it is the same as the point on the new curve t==(0+1)/2.
103
104 d / dz == conic_poly(dst, unknownW, .5) / conic_weight(unknownW, .5);
105
106 conic_poly(dst, unknownW, .5)
107 = a / 4 + (b * unknownW) / 2 + c / 4
108 = (a + c) / 4 + (bx * unknownW) / 2
109
110 conic_weight(unknownW, .5)
111 = unknownW / 2 + 1 / 2
112
113 d / dz == ((a + c) / 2 + b * unknownW) / (unknownW + 1)
114 d / dz * (unknownW + 1) == (a + c) / 2 + b * unknownW
115 unknownW = ((a + c) / 2 - d / dz) / (d / dz - b)
116
117 Thus, w is the ratio of the distance from the mid of end points to the on-cu rve point, and the
118 distance of the on-curve point to the control point.
119 */
120 SkDConic SkDConic::subDivide(double t1, double t2) const { 100 SkDConic SkDConic::subDivide(double t1, double t2) const {
121 double ax, ay, az; 101 double ax, ay, az;
122 if (t1 == 0) { 102 if (t1 == 0) {
123 ax = fPts[0].fX; 103 ax = fPts[0].fX;
124 ay = fPts[0].fY; 104 ay = fPts[0].fY;
125 az = 1; 105 az = 1;
126 } else if (t1 != 1) { 106 } else if (t1 != 1) {
127 ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1); 107 ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1);
128 ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1); 108 ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1);
129 az = conic_eval_denominator(fWeight, t1); 109 az = conic_eval_denominator(fWeight, t1);
(...skipping 16 matching lines...) Expand all
146 cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2); 126 cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2);
147 cz = conic_eval_denominator(fWeight, t2); 127 cz = conic_eval_denominator(fWeight, t2);
148 } else { 128 } else {
149 cx = fPts[0].fX; 129 cx = fPts[0].fX;
150 cy = fPts[0].fY; 130 cy = fPts[0].fY;
151 cz = 1; 131 cz = 1;
152 } 132 }
153 double bx = 2 * dx - (ax + cx) / 2; 133 double bx = 2 * dx - (ax + cx) / 2;
154 double by = 2 * dy - (ay + cy) / 2; 134 double by = 2 * dy - (ay + cy) / 2;
155 double bz = 2 * dz - (az + cz) / 2; 135 double bz = 2 * dz - (az + cz) / 2;
156 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz} }}, 0 }; 136 double dt = t2 - t1;
157 SkDPoint dMidAC = { (dst.fPts[0].fX + dst.fPts[2].fX) / 2, 137 double dt_1 = 1 - dt;
158 (dst.fPts[0].fY + dst.fPts[2].fY) / 2 }; 138 SkScalar w = SkDoubleToScalar((1 + dt * (fWeight - 1))
159 SkDPoint dMid = { dx / dz, dy / dz }; 139 / sqrt(dt * dt + 2 * dt * dt_1 * fWeight + dt_1 * dt_1));
160 SkDVector dWNumer = dMidAC - dMid; 140 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz} }}, w };
161 SkDVector dWDenom = dMid - dst.fPts[1];
162 dst.fWeight = dWNumer.length() / dWDenom.length();
163 return dst; 141 return dst;
164 } 142 }
165 143
166 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do uble t2, 144 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do uble t2,
167 SkScalar* weight) const { 145 SkScalar* weight) const {
168 SkDConic chopped = this->subDivide(t1, t2); 146 SkDConic chopped = this->subDivide(t1, t2);
169 *weight = chopped.fWeight; 147 *weight = chopped.fWeight;
170 return chopped[1]; 148 return chopped[1];
171 } 149 }
OLDNEW
« no previous file with comments | « src/pathops/SkPathOpsConic.h ('k') | src/pathops/SkPathOpsCubic.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698