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

Side by Side Diff: src/core/SkGeometry.cpp

Issue 175193003: Stub for conic section max curvature (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 10 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 | « include/core/SkGeometry.h ('k') | no next file » | 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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 7
8 #include "SkGeometry.h" 8 #include "SkGeometry.h"
9 #include "SkMatrix.h" 9 #include "SkMatrix.h"
10 10
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 if (dir == kCCW_SkRotationDirection) { 1155 if (dir == kCCW_SkRotationDirection) {
1156 matrix.preScale(SK_Scalar1, -SK_Scalar1); 1156 matrix.preScale(SK_Scalar1, -SK_Scalar1);
1157 } 1157 }
1158 if (userMatrix) { 1158 if (userMatrix) {
1159 matrix.postConcat(*userMatrix); 1159 matrix.postConcat(*userMatrix);
1160 } 1160 }
1161 matrix.mapPoints(quadPoints, pointCount); 1161 matrix.mapPoints(quadPoints, pointCount);
1162 return pointCount; 1162 return pointCount;
1163 } 1163 }
1164 1164
1165
1165 /////////////////////////////////////////////////////////////////////////////// 1166 ///////////////////////////////////////////////////////////////////////////////
1166 1167 //
1168 // NURB representation for conics. Helpful explanations at:
1169 //
1170 // http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.44.5740&rep=rep1&typ e=ps
reed1 2014/02/21 17:00:04 nit: 80-col
humper 2014/02/21 17:07:21 Done, and fixed a bunch of other 80 col issues in
1171 // and
1172 // http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/NURBS/RB-conics.html
1173 //
1167 // F = (A (1 - t)^2 + C t^2 + 2 B (1 - t) t w) 1174 // F = (A (1 - t)^2 + C t^2 + 2 B (1 - t) t w)
1168 // ------------------------------------------ 1175 // ------------------------------------------
1169 // ((1 - t)^2 + t^2 + 2 (1 - t) t w) 1176 // ((1 - t)^2 + t^2 + 2 (1 - t) t w)
1170 // 1177 //
1171 // = {t^2 (P0 + P2 - 2 P1 w), t (-2 P0 + 2 P1 w), P0} 1178 // = {t^2 (P0 + P2 - 2 P1 w), t (-2 P0 + 2 P1 w), P0}
1172 // ------------------------------------------------ 1179 // ------------------------------------------------
1173 // {t^2 (2 - 2 w), t (-2 + 2 w), 1} 1180 // {t^2 (2 - 2 w), t (-2 + 2 w), 1}
1174 // 1181 //
1175 1182
1176 // Take the parametric specification for the conic (either X or Y) and return
1177 // in coeff[] the coefficients for the simple quadratic polynomial
1178 // coeff[0] for t^2
1179 // coeff[1] for t
1180 // coeff[2] for constant term
1181 //
1182 static SkScalar conic_eval_pos(const SkScalar src[], SkScalar w, SkScalar t) { 1183 static SkScalar conic_eval_pos(const SkScalar src[], SkScalar w, SkScalar t) {
1183 SkASSERT(src); 1184 SkASSERT(src);
1184 SkASSERT(t >= 0 && t <= SK_Scalar1); 1185 SkASSERT(t >= 0 && t <= SK_Scalar1);
1185 1186
1186 SkScalar src2w = SkScalarMul(src[2], w); 1187 SkScalar src2w = SkScalarMul(src[2], w);
1187 SkScalar C = src[0]; 1188 SkScalar C = src[0];
1188 SkScalar A = src[4] - 2 * src2w + C; 1189 SkScalar A = src[4] - 2 * src2w + C;
1189 SkScalar B = 2 * (src2w - C); 1190 SkScalar B = 2 * (src2w - C);
1190 SkScalar numer = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C); 1191 SkScalar numer = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C);
1191 1192
1192 B = 2 * (w - SK_Scalar1); 1193 B = 2 * (w - SK_Scalar1);
1193 C = SK_Scalar1; 1194 C = SK_Scalar1;
1194 A = -B; 1195 A = -B;
1195 SkScalar denom = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C); 1196 SkScalar denom = SkScalarMulAdd(SkScalarMulAdd(A, t, B), t, C);
1196 1197
1197 return SkScalarDiv(numer, denom); 1198 return SkScalarDiv(numer, denom);
1198 } 1199 }
1199 1200
1201
1202 // Take the parametric specification for the conic (either X or Y) and return
reed1 2014/02/21 17:00:04 This comment does not go with deriv_coeff, but per
humper 2014/02/21 17:07:21 Done.
1203 // in coeff[] the coefficients for the simple quadratic polynomial
1204 //
1200 // F' = 2 (C t (1 + t (-1 + w)) - A (-1 + t) (t (-1 + w) - w) + B (1 - 2 t) w) 1205 // F' = 2 (C t (1 + t (-1 + w)) - A (-1 + t) (t (-1 + w) - w) + B (1 - 2 t) w)
1201 // 1206 //
1202 // t^2 : (2 P0 - 2 P2 - 2 P0 w + 2 P2 w) 1207 // t^2 : (2 P0 - 2 P2 - 2 P0 w + 2 P2 w)
1203 // t^1 : (-2 P0 + 2 P2 + 4 P0 w - 4 P1 w) 1208 // t^1 : (-2 P0 + 2 P2 + 4 P0 w - 4 P1 w)
1204 // t^0 : -2 P0 w + 2 P1 w 1209 // t^0 : -2 P0 w + 2 P1 w
1205 // 1210 //
1206 // We disregard magnitude, so we can freely ignore the denominator of F', and 1211 // We disregard magnitude, so we can freely ignore the denominator of F', and
1207 // divide the numerator by 2 1212 // divide the numerator by 2
1208 // 1213 //
1209 // coeff[0] for t^2 1214 // coeff[0] for t^2
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 } 1440 }
1436 if (this->findYExtrema(&t)) { 1441 if (this->findYExtrema(&t)) {
1437 this->evalAt(t, &pts[count++]); 1442 this->evalAt(t, &pts[count++]);
1438 } 1443 }
1439 bounds->set(pts, count); 1444 bounds->set(pts, count);
1440 } 1445 }
1441 1446
1442 void SkConic::computeFastBounds(SkRect* bounds) const { 1447 void SkConic::computeFastBounds(SkRect* bounds) const {
1443 bounds->set(fPts, 3); 1448 bounds->set(fPts, 3);
1444 } 1449 }
1450
1451 // Find the parameter value where the conic takes on its maximum curvature.
reed1 2014/02/21 17:00:04 Lets hoist this comment out to the header.
humper 2014/02/21 17:07:21 Done.
1452 // Returns true if the max curvature is inside the 0..1 parameter range,
1453 // otherwise returns false and leaves its t parameter unchanged.
1454 bool SkConic::findMaxCurvature(SkScalar* t) const {
1455 // TODO: Implement me
1456 return false;
1457 }
OLDNEW
« no previous file with comments | « include/core/SkGeometry.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698