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

Side by Side Diff: src/utils/SkCurveMeasure.h

Issue 2187083002: Add initial CurveMeasure code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Include <algorithm> for overloaded min/max Created 4 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 | « gyp/utils.gypi ('k') | src/utils/SkCurveMeasure.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkCurveMeasure_DEFINED
9 #define SkCurveMeasure_DEFINED
10
11 #include "SkPoint.h"
12 #include "SkNx.h"
13
14 // These are weights and abscissae for gaussian quadrature with weight function
15 // w(x) = 1
16 static SkScalar weights8[8] = {0.3626837833783620f, 0.3626837833783620f,
17 0.3137066458778873f, 0.3137066458778873f,
18 0.2223810344533745f, 0.2223810344533745f,
19 0.1012285362903763f, 0.1012285362903763f};
20 static SkScalar absc8[8] = {-0.1834346424956498f, 0.1834346424956498f,
21 -0.5255324099163290f, 0.5255324099163290f,
22 -0.7966664774136267f, 0.7966664774136267f,
23 -0.9602898564975363f, 0.9602898564975363f};
24
25 static Sk8f weights = Sk8f::Load(weights8);
26 static Sk8f absc = 0.5f*(Sk8f::Load(absc8) + 1.0f);
27
28
29 // this is the same enum as in SkPathMeasure but it doesn't have a name there
30 enum SkSegType {
31 kLine_SegType,
32 kQuad_SegType,
33 kCubic_SegType,
34 kConic_SegType,
35 };
36
37 class ArcLengthIntegrator {
38 public:
39 ArcLengthIntegrator() {}
40 ArcLengthIntegrator(const SkPoint* pts, SkSegType segType);
41 SkScalar computeLength(SkScalar t);
42
43 private:
44 SkSegType fSegType;
45
46 // precomputed coefficients for derivatives in Horner form
47 Sk8f xCoeff[3];
48 Sk8f yCoeff[3];
49 };
50
51 class SkCurveMeasure {
52 public:
53 SkCurveMeasure() {}
54 SkCurveMeasure(const SkPoint* pts, SkSegType segType);
55
56 SkScalar getTime(SkScalar targetLength);
57 void getPosTan(SkScalar distance, SkPoint* pos, SkVector* tan);
58 SkScalar getLength();
59
60 private:
61 SkPoint evaluateQuad(SkScalar t);
62 SkVector evaluateQuadDerivative(SkScalar t);
63 //SkPoint evaluate_cubic(SkScalar t);
64 //SkVector evaluate_cubic_derivative(SkScalar t);
65 //SkPoint evaluate_conic(SkScalar t);
66 //SkVector evaluate_conic_derivative(SkScalar t);
67
68 const SkScalar kTolerance = 0.0001f;
69 const int kNewtonIters = 5;
70 const int kBisectIters = 5;
71
72 SkSegType fSegType;
73 SkPoint fPts[4];
74 SkScalar fLength = -1.0f;
75 ArcLengthIntegrator fIntegrator;
76
77 // for debug purposes
78 int fIters;
79 };
80
81 #endif // SkCurveMeasure_DEFINED
OLDNEW
« no previous file with comments | « gyp/utils.gypi ('k') | src/utils/SkCurveMeasure.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698