OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 | 7 |
8 #ifndef SkCurveMeasure_DEFINED | 8 #ifndef SkCurveMeasure_DEFINED |
9 #define SkCurveMeasure_DEFINED | 9 #define SkCurveMeasure_DEFINED |
10 | 10 |
11 #include "SkPathMeasurePriv.h" | 11 #include "SkPathMeasurePriv.h" |
12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
13 #include "SkNx.h" | 13 #include "SkNx.h" |
14 | 14 |
15 // These are weights and abscissae for gaussian quadrature with weight function | 15 // These are weights and abscissae for gaussian quadrature with weight function |
16 // w(x) = 1 | 16 // w(x) = 1 |
17 static SkScalar weights8[8] = {0.3626837833783620f, 0.3626837833783620f, | 17 static SkScalar weights8[8] = {0.3626837833783620f, 0.3626837833783620f, |
18 0.3137066458778873f, 0.3137066458778873f, | 18 0.3137066458778873f, 0.3137066458778873f, |
19 0.2223810344533745f, 0.2223810344533745f, | 19 0.2223810344533745f, 0.2223810344533745f, |
20 0.1012285362903763f, 0.1012285362903763f}; | 20 0.1012285362903763f, 0.1012285362903763f}; |
21 static SkScalar absc8[8] = {-0.1834346424956498f, 0.1834346424956498f, | 21 static SkScalar absc8[8] = {-0.1834346424956498f, 0.1834346424956498f, |
22 -0.5255324099163290f, 0.5255324099163290f, | 22 -0.5255324099163290f, 0.5255324099163290f, |
23 -0.7966664774136267f, 0.7966664774136267f, | 23 -0.7966664774136267f, 0.7966664774136267f, |
24 -0.9602898564975363f, 0.9602898564975363f}; | 24 -0.9602898564975363f, 0.9602898564975363f}; |
25 | 25 |
26 static Sk8f weights = Sk8f::Load(weights8); | 26 static Sk8f weights = Sk8f::Load(weights8); |
caryclark
2016/08/15 19:13:04
Writable globals are seldom a good idea. Another t
Harry Stern
2016/08/15 20:55:16
These should all have be static const - they never
| |
27 static Sk8f absc = 0.5f*(Sk8f::Load(absc8) + 1.0f); | 27 static Sk8f absc = 0.5f*(Sk8f::Load(absc8) + 1.0f); |
28 | 28 |
29 | 29 |
30 class ArcLengthIntegrator { | 30 class ArcLengthIntegrator { |
31 public: | 31 public: |
32 ArcLengthIntegrator() {} | 32 ArcLengthIntegrator() {} |
caryclark
2016/08/15 19:13:04
Why does this leave fSegType uninitialized?
Do you
Harry Stern
2016/08/15 20:55:16
I think I need the default constructor for the Cur
| |
33 ArcLengthIntegrator(const SkPoint* pts, SkSegType segType); | 33 ArcLengthIntegrator(const SkPoint* pts, SkSegType segType); |
34 SkScalar computeLength(SkScalar t); | 34 SkScalar computeLength(SkScalar t); |
35 | 35 |
36 private: | 36 private: |
37 SkSegType fSegType; | 37 SkSegType fSegType; |
38 | 38 |
39 // precomputed coefficients for derivatives in Horner form | 39 // precomputed coefficients for derivatives in Horner form |
40 Sk8f xCoeff[3]; | 40 Sk8f xCoeff[3]; |
caryclark
2016/08/15 19:13:04
Preceed with 'f'
Harry Stern
2016/08/15 20:55:17
Done.
| |
41 Sk8f yCoeff[3]; | 41 Sk8f yCoeff[3]; |
42 | |
43 SkScalar fConicW = 0; | |
caryclark
2016/08/15 19:13:04
Why zero? That's a valid weight; do you mean for i
Harry Stern
2016/08/15 20:55:17
This variable only gets read when we are a conic,
| |
42 }; | 44 }; |
43 | 45 |
44 class SkCurveMeasure { | 46 class SkCurveMeasure { |
45 public: | 47 public: |
46 SkCurveMeasure() {} | 48 SkCurveMeasure() {} |
47 | 49 |
48 // Almost exactly the same as in SkPath::Iter: | 50 // Almost exactly the same as in SkPath::Iter: |
49 // kLine_SegType -> 2 points: start end | 51 // kLine_SegType -> 2 points: start end |
50 // kQuad_SegType -> 3 points: start control end | 52 // kQuad_SegType -> 3 points: start control end |
51 // kCubic_SegType -> 4 points: start control1 control2 end | 53 // kCubic_SegType -> 4 points: start control1 control2 end |
52 // kConic_SegType -> 4 points: start control end (w, w) | 54 // kConic_SegType -> 4 points: start control end (w, w) |
caryclark
2016/08/15 19:13:04
Do you repeat w twice? Do you rely on this? Why?
Harry Stern
2016/08/15 20:55:17
I do set it to (w, w) for no particular reason, bu
| |
53 // | 55 // |
54 // i.e. the only difference is that the conic's last point is a point | 56 // i.e. the only difference is that the conic's last point is a point |
55 // consisting of the w value twice | 57 // consisting of the w value twice |
56 SkCurveMeasure(const SkPoint* pts, SkSegType segType); | 58 SkCurveMeasure(const SkPoint* pts, SkSegType segType); |
57 | 59 |
58 SkScalar getTime(SkScalar targetLength); | 60 SkScalar getTime(SkScalar targetLength); |
59 void getPosTanTime(SkScalar distance, SkPoint* pos, SkVector* tan, SkScalar* time); | 61 void getPosTanTime(SkScalar distance, SkPoint* pos, SkVector* tan, SkScalar* time); |
60 SkScalar getLength(); | 62 SkScalar getLength(); |
61 | 63 |
62 private: | 64 private: |
63 const SkScalar kTolerance = 0.0001f; | 65 const SkScalar kTolerance = 0.0001f; |
64 const int kNewtonIters = 5; | 66 const int kNewtonIters = 5; |
65 const int kBisectIters = 5; | 67 const int kBisectIters = 5; |
66 | 68 |
67 SkSegType fSegType; | 69 SkSegType fSegType; |
68 SkPoint fPts[4]; | 70 SkPoint fPts[4]; |
69 SkScalar fLength = -1.0f; | 71 SkScalar fLength = -1.0f; |
70 ArcLengthIntegrator fIntegrator; | 72 ArcLengthIntegrator fIntegrator; |
71 | 73 |
72 // for debug purposes | 74 // for debug purposes |
73 int fIters; | 75 int fIters; |
74 }; | 76 }; |
75 | 77 |
76 #endif // SkCurveMeasure_DEFINED | 78 #endif // SkCurveMeasure_DEFINED |
OLD | NEW |