OLD | NEW |
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 Loading... |
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 rationale */ | 99 /* see quad subdivide for point 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 */ |
100 SkDConic SkDConic::subDivide(double t1, double t2) const { | 120 SkDConic SkDConic::subDivide(double t1, double t2) const { |
101 double ax, ay, az; | 121 double ax, ay, az; |
102 if (t1 == 0) { | 122 if (t1 == 0) { |
103 ax = fPts[0].fX; | 123 ax = fPts[0].fX; |
104 ay = fPts[0].fY; | 124 ay = fPts[0].fY; |
105 az = 1; | 125 az = 1; |
106 } else if (t1 != 1) { | 126 } else if (t1 != 1) { |
107 ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1); | 127 ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1); |
108 ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1); | 128 ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1); |
109 az = conic_eval_denominator(fWeight, t1); | 129 az = conic_eval_denominator(fWeight, t1); |
(...skipping 16 matching lines...) Expand all Loading... |
126 cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2); | 146 cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2); |
127 cz = conic_eval_denominator(fWeight, t2); | 147 cz = conic_eval_denominator(fWeight, t2); |
128 } else { | 148 } else { |
129 cx = fPts[0].fX; | 149 cx = fPts[0].fX; |
130 cy = fPts[0].fY; | 150 cy = fPts[0].fY; |
131 cz = 1; | 151 cz = 1; |
132 } | 152 } |
133 double bx = 2 * dx - (ax + cx) / 2; | 153 double bx = 2 * dx - (ax + cx) / 2; |
134 double by = 2 * dy - (ay + cy) / 2; | 154 double by = 2 * dy - (ay + cy) / 2; |
135 double bz = 2 * dz - (az + cz) / 2; | 155 double bz = 2 * dz - (az + cz) / 2; |
136 double dt = t2 - t1; | 156 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz}
}}, 0 }; |
137 double dt_1 = 1 - dt; | 157 SkDPoint dMidAC = { (dst.fPts[0].fX + dst.fPts[2].fX) / 2, |
138 SkScalar w = SkDoubleToScalar((1 + dt * (fWeight - 1)) | 158 (dst.fPts[0].fY + dst.fPts[2].fY) / 2 }; |
139 / sqrt(dt * dt + 2 * dt * dt_1 * fWeight + dt_1 * dt_1)); | 159 SkDPoint dMid = { dx / dz, dy / dz }; |
140 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz}
}}, w }; | 160 SkDVector dWNumer = dMidAC - dMid; |
| 161 SkDVector dWDenom = dMid - dst.fPts[1]; |
| 162 dst.fWeight = dWNumer.length() / dWDenom.length(); |
141 return dst; | 163 return dst; |
142 } | 164 } |
143 | 165 |
144 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do
uble t2, | 166 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do
uble t2, |
145 SkScalar* weight) const { | 167 SkScalar* weight) const { |
146 SkDConic chopped = this->subDivide(t1, t2); | 168 SkDConic chopped = this->subDivide(t1, t2); |
147 *weight = chopped.fWeight; | 169 *weight = chopped.fWeight; |
148 return chopped[1]; | 170 return chopped[1]; |
149 } | 171 } |
OLD | NEW |