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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 SkDPoint SkDConic::ptAtT(double t) const { | 76 SkDPoint SkDConic::ptAtT(double t) const { |
77 double denominator = conic_eval_denominator(fWeight, t); | 77 double denominator = conic_eval_denominator(fWeight, t); |
78 SkDPoint result = { | 78 SkDPoint result = { |
79 conic_eval_numerator(&fPts[0].fX, fWeight, t) / denominator, | 79 conic_eval_numerator(&fPts[0].fX, fWeight, t) / denominator, |
80 conic_eval_numerator(&fPts[0].fY, fWeight, t) / denominator | 80 conic_eval_numerator(&fPts[0].fY, fWeight, t) / denominator |
81 }; | 81 }; |
82 return result; | 82 return result; |
83 } | 83 } |
84 | 84 |
85 SkDPoint SkDConic::top(double startT, double endT) const { | |
86 SkDConic sub = subDivide(startT, endT); | |
87 SkDPoint topPt = sub[0]; | |
88 if (topPt.fY > sub[2].fY || (topPt.fY == sub[2].fY && topPt.fX > sub[2].fX))
{ | |
89 topPt = sub[2]; | |
90 } | |
91 if (!between(sub[0].fY, sub[1].fY, sub[2].fY)) { | |
92 double extremeT; | |
93 if (FindExtrema(&sub[0].fY, sub.fWeight, &extremeT)) { | |
94 extremeT = startT + (endT - startT) * extremeT; | |
95 SkDPoint test = ptAtT(extremeT); | |
96 if (topPt.fY > test.fY || (topPt.fY == test.fY && topPt.fX > test.fX
)) { | |
97 topPt = test; | |
98 } | |
99 } | |
100 } | |
101 return topPt; | |
102 } | |
103 | |
104 /* see quad subdivide for rationale */ | 85 /* see quad subdivide for rationale */ |
105 SkDConic SkDConic::subDivide(double t1, double t2) const { | 86 SkDConic SkDConic::subDivide(double t1, double t2) const { |
106 double ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1); | 87 double ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1); |
107 double ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1); | 88 double ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1); |
108 double az = conic_eval_denominator(fWeight, t1); | 89 double az = conic_eval_denominator(fWeight, t1); |
109 double midT = (t1 + t2) / 2; | 90 double midT = (t1 + t2) / 2; |
110 double dx = conic_eval_numerator(&fPts[0].fX, fWeight, midT); | 91 double dx = conic_eval_numerator(&fPts[0].fX, fWeight, midT); |
111 double dy = conic_eval_numerator(&fPts[0].fY, fWeight, midT); | 92 double dy = conic_eval_numerator(&fPts[0].fY, fWeight, midT); |
112 double dz = conic_eval_denominator(fWeight, midT); | 93 double dz = conic_eval_denominator(fWeight, midT); |
113 double cx = conic_eval_numerator(&fPts[0].fX, fWeight, t2); | 94 double cx = conic_eval_numerator(&fPts[0].fX, fWeight, t2); |
114 double cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2); | 95 double cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2); |
115 double cz = conic_eval_denominator(fWeight, t2); | 96 double cz = conic_eval_denominator(fWeight, t2); |
116 double bx = 2 * dx - (ax + cx) / 2; | 97 double bx = 2 * dx - (ax + cx) / 2; |
117 double by = 2 * dy - (ay + cy) / 2; | 98 double by = 2 * dy - (ay + cy) / 2; |
118 double bz = 2 * dz - (az + cz) / 2; | 99 double bz = 2 * dz - (az + cz) / 2; |
119 double dt = t2 - t1; | 100 double dt = t2 - t1; |
120 double dt_1 = 1 - dt; | 101 double dt_1 = 1 - dt; |
121 SkScalar w = SkDoubleToScalar((1 + dt * (fWeight - 1)) | 102 SkScalar w = SkDoubleToScalar((1 + dt * (fWeight - 1)) |
122 / sqrt(dt * dt + 2 * dt * dt_1 * fWeight + dt_1 * dt_1)); | 103 / sqrt(dt * dt + 2 * dt * dt_1 * fWeight + dt_1 * dt_1)); |
123 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz}
}}, w }; | 104 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz}
}}, w }; |
124 return dst; | 105 return dst; |
125 } | 106 } |
126 | 107 |
127 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do
uble t2, | 108 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do
uble t2, |
128 SkScalar* weight) const { | 109 SkScalar* weight) const { |
129 SkDConic chopped = this->subDivide(t1, t2); | 110 SkDConic chopped = this->subDivide(t1, t2); |
130 *weight = chopped.fWeight; | 111 *weight = chopped.fWeight; |
131 return chopped[1]; | 112 return chopped[1]; |
132 } | 113 } |
| 114 |
| 115 SkDPoint SkDConic::top(double startT, double endT, double* topT) const { |
| 116 SkDConic sub = subDivide(startT, endT); |
| 117 SkDPoint topPt = sub[0]; |
| 118 *topT = startT; |
| 119 if (topPt.fY > sub[2].fY || (topPt.fY == sub[2].fY && topPt.fX > sub[2].fX))
{ |
| 120 *topT = endT; |
| 121 topPt = sub[2]; |
| 122 } |
| 123 if (!between(sub[0].fY, sub[1].fY, sub[2].fY)) { |
| 124 double extremeT; |
| 125 if (FindExtrema(&sub[0].fY, sub.fWeight, &extremeT)) { |
| 126 extremeT = startT + (endT - startT) * extremeT; |
| 127 SkDPoint test = ptAtT(extremeT); |
| 128 if (topPt.fY > test.fY || (topPt.fY == test.fY && topPt.fX > test.fX
)) { |
| 129 *topT = extremeT; |
| 130 topPt = test; |
| 131 } |
| 132 } |
| 133 } |
| 134 return topPt; |
| 135 } |
OLD | NEW |