Extract SkFindCubicMidTangent from SkChopCubicAtMidTangent
Also does the same for the quadratic variants.
Bug: skia:10419
Change-Id: I4a0e46a0d76d16dcf452f39c7e2552975ec46ed6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318783
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index 63aed08..b858060 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -208,7 +208,7 @@
return SkPoint{x0_x1[0] + x0_x1[1], y0_y1[0] + y0_y1[1]};
}
-void SkChopQuadAtMidTangent(const SkPoint src[3], SkPoint dst[5]) {
+float SkFindQuadMidTangent(const SkPoint src[3]) {
// Tangents point in the direction of increasing T, so tan0 and -tan1 both point toward the
// midtangent. The bisector of tan0 and -tan1 is orthogonal to the midtangent:
//
@@ -234,7 +234,7 @@
T = .5; // The quadratic was a line or near-line. Just chop at .5.
}
- SkChopQuadAt(src, dst, T);
+ return T;
}
/** Quad'(t) = At + B, where
@@ -558,7 +558,7 @@
return SkNx_fma(f, Sk4f(m), a);
}
-void SkChopCubicAtMidTangent(const SkPoint src[4], SkPoint dst[7]) {
+float SkFindCubicMidTangent(const SkPoint src[4]) {
// Tangents point in the direction of increasing T, so tan0 and -tan1 both point toward the
// midtangent. The bisector of tan0 and -tan1 is orthogonal to the midtangent:
//
@@ -627,7 +627,7 @@
T = .5;
}
- SkChopCubicAt(src, dst, T);
+ return T;
}
static void flatten_double_cubic_extrema(SkScalar coords[14]) {
diff --git a/src/core/SkGeometry.h b/src/core/SkGeometry.h
index 6b66fb8..92d70fa 100644
--- a/src/core/SkGeometry.h
+++ b/src/core/SkGeometry.h
@@ -72,10 +72,17 @@
return SkMeasureAngleInsideVectors(pts[1] - pts[0], pts[2] - pts[1]);
}
+/** Given a src quadratic bezier, returns the T value whose tangent angle is halfway between the
+ tangents at p0 and p3.
+*/
+float SkFindQuadMidTangent(const SkPoint src[4]);
+
/** Given a src quadratic bezier, chop it at the tangent whose angle is halfway between the
tangents at p0 and p2. The new quads are returned in dst[0..2] and dst[2..4].
*/
-void SkChopQuadAtMidTangent(const SkPoint src[3], SkPoint dst[5]);
+inline void SkChopQuadAtMidTangent(const SkPoint src[3], SkPoint dst[5]) {
+ SkChopQuadAt(src, dst, SkFindQuadMidTangent(src));
+}
/** Given the 3 coefficients for a quadratic bezier (either X or Y values), look
for extrema, and return the number of t-values that are found that represent
@@ -158,6 +165,11 @@
*/
float SkMeasureNonInflectCubicRotation(const SkPoint[4]);
+/** Given a src cubic bezier, returns the T value whose tangent angle is halfway between the
+ tangents at p0 and p3.
+*/
+float SkFindCubicMidTangent(const SkPoint src[4]);
+
/** Given a src cubic bezier, chop it at the tangent whose angle is halfway between the
tangents at p0 and p3. The new cubics are returned in dst[0..3] and dst[3..6].
@@ -166,7 +178,9 @@
If this is the case then we simply chop at a point which guarantees neither side rotates more
than 180 degrees.
*/
-void SkChopCubicAtMidTangent(const SkPoint src[4], SkPoint dst[7]);
+inline void SkChopCubicAtMidTangent(const SkPoint src[4], SkPoint dst[7]) {
+ SkChopCubicAt(src, dst, SkFindCubicMidTangent(src));
+}
/** Given the 4 coefficients for a cubic bezier (either X or Y values), look
for extrema, and return the number of t-values that are found that represent