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

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: Remove unused variable 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
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
15 // These are weights and abscissae for gaussian quadrature with weight function w(x) = 1
16 static SkScalar weights8[8] = {0.3626837833783620f, 0.3626837833783620f, 0.31370 66458778873f, 0.3137066458778873f, 0.2223810344533745f, 0.2223810344533745f, 0.1 012285362903763f, 0.1012285362903763f};
17 static SkScalar absc8[8] = {-0.1834346424956498f, 0.1834346424956498f, -0.525532 4099163290f, 0.5255324099163290f, -0.7966664774136267f, 0.7966664774136267f, -0. 9602898564975363f, 0.9602898564975363f};
18
19 static Sk8f weights = Sk8f::Load(weights8);
20 static Sk8f absc = 0.5f*(Sk8f::Load(absc8) + 1.0f);
21
22
23 // this is the same enum as in SkPathMeasure but it doesn't have a name there
24 enum SkSegType {
25 kLine_SegType,
26 kQuad_SegType,
27 kCubic_SegType,
28 kConic_SegType,
29 };
30
31 class ArcLengthIntegrator {
32 public:
33 ArcLengthIntegrator() {}
34 ArcLengthIntegrator(const SkPoint* pts, SkSegType segType);
35 SkScalar computeLength(SkScalar t);
36
37 private:
38 Sk8f evaluateDerivativeLength(Sk8f ts);
39
40 SkSegType fSegType;
41
42 // TODO(hstern) make some generic things like fCoeff1x, fCoeff1y, fCoeff2x, etc.
43 // which are opaque and shared between the different curve types. Or use an array.
44 // Either way, fill in inside the constructor.
45
46 // precomputed quad coeffs for derivative
47 Sk8f A2BC_x, A2BC_y;
48 Sk8f AB_x, AB_y;
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 private:
60 SkPoint evaluateQuad(SkScalar t);
61 SkVector evaluateQuadDerivative(SkScalar t);
62 //SkPoint evaluate_cubic(SkScalar t);
63 //SkVector evaluate_cubic_derivative(SkScalar t);
64 //SkPoint evaluate_conic(SkScalar t);
65 //SkVector evaluate_conic_derivative(SkScalar t);
66
67 const SkScalar kTolerance = 0.0001f;
68 const int kNewtonIters = 5;
69 const int kBisectIters = 5;
70
71 SkSegType fSegType;
72 SkPoint fPts[4];
73 SkScalar fLength = -1.0f;
74 ArcLengthIntegrator fIntegrator;
75
76 // for debug purposes
77 int fIters;
78 };
79
80 #endif // SkCurveMeasure_DEFINED
OLDNEW
« no previous file with comments | « gyp/utils.gypi ('k') | src/utils/SkCurveMeasure.cpp » ('j') | src/utils/SkCurveMeasure.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698