OLD | NEW |
---|---|
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 #include "SkNx.h" | 10 #include "SkNx.h" |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
909 if (dst) { | 909 if (dst) { |
910 if (count == 0) { | 910 if (count == 0) { |
911 memcpy(dst, src, 4 * sizeof(SkPoint)); | 911 memcpy(dst, src, 4 * sizeof(SkPoint)); |
912 } else { | 912 } else { |
913 SkChopCubicAt(src, dst, tValues, count); | 913 SkChopCubicAt(src, dst, tValues, count); |
914 } | 914 } |
915 } | 915 } |
916 return count + 1; | 916 return count + 1; |
917 } | 917 } |
918 | 918 |
919 #include "../pathops/SkPathOpsCubic.h" | |
920 | |
921 //static int RootsValidT(const double A, const double B, const double C, double D, double s[3]); | |
922 | |
923 static void cubic_to_dcoeff(double p0, double p1, double p2, double p3, double c oeff[4]) { | |
924 const Sk2s three(3); | |
caryclark
2015/04/30 12:59:41
unused variable?
reed1
2015/04/30 13:34:22
Done.
| |
925 double p1minusp2 = p1 - p2; | |
926 | |
927 double D = p0; | |
928 double A = p3 + 3 * p1minusp2 - D; | |
929 double B = 3 * (D - p1minusp2 - p1); | |
930 double C = 3 * (p1 - D); | |
931 | |
932 coeff[0] = A; | |
933 coeff[1] = B; | |
934 coeff[2] = C; | |
935 coeff[3] = D; | |
936 } | |
937 | |
938 static SkPoint dpoint_to_point(const SkDPoint& src) { | |
caryclark
2015/04/30 12:59:40
this is the same as
src.asSkPoint()
reed1
2015/04/30 13:34:22
Done.
| |
939 return SkPoint::Make(SkDoubleToScalar(src.fX), SkDoubleToScalar(src.fY)); | |
940 } | |
941 | |
942 static bool cubic_dchop_at_root(const SkPoint src[4], const double coeff[4], SkP oint dst[7]) { | |
943 double t[3]; | |
944 int roots = SkDCubic::RootsValidT(coeff[0], coeff[1], coeff[2], coeff[3], t) ; | |
caryclark
2015/04/30 12:59:41
This doesn't take into account the case where the
caryclark
2015/04/30 13:03:00
On 2015/04/30 12:59:41, caryclark wrote:
int root
reed1
2015/04/30 13:34:22
Done.
| |
945 SkASSERT(roots <= 1); | |
946 if (roots > 0) { | |
947 SkDCubic cubic; | |
948 SkDCubicPair pair = cubic.set(src).chopAt(t[0]); | |
949 for (int i = 0; i < 7; ++i) { | |
950 dst[i] = dpoint_to_point(pair.pts[i]); | |
951 } | |
952 return true; | |
953 } | |
954 return false; | |
955 } | |
956 | |
957 bool SkChopMonoCubicAtY(SkPoint src[4], SkScalar y, SkPoint dst[7]) { | |
958 double coeff[4]; | |
959 cubic_to_dcoeff(src[0].fY, src[1].fY, src[2].fY, src[3].fY, coeff); | |
960 coeff[3] -= y; | |
961 return cubic_dchop_at_root(src, coeff, dst); | |
962 } | |
963 | |
964 bool SkChopMonoCubicAtX(SkPoint src[4], SkScalar x, SkPoint dst[7]) { | |
965 double coeff[4]; | |
966 cubic_to_dcoeff(src[0].fX, src[1].fX, src[2].fX, src[3].fX, coeff); | |
967 coeff[3] -= x; | |
968 return cubic_dchop_at_root(src, coeff, dst); | |
969 } | |
970 | |
919 /////////////////////////////////////////////////////////////////////////////// | 971 /////////////////////////////////////////////////////////////////////////////// |
920 | 972 |
921 /* Find t value for quadratic [a, b, c] = d. | 973 /* Find t value for quadratic [a, b, c] = d. |
922 Return 0 if there is no solution within [0, 1) | 974 Return 0 if there is no solution within [0, 1) |
923 */ | 975 */ |
924 static SkScalar quad_solve(SkScalar a, SkScalar b, SkScalar c, SkScalar d) { | 976 static SkScalar quad_solve(SkScalar a, SkScalar b, SkScalar c, SkScalar d) { |
925 // At^2 + Bt + C = d | 977 // At^2 + Bt + C = d |
926 SkScalar A = a - 2 * b + c; | 978 SkScalar A = a - 2 * b + c; |
927 SkScalar B = 2 * (b - a); | 979 SkScalar B = 2 * (b - a); |
928 SkScalar C = a - d; | 980 SkScalar C = a - d; |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1550 matrix.preScale(SK_Scalar1, -SK_Scalar1); | 1602 matrix.preScale(SK_Scalar1, -SK_Scalar1); |
1551 } | 1603 } |
1552 if (userMatrix) { | 1604 if (userMatrix) { |
1553 matrix.postConcat(*userMatrix); | 1605 matrix.postConcat(*userMatrix); |
1554 } | 1606 } |
1555 for (int i = 0; i < conicCount; ++i) { | 1607 for (int i = 0; i < conicCount; ++i) { |
1556 matrix.mapPoints(dst[i].fPts, 3); | 1608 matrix.mapPoints(dst[i].fPts, 3); |
1557 } | 1609 } |
1558 return conicCount; | 1610 return conicCount; |
1559 } | 1611 } |
OLD | NEW |