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

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

Issue 1259513004: compute split conic endpoints exactly (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | tests/PathOpsSimplifyTest.cpp » ('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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 double C = 1; 67 double C = 1;
68 double A = -B; 68 double A = -B;
69 return (A * t + B) * t + C; 69 return (A * t + B) * t + C;
70 } 70 }
71 71
72 bool SkDConic::hullIntersects(const SkDCubic& cubic, bool* isLinear) const { 72 bool SkDConic::hullIntersects(const SkDCubic& cubic, bool* isLinear) const {
73 return cubic.hullIntersects(*this, isLinear); 73 return cubic.hullIntersects(*this, isLinear);
74 } 74 }
75 75
76 SkDPoint SkDConic::ptAtT(double t) const { 76 SkDPoint SkDConic::ptAtT(double t) const {
77 if (t == 0) {
78 return fPts[0];
79 }
80 if (t == 1) {
81 return fPts[2];
82 }
77 double denominator = conic_eval_denominator(fWeight, t); 83 double denominator = conic_eval_denominator(fWeight, t);
78 SkDPoint result = { 84 SkDPoint result = {
79 conic_eval_numerator(&fPts[0].fX, fWeight, t) / denominator, 85 conic_eval_numerator(&fPts[0].fX, fWeight, t) / denominator,
80 conic_eval_numerator(&fPts[0].fY, fWeight, t) / denominator 86 conic_eval_numerator(&fPts[0].fY, fWeight, t) / denominator
81 }; 87 };
82 return result; 88 return result;
83 } 89 }
84 90
85 /* see quad subdivide for rationale */ 91 /* see quad subdivide for rationale */
86 SkDConic SkDConic::subDivide(double t1, double t2) const { 92 SkDConic SkDConic::subDivide(double t1, double t2) const {
87 double ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1); 93 double ax, ay, az;
88 double ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1); 94 if (t1 == 0) {
89 double az = conic_eval_denominator(fWeight, t1); 95 ax = fPts[0].fX;
96 ay = fPts[0].fY;
97 az = 1;
98 } else if (t1 != 1) {
99 ax = conic_eval_numerator(&fPts[0].fX, fWeight, t1);
100 ay = conic_eval_numerator(&fPts[0].fY, fWeight, t1);
101 az = conic_eval_denominator(fWeight, t1);
102 } else {
103 ax = fPts[2].fX;
104 ay = fPts[2].fY;
105 az = 1;
106 }
90 double midT = (t1 + t2) / 2; 107 double midT = (t1 + t2) / 2;
91 double dx = conic_eval_numerator(&fPts[0].fX, fWeight, midT); 108 double dx = conic_eval_numerator(&fPts[0].fX, fWeight, midT);
92 double dy = conic_eval_numerator(&fPts[0].fY, fWeight, midT); 109 double dy = conic_eval_numerator(&fPts[0].fY, fWeight, midT);
93 double dz = conic_eval_denominator(fWeight, midT); 110 double dz = conic_eval_denominator(fWeight, midT);
94 double cx = conic_eval_numerator(&fPts[0].fX, fWeight, t2); 111 double cx, cy, cz;
95 double cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2); 112 if (t2 == 1) {
96 double cz = conic_eval_denominator(fWeight, t2); 113 cx = fPts[2].fX;
114 cy = fPts[2].fY;
115 cz = 1;
116 } else if (t2 != 0) {
117 cx = conic_eval_numerator(&fPts[0].fX, fWeight, t2);
118 cy = conic_eval_numerator(&fPts[0].fY, fWeight, t2);
119 cz = conic_eval_denominator(fWeight, t2);
120 } else {
121 cx = fPts[0].fX;
122 cy = fPts[0].fY;
123 cz = 1;
124 }
97 double bx = 2 * dx - (ax + cx) / 2; 125 double bx = 2 * dx - (ax + cx) / 2;
98 double by = 2 * dy - (ay + cy) / 2; 126 double by = 2 * dy - (ay + cy) / 2;
99 double bz = 2 * dz - (az + cz) / 2; 127 double bz = 2 * dz - (az + cz) / 2;
100 double dt = t2 - t1; 128 double dt = t2 - t1;
101 double dt_1 = 1 - dt; 129 double dt_1 = 1 - dt;
102 SkScalar w = SkDoubleToScalar((1 + dt * (fWeight - 1)) 130 SkScalar w = SkDoubleToScalar((1 + dt * (fWeight - 1))
103 / sqrt(dt * dt + 2 * dt * dt_1 * fWeight + dt_1 * dt_1)); 131 / sqrt(dt * dt + 2 * dt * dt_1 * fWeight + dt_1 * dt_1));
104 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz} }}, w }; 132 SkDConic dst = {{{{ax / az, ay / az}, {bx / bz, by / bz}, {cx / cz, cy / cz} }}, w };
105 return dst; 133 return dst;
106 } 134 }
107 135
108 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do uble t2, 136 SkDPoint SkDConic::subDivide(const SkDPoint& a, const SkDPoint& c, double t1, do uble t2,
109 SkScalar* weight) const { 137 SkScalar* weight) const {
110 SkDConic chopped = this->subDivide(t1, t2); 138 SkDConic chopped = this->subDivide(t1, t2);
111 *weight = chopped.fWeight; 139 *weight = chopped.fWeight;
112 return chopped[1]; 140 return chopped[1];
113 } 141 }
OLDNEW
« no previous file with comments | « no previous file | tests/PathOpsSimplifyTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698