| 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 const 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 const 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 const Sk8f weights = Sk8f::Load(weights8); |
| 27 static Sk8f absc = 0.5f*(Sk8f::Load(absc8) + 1.0f); | 27 static const Sk8f absc = 0.5f*(Sk8f::Load(absc8) + 1.0f); |
| 28 | 28 |
| 29 /* Currently this uses Gaussian quadrature with a fixed number of |
| 30 * evaluation points (see above weights and abscissae) but in principle |
| 31 * we could have a table of abscissae and weights and choose which to use |
| 32 * based on an approximation of the max length of the curve. |
| 33 * |
| 34 * We should always use some power of 2 number of evaluation points so that |
| 35 * the SkNx templates will compile down into SIMD-register-aligned blocks. |
| 36 */ |
| 29 | 37 |
| 30 class ArcLengthIntegrator { | 38 class ArcLengthIntegrator { |
| 31 public: | 39 public: |
| 32 ArcLengthIntegrator() {} | 40 ArcLengthIntegrator() {} |
| 33 ArcLengthIntegrator(const SkPoint* pts, SkSegType segType); | 41 ArcLengthIntegrator(const SkPoint* pts, SkSegType segType); |
| 34 SkScalar computeLength(SkScalar t); | 42 SkScalar computeLength(SkScalar t); |
| 35 | 43 |
| 36 private: | 44 private: |
| 37 SkSegType fSegType; | 45 SkSegType fSegType; |
| 38 | 46 |
| 39 // precomputed coefficients for derivatives in Horner form | 47 // precomputed coefficients for derivatives in Horner form |
| 40 Sk8f xCoeff[3]; | 48 Sk8f fXCoeff[3]; |
| 41 Sk8f yCoeff[3]; | 49 Sk8f fYCoeff[3]; |
| 50 |
| 51 SkScalar fConicW = 0; |
| 42 }; | 52 }; |
| 43 | 53 |
| 44 class SkCurveMeasure { | 54 class SkCurveMeasure { |
| 45 public: | 55 public: |
| 46 SkCurveMeasure() {} | |
| 47 | |
| 48 // Almost exactly the same as in SkPath::Iter: | 56 // Almost exactly the same as in SkPath::Iter: |
| 49 // kLine_SegType -> 2 points: start end | 57 // kLine_SegType -> 2 points: start end |
| 50 // kQuad_SegType -> 3 points: start control end | 58 // kQuad_SegType -> 3 points: start control end |
| 51 // kCubic_SegType -> 4 points: start control1 control2 end | 59 // kCubic_SegType -> 4 points: start control1 control2 end |
| 52 // kConic_SegType -> 4 points: start control end (w, w) | 60 // kConic_SegType -> 4 points: start control end (w, w) |
| 53 // | 61 // |
| 54 // i.e. the only difference is that the conic's last point is a point | 62 // i.e. the only difference is that the conic's last point is a point |
| 55 // consisting of the w value twice | 63 // consisting of the w value twice |
| 56 SkCurveMeasure(const SkPoint* pts, SkSegType segType); | 64 SkCurveMeasure(const SkPoint* pts, SkSegType segType); |
| 57 | 65 |
| 58 SkScalar getTime(SkScalar targetLength); | 66 SkScalar getTime(SkScalar targetLength); |
| 59 void getPosTanTime(SkScalar distance, SkPoint* pos, SkVector* tan, SkScalar*
time); | 67 void getPosTanTime(SkScalar distance, SkPoint* pos, SkVector* tan, SkScalar*
time); |
| 60 SkScalar getLength(); | 68 SkScalar getLength(); |
| 61 | 69 |
| 62 private: | 70 private: |
| 63 const SkScalar kTolerance = 0.0001f; | 71 static constexpr SkScalar kTolerance = 0.0001f; |
| 64 const int kNewtonIters = 5; | 72 static const int kNewtonIters = 5; |
| 65 const int kBisectIters = 5; | 73 static const int kBisectIters = 5; |
| 66 | 74 |
| 67 SkSegType fSegType; | 75 SkSegType fSegType; |
| 68 SkPoint fPts[4]; | 76 SkPoint fPts[4]; |
| 69 SkScalar fLength = -1.0f; | 77 SkScalar fLength = -1.0f; |
| 70 ArcLengthIntegrator fIntegrator; | 78 ArcLengthIntegrator fIntegrator; |
| 71 | 79 |
| 72 // for debug purposes | 80 // for debug purposes |
| 73 int fIters; | 81 int fIters; |
| 74 }; | 82 }; |
| 75 | 83 |
| 76 #endif // SkCurveMeasure_DEFINED | 84 #endif // SkCurveMeasure_DEFINED |
| OLD | NEW |