How many quadratics does a cubic take? The error of cu2qu’s spline in closed form

Written by Claude, with Behdad Esfahbod · November 23, 2026

cu2qu converts cubic Bézier curves to quadratic splines for TrueType. It cuts a cubic into \(n\) pieces of equal parameter length, gives each piece one off-curve point, and raises \(n\) until the spline tests within tolerance. This note shows that the spline needs no test. At equal parameters it differs from the cubic by a multiple of a single vector, the cubic’s third difference \(\mathbf{d}_3\), and the largest distance between them is \(\lvert\mathbf{d}_3\rvert\,\Phi(n)/n^3\), where \(\Phi(n)\) depends on \(n\) alone and has a closed form: 4/27 for two quadratics, 27/128 for three, rising towards \(\tfrac14 + \tfrac{\sqrt3}{36}\). So the number of quadratics is computed, not searched for. The same analysis shows what it costs a spline to start and end with the cubic’s derivative, as cu2qu’s does, and that cu2qu’s weights are then the best there are for two and three quadratics; it tells when a single quadratic cannot fit, and explains why the recursive fit test could fail to return on finite input. For renderers, which have no masters to keep compatible, a second closed form bounds the true distance between a cubic and the quadratic of its end tangents. The results are in HarfBuzz and are proposed for fontTools and kurbo.

∞ 1. Introduction

Type is mostly drawn with cubic Bézier curves, and TrueType outlines are quadratic. So cubics get converted: by font compilers that build TrueType fonts from cubic sources, and by renderers whose curve handling is quadratic only. cu2qu [1], which James Godfrey-Kittle and Behdad Esfahbod wrote in 2015 and which has been part of fontTools since 2020 [2], is the converter behind fontmake (through ufo2ft). kurbo has a Rust port of it [3], which fontc uses, and HarfBuzz’s GPU library has one in C++.

The idea fits in three sentences. Cut the cubic into \(n\) pieces of equal parameter length. Give each piece one off-curve point, between the point that would keep the piece’s tangent at its start and the point that would keep it at its end, going from the first to the second as the pieces go from the first to the last. Leave the on-curve points between them out: TrueType implies an on-curve point halfway between two consecutive off-curve points. Behdad’s sketch of this, in July 2015, left one thing open [4]:

The only part I have not figured out is the error function. After error function is figured out, just increase n until feasible solution is found.

The error was at first measured at sampled parameters, an exact and recursive test replaced that the following year, and \(n\) has been increased until feasible ever since. This note figures the error function out. What it finds:

∞ 2. The construction

A cubic has control points \(\mathbf{c}_0, \mathbf{c}_1, \mathbf{c}_2, \mathbf{c}_3\) and is

\[C(t) = (1-t)^3\,\mathbf{c}_0 + 3t(1-t)^2\,\mathbf{c}_1 + 3t^2(1-t)\,\mathbf{c}_2 + t^3\,\mathbf{c}_3, \qquad 0 \le t \le 1.\]

Points and vectors are in bold, and distances are Euclidean. The tolerance is \(\varepsilon\), in the units of the coordinates. Font compilers use a thousandth of the em by default, which is one unit for a font of 1,000 units per em.

∞ The spline

For \(n \ge 2\), cut the cubic at \(t = k/n\) into \(n\) pieces, numbered \(k = 0, \dots, n-1\). Each piece is a cubic with control points \(\mathbf{p}_0, \mathbf{p}_1, \mathbf{p}_2, \mathbf{p}_3\) of its own and a parameter \(u\) from 0 to 1 of its own. A quadratic from \(\mathbf{p}_0\) to \(\mathbf{p}_3\) with off-curve point \(\mathbf{q}\) starts with derivative \(2(\mathbf{q} - \mathbf{p}_0)\), and the piece starts with \(3(\mathbf{p}_1 - \mathbf{p}_0)\). So there is one quadratic that leaves \(\mathbf{p}_0\) exactly as the piece does, and one that arrives at \(\mathbf{p}_3\) exactly as the piece does. Their off-curve points are the two candidates of the piece:

\[\mathbf{q}^{+} = \mathbf{p}_0 + \tfrac32\,(\mathbf{p}_1 - \mathbf{p}_0), \qquad \mathbf{q}^{-} = \mathbf{p}_3 + \tfrac32\,(\mathbf{p}_2 - \mathbf{p}_3).\]

The off-curve point of piece \(k\) is taken between its two candidates, at the first for the first piece and at the second for the last:

\[\mathbf{o}_k = \left(1 - \frac{k}{n-1}\right)\mathbf{q}_k^{+} + \frac{k}{n-1}\,\mathbf{q}_k^{-}.\]

(The 2015 sketch divided by \(n\) here. cu2qu divides by \(n - 1\), so that the last piece takes its second candidate.) The spline has the points \(\mathbf{c}_0, \mathbf{o}_0, \dots, \mathbf{o}_{n-1}, \mathbf{c}_3\), of which only the first and the last are on the curve. Its \(n\) quadratics meet halfway between consecutive off-curve points (Figure 1).

The cu2qu spline of quadratics for a cubic A cubic cut into equal pieces. Each piece has two candidate off-curve points, a fixed distance apart; the first piece takes its first candidate, the last piece its second, and the pieces between go from one to the other. On-curve points of the spline are halfway between consecutive off-curve points. c0​ c1​ c2​ c3​ o0 = q0+​ q0−​ q1+​ q1−​ o1​ q2+​ o2 = q2−​ cubic spline candidates off-curve points implied on-curve points

third difference 1146, tolerance 10.0: 3 quadratics. Largest distance at equal parameters: 8.96 by the formula, 8.96 measured.

Figure 1. The spline for a cubic, three quadratics as first drawn. Each piece of the cubic has two candidates for its off-curve point, drawn joined. They are the same distance apart, in the same direction, in every piece: half the third difference of a piece (Lemma 1). The first piece takes its first candidate, the last its second, and the pieces between go from one to the other in equal steps. The example is far coarser than a font would allow, so that the spline can be told from the cubic. The figure draws the spline from two quadratics up, and says where cu2qu would use one.

Three things follow at once.

∞ One quadratic

For \(n = 1\) the rule above has no meaning, and keeping both end tangents leaves one choice: the point \(\mathbf{q}\) where the two end tangent lines meet. cu2qu tries this quadratic first.

∞ The measure, and the search

A spline is accepted when it is within \(\varepsilon\) of the cubic at equal parameters: quadratic \(k\) at its parameter \(u\) is compared with the cubic at \(t = (k+u)/n\), for every \(k\) and \(u\). This asks for more than the two curves being close. Section 6 says why fonts need it.

Until now the answer was found by trying. The single quadratic first; then the spline for \(n = 2, 3, \dots\), up to 100 in fontTools, each built and each of its quadratics tested against its piece. The test, cubic_farthest_fit_inside, takes the difference of the two curves, which is itself a cubic Bézier, and halves it until its control points are within \(\varepsilon\) of the origin, which settles that it is inside, or its middle is farther than \(\varepsilon\), which settles that it is not. It is exact up to rounding, and it is a large part of the work.

∞ 3. The error in closed form

∞ One vector

Let

\[\mathbf{d}_3 = \mathbf{c}_3 - 3\,\mathbf{c}_2 + 3\,\mathbf{c}_1 - \mathbf{c}_0\]

be the third difference of the control points. It is the coefficient of \(t^3\) in \(C(t)\), and it is zero exactly when the cubic is a quadratic written with four points. Each of the \(n\) pieces, with its own parameter from 0 to 1, has the third difference \(\mathbf{d} = \mathbf{d}_3/n^3\). Everything below comes from two facts, one about a piece and one about two neighbours.

Lemma 1. Let a piece have control points \(\mathbf{p}_0, \dots, \mathbf{p}_3\) and third difference \(\mathbf{d}\), and let \(\mathbf{m} = \tfrac12(\mathbf{q}^{+} + \mathbf{q}^{-})\) be the point halfway between its candidates. Then \(\mathbf{q}^{+} - \mathbf{q}^{-} = \tfrac12\,\mathbf{d}\), and the quadratic with control points \(\mathbf{p}_0 + \mathbf{x}_0\), \(\mathbf{m} + \mathbf{x}_1\), \(\mathbf{p}_3 + \mathbf{x}_2\) differs from the piece, at parameter \(u\), by

\[(1-u)^2\,\mathbf{x}_0 + 2u(1-u)\,\mathbf{x}_1 + u^2\,\mathbf{x}_2 + \tfrac12\,u(1-u)(2u-1)\,\mathbf{d}.\]

Proof. From the definitions, \(\mathbf{q}^{+} - \mathbf{q}^{-} = \tfrac12(\mathbf{p}_3 - 3\mathbf{p}_2 + 3\mathbf{p}_1 - \mathbf{p}_0)\) and \(\mathbf{m} = \tfrac14\,(3\mathbf{p}_1 + 3\mathbf{p}_2 - \mathbf{p}_0 - \mathbf{p}_3)\). Written as a cubic, the quadratic \((\mathbf{p}_0, \mathbf{m}, \mathbf{p}_3)\) has the inner control points \(\tfrac13(\mathbf{p}_0 + 2\mathbf{m}) = \mathbf{p}_1 - \tfrac16\mathbf{d}\) and \(\tfrac13(2\mathbf{m} + \mathbf{p}_3) = \mathbf{p}_2 + \tfrac16\mathbf{d}\), so it differs from the piece by

\[3u(1-u)^2\left(-\tfrac16\mathbf{d}\right) + 3u^2(1-u)\left(\tfrac16\mathbf{d}\right) = \tfrac12\,u(1-u)(2u-1)\,\mathbf{d}.\]

Moving the three control points of a quadratic by \(\mathbf{x}_0, \mathbf{x}_1, \mathbf{x}_2\) moves its point at \(u\) by \((1-u)^2\mathbf{x}_0 + 2u(1-u)\mathbf{x}_1 + u^2\mathbf{x}_2\). ∎

Lemma 2. Let two consecutive pieces of a cubic, of equal parameter length, meet at the point \(\mathbf{j}\) of the cubic. Then the halfway point \(\mathbf{m}\) of the first and that of the second have \(\mathbf{j}\) as their midpoint.

Proof. The pieces have equal parameter lengths, so the cubic’s derivative at \(\mathbf{j}\) gives them the same handle there: the first ends with \(\mathbf{p}_3 - \mathbf{p}_2 = \mathbf{h}\) and the second starts with \(\mathbf{p}_1 - \mathbf{p}_0 = \mathbf{h}\). Hence the second candidate of the first piece is \(\mathbf{j} - \tfrac32\mathbf{h}\) and the first candidate of the second piece is \(\mathbf{j} + \tfrac32\mathbf{h}\). By Lemma 1 the halfway points are those plus and minus \(\tfrac14\mathbf{d}\), with the same \(\mathbf{d}\) for both pieces. ∎

∞ The error of the spline

Write the off-curve point of piece \(k\) as \(\mathbf{o}_k = \mathbf{m}_k + \tfrac14\,s_k\,\mathbf{d}\). By Lemma 1 the weight \(s_k = +1\) is the first candidate and \(s_k = -1\) the second, and cu2qu’s rule is the ramp

\[s_k = 1 - \frac{2k}{n-1}, \qquad k = 0, \dots, n-1.\]

By Lemma 2, the implied on-curve point between pieces \(k-1\) and \(k\) is \(\tfrac12(\mathbf{o}_{k-1} + \mathbf{o}_k) = C(k/n) + g_k\,\mathbf{d}\), with

\[g_k = \frac{s_{k-1} + s_k}{8} = \frac{n - 2k}{4(n-1)} \quad\text{for } 0 \lt k \lt n, \qquad g_0 = g_n = 0,\]

the last two because the spline starts and ends on the cubic. Lemma 1, with \(\mathbf{x}_0 = g_k\mathbf{d}\), \(\mathbf{x}_1 = \tfrac14 s_k\mathbf{d}\) and \(\mathbf{x}_2 = g_{k+1}\mathbf{d}\), now gives the whole error.

Theorem 1. Quadratic \(k\) of the spline at parameter \(u\), minus the cubic at \(t = (k+u)/n\), is \(\varphi_k(u)\,\mathbf{d}\), where

\[\varphi_k(u) = g_k\,(1-u)^2 + g_{k+1}\,u^2 + \tfrac12\,u(1-u)\,(2u - 1 + s_k).\]

The error always points along \(\mathbf{d}_3\). Its size, in units of \(\lvert\mathbf{d}_3\rvert/n^3\), has nothing to do with the cubic: it is the same function for every cubic there is (Figure 2).

The error of the spline along the cubic, for two, three and more quadratics Plots of the difference between the spline and the cubic against the cubic's parameter, in units of the third difference of a piece. Each piece is a cubic polynomial; the largest value is in the first piece and, mirrored, in the last: 4/27 for two quadratics, 27/128 for three, 0.256 for six. Where pieces meet the difference is not zero, except at the middle of an even number of pieces. Φ(2) = 4/27 n = 2 0 1 t ¼ 0 −¼ Φ(3) = 27/128 n = 3 0 1 t Φ(6) = 0.256 n = 6 0 1 t
Figure 2. \(\varphi_k(u)\) along the cubic, for two, three and, as first drawn, six quadratics. The filled dot is the largest value, \(\Phi(n)\); it is in the first piece, and the last piece mirrors it. The open dots are the implied on-curve points, which are off the cubic by \(g_k\,\mathbf{d}\); the middle one of an even number of quadratics is on it.

∞ Its largest value

For the ramp the polynomials are simple. In the first piece,

\[\varphi_0(u) = (1 + g_1)\,u^2 - u^3, \qquad g_1 = \frac{n-2}{4(n-1)},\]

which is largest at \(u = \tfrac23(1+g_1)\), where it is \(\tfrac{4}{27}(1+g_1)^3\). The last piece is its mirror image, \(\varphi_{n-1}(u) = -\varphi_0(1-u)\). In the pieces between, with \(v = u - \tfrac12\),

\[\varphi_k(u) = \tfrac14\,s_k + \beta\,v - v^3, \qquad \beta = \frac{n-3}{4(n-1)}:\]

the same odd cubic in every piece, on a constant that ramps down from piece to piece. Its largest value over those pieces is in the second piece. From \(n = 9\) on that is \(\beta + 2(\beta/3)^{3/2}\), at \(v = \sqrt{\beta/3}\); for fewer pieces it is where the second piece meets the first, and below the first piece’s maximum.

Theorem 2. The largest distance, at equal parameters, between a cubic and its spline of \(n \ge 2\) quadratics is \(\lvert\mathbf{d}_3\rvert\,\Phi(n)/n^3\), with

\[\Phi(n) = \max\left\{ \frac{4}{27}\,(1+g_1)^3,\ \ \beta + 2\left(\frac{\beta}{3}\right)^{3/2} \right\},\]

with \(g_1 = \frac{n-2}{4(n-1)}\) and \(\beta = \frac{n-3}{4(n-1)}\) as above, where the second term counts from \(n = 4\). \(\Phi(2) = 4/27\), \(\Phi(3) = 27/128\), and \(\Phi\) grows with \(n\) towards \(\tfrac14 + \tfrac{\sqrt3}{36} \approx 0.2981\). The first term is the larger one up to \(n = 54\). (The second is the largest value of the pieces between only from \(n = 9\); below that it is one of their values, and less than the first term.)

∞ The number of quadratics

So the spline of \(n\) quadratics is within tolerance exactly when

\[\lvert\mathbf{d}_3\rvert \le \varepsilon\,L(n), \qquad L(n) = \frac{n^3}{\Phi(n)}.\]

\(L\) grows with \(n\), because \(\Phi\) grows more slowly than \(n^3\): from \(n\) to \(n+1\) its first term grows by the factor \(\bigl(1 + \tfrac{1}{n(5n-6)}\bigr)^3\) and its second by less than \(\bigl(1 + \tfrac{2}{n(n-3)}\bigr)^{3/2}\), and both are below \(\bigl(1 + \tfrac1n\bigr)^3\). So the number of quadratics a cubic takes is the least \(n\) whose limit holds its third difference (Table 1). It takes a third difference, one length, and a walk up a table that is the same for every cubic (Appendix A). The spline is then built once, with the same arithmetic as before, and not tested.

Table 1. The error factor and the limit of \(\lvert\mathbf{d}_3\rvert/\varepsilon\) for cu2qu’s spline, and the limit for the best weights that start and end with the cubic’s derivative (section 4).
\(n\)\(\Phi(n)\)\(L(n)\)best weights
20.148155454
30.21094128128
40.23525272.05432
50.24808503.86823.02
60.25600843.751,458
70.261371,312.312,296.10
80.265251,930.243,456
90.268192,718.244,917.60
100.270493,697.036,750
160.2779314,737.4527,648
1000.291613,429,220.626,750,000

Three remarks.

∞ 4. How good are the weights?

The ramp is one choice of weights. Theorem 1 did not use it: for any weights \(s_0, \dots, s_{n-1}\) the error is \(\varphi_k(u)\,\mathbf{d}\) with \(g_k = (s_{k-1} + s_k)/8\). Nor is there anything to gain from moving an off-curve point off the line through its two candidates. If \(\mathbf{o}_k = \mathbf{m}_k + \tfrac14 s_k\mathbf{d} + \mathbf{x}_k\) with \(\mathbf{x}_k\) across \(\mathbf{d}\), the part of the error along \(\mathbf{d}\) is still \(\varphi_k(u)\,\mathbf{d}\), and the \(\mathbf{x}_k\) only add a part across it, which makes it longer. So the weights cover every spline of \(n\) quadratics with implied on-curve points, as long as it is compared with the cubic piece by piece at equal parameters.

Two of the weights have a meaning of their own. With \(s_0 = 1\) the first off-curve point is the first candidate, and the spline starts with the cubic’s derivative: its first handle is \(\tfrac{3}{2n}\) of the cubic’s. With \(s_{n-1} = -1\) it ends with the cubic’s derivative. cu2qu’s spline does both. That is more than keeping the end tangents, for which an off-curve point may be anywhere on the tangent line.

Theorem 3. For every \(n \ge 1\) and every choice of weights, the largest \(\lvert\varphi_k(u)\rvert\) is at least \(\sqrt3/36 \approx 0.0481\), and it is exactly that when all weights are zero. If \(s_0 = 1\) or \(s_{n-1} = -1\), it is at least \(4/27 \approx 0.1481\).

Proof. Take the second claim first, with \(s_0 = 1\); the other end follows by reversing the cubic, which turns the weights \(s_k\) into \(-s_{n-1-k}\). From Theorem 1, for every \(k\),

\[\begin{aligned} \varphi_k\!\left(\tfrac23\right) &= \phantom{-}\tfrac{4}{27} + \tfrac19\,(4g_{k+1} + g_k) + \tfrac19\,(s_k - 1), \\ \varphi_k\!\left(\tfrac13\right) &= -\tfrac{4}{27} + \tfrac19\,(g_{k+1} + 4g_k) + \tfrac19\,(s_k + 1). \end{aligned}\]

Suppose every \(\lvert\varphi_k(u)\rvert\) were below 4/27. For an even \(k\) with \(g_k \ge 0\) and \(s_k \ge 1\), which holds for \(k = 0\), the first identity gives \(\varphi_k(\tfrac23) \ge \tfrac{4}{27} + \tfrac49 g_{k+1}\), so \(g_{k+1} \lt 0\), and then \(s_{k+1} = 8g_{k+1} - s_k \lt -1\). For an odd \(k\) with \(g_k \lt 0\) and \(s_k \lt -1\), the second identity gives \(\varphi_k(\tfrac13) \lt -\tfrac{4}{27} + \tfrac19 g_{k+1}\), so \(g_{k+1} \gt 0\) and \(s_{k+1} \gt 1\). So the signs alternate all the way along the spline, and the last step asks for \(g_n \ne 0\). But \(g_n = 0\): the spline ends on the cubic.

The first claim goes the same way with the two parameters \(u_\pm = \tfrac12 \pm \tfrac{\sqrt3}{6}\), where \(u(1-u) = \tfrac16\) and \((1 - u_\pm)^2 = u_\mp^2\):

\[\begin{aligned} \varphi_k(u_+) &= \phantom{-}\tfrac{\sqrt3}{36} + u_-^2\,g_k + u_+^2\,g_{k+1} + \tfrac{1}{12}s_k, \\ \varphi_k(u_-) &= -\tfrac{\sqrt3}{36} + u_+^2\,g_k + u_-^2\,g_{k+1} + \tfrac{1}{12}s_k. \end{aligned}\]

Suppose every \(\lvert\varphi_k(u)\rvert\) were below \(\sqrt3/36\). The first piece, where \(g_0 = 0\), gives \(u_+^2\,g_1 + \tfrac{1}{12}s_0 \lt 0 \lt u_-^2\,g_1 + \tfrac{1}{12}s_0\), hence \(g_1 \lt 0 \lt s_0\), as \(u_+ \gt u_-\). For an odd \(k\) with \(g_k \lt 0\) and \(s_k \lt 0\), which \(k = 1\) is since \(s_1 = 8g_1 - s_0\), the second identity gives \(u_-^2\,g_{k+1} \gt -u_+^2\,g_k - \tfrac{1}{12}s_k \gt 0\), so \(g_{k+1} \gt 0\) and \(s_{k+1} = 8g_{k+1} - s_k \gt 0\). For an even \(k \ge 2\) with \(g_k \gt 0\) and \(s_k \gt 0\), the first gives \(u_+^2\,g_{k+1} \lt -u_-^2\,g_k - \tfrac{1}{12}s_k \lt 0\), so \(g_{k+1} \lt 0\) and \(s_{k+1} \lt 0\). Again the signs alternate up to \(g_n \ne 0\). With all weights zero every \(g_k\) is zero and \(\varphi_k(u) = \tfrac12 u(1-u)(2u-1)\), whose largest size is \(\sqrt3/36\), at \(u_\pm\). ∎

What the theorem says:

The last column of Table 1 has the limits of those best weights, and Figure 3 the number of quadratics each choice takes. For a long curve the ramp takes \(\sqrt[3]{0.2981 / 0.1481} = 1.26\) times the quadratics of the best weights. In fonts the difference is much less, because a cubic that takes two or three quadratics has nothing to gain, and most do. In the fonts of section 8 the best weights would save 0.6% of the quadratics at a tolerance of one unit, 2.6% at half a unit, and 10.6% at a tenth. They would also move every curve of four quadratics or more in every font that is rebuilt. cu2qu keeps the ramp.

How many quadratics a cubic takes, against its third difference Step functions of the number of quadratics against the length of the third difference divided by the tolerance, on a logarithmic axis from 10 to 10,000. cu2qu takes two up to 54, three up to 128, four up to 272, and fifteen at 10,000; the best weights with the same ends take twelve there; the mid-point spline, which does not keep them, takes eight. Half of the cubics of the three fonts are below 27.7 at a tolerance of one unit. 5 10 15 1 10 100 1,000 10,000 quadratics length of the third difference / tolerance mid-point: 8 best weights: 12 cu2qu: 15 cu2qu best weights, same ends as cu2qu mid-point: end tangents not kept 50% 90% 99%
Figure 3. The number of quadratics against the length of the third difference over the tolerance, for cu2qu, for the best weights that start and end with the cubic’s derivative, and for the mid-point spline, which does not keep the end tangents. The marks under the axis show where the cubics of three fonts are at a tolerance of one unit: half of them are below 27.7, 90% below 131.6 and 99% below 336. To the left of 20.8 a single quadratic may fit, depending on the cubic (section 5).

∞ 5. One quadratic

The single quadratic has its off-curve point at \(\mathbf{q}\), where the lines through \(\mathbf{c}_0, \mathbf{c}_1\) and through \(\mathbf{c}_2, \mathbf{c}_3\) meet. By Lemma 1 it differs from the cubic by

\[u(1-u)\left[\,2\,(\mathbf{q} - \mathbf{m}) + \tfrac12\,(2u-1)\,\mathbf{d}_3\,\right],\]

and \(\mathbf{q} - \mathbf{m}\) does not lie along \(\mathbf{d}_3\) in general. So this error depends on the shape of the cubic, and cu2qu keeps testing it, with the recursive test.

∞ When it cannot fit

The part of that error along \(\mathbf{d}_3\) is the case \(n = 1\) of Theorem 3: wherever the off-curve point is, a quadratic with the cubic’s end points is at least \(\tfrac{\sqrt3}{36}\lvert\mathbf{d}_3\rvert\) from the cubic somewhere, at equal parameters. So no single quadratic fits when

\[\lvert\mathbf{d}_3\rvert \gt \frac{36}{\sqrt3}\,\varepsilon \approx 20.78\,\varepsilon,\]

and there is no need to intersect tangents or to run the test. In the fonts of section 8 this rules out 61% of the cubics at a tolerance of one unit, 80% at half a unit and 97% at a tenth. Of the rest, few pass: 6.3%, 2.4% and 0.3% of all cubics. The implementations compare with 21, so that the bound can change no result.

∞ When the test does not return

The recursive test stops at a piece of the difference curve whose inner control points are within \(\varepsilon\), and at one whose middle is beyond \(\varepsilon\). A difference that touches \(\varepsilon\) at its farthest point, without crossing, has a piece that never becomes either. In floating point one control point of that piece can stay one unit in the last place outside while its middle rounds to \(\varepsilon\) itself, and the half that contains the touching point is the same piece again. It takes a tolerance and a curve whose bits line up. These are two:

curve_to_quadratic([(0, 0), (0, 0), (0, 0), (25, 0)], 100 / 27)
curve_to_quadratic([(-45, -3), (-30, -2), (0, 5), (0, 9)], 20 / 3)

In the first, the difference is \(25\,u^2(1-u)\) along the \(x\) axis, which peaks at exactly 100/27. With fontTools 4.60.1 each of the two calls ends in a RecursionError in pure Python and takes the interpreter down with the compiled module. Both are single quadratics. The same happens in the search over \(n\), to a spline exactly at a limit of Table 1, as in these two, whose third differences are 128 × 5 and 843.75 × 4:

curve_to_quadratic([(-258, -394), (-148, -194), (-155, -13), (105, 661)], 5)
curve_to_quadratic([(-22, 289), (31, 324), (-137, 476), (1499, 3445)], 4)

kurbo’s port, whose arithmetic differs from fontTools’ in the last bit, returns from these four and overflows its stack on others: in the search over \(n\) on the cubic (386, −158), (527, −28), (480, −99), (2270, 2329) at an accuracy of 4, again 843.75 × 4, and on single quadratics such as (−20, 7), (−20, −27.5), (−12, −32.5), (4, −32) at 32/9. A NaN coordinate or tolerance does the same in both, because every comparison with it is false.

The repair proposed for both is a limit of 64 halvings, after which the control points of a piece differ by rounding alone and the piece is taken to be where its middle is, and comparisons written so that a NaN ends the recursion. With \(n\) computed, the spline no longer goes through the test at all.

∞ 6. Masters: why equal parameters

A variable font stores masters and interpolates between them: every control point of an instance is the same weighted average of that point in the masters. The masters have to be converted together, to the same number of points, and what the conversion did to the masters has to hold in every instance. That decides the measure.

∞ Instances inherit the bound

Let master \(i\) have the cubic \(C_i\) and the spline \(S_i\), and let an instance have the coefficients \(w_i\), which add up to one. Its cubic is \(\sum_i w_i C_i\) and its spline is \(\sum_i w_i S_i\), both at every parameter, because Bézier curves are linear in their control points. So at equal parameters

\[\Bigl\lvert \sum_i w_i\,S_i(t) - \sum_i w_i\,C_i(t) \Bigr\rvert \;\le\; \sum_i \lvert w_i\rvert\,\bigl\lvert S_i(t) - C_i(t) \bigr\rvert \;\le\; \varepsilon \sum_i \lvert w_i\rvert,\]

which is \(\varepsilon\) when no coefficient is negative, as for an instance between two masters. So if each master is within tolerance at equal parameters, every such instance is.

Nothing like this holds for the distance between the curves as sets of points. Take a master whose cubic is the straight segment from (0, 0) to (1, 0), with its control points a third and two thirds of the way, and whose quadratic is the same segment with its control point at (0.1, 0); and a second master with the segment from (0, 0) to (0, 1), the quadratic’s control point at (0, 0.5). In each master the two curves are the same set of points. Halfway between the masters the cubic is the straight segment to (0.5, 0.5), and the quadratic, with its control point at (0.05, 0.25), bulges 0.07 away from it. Each master’s quadratic runs along its cubic at a pace of its own, and averaging the masters puts together points that were never near each other.

∞ Smooth joints stay smooth

Take an on-curve point where two curves join smoothly, with the handle \(\mathbf{h}^{-}\) arriving and the handle \(\mathbf{h}^{+}\) leaving. Smooth means \(\mathbf{h}^{+} = r\,\mathbf{h}^{-}\) with \(r \gt 0\), the ratio of the two handle lengths. For two masters and the instance at \(\mu\) between them, \(\mathbf{h}^{-} = (1-\mu)\,\mathbf{h}_1^{-} + \mu\,\mathbf{h}_2^{-}\) and \(\mathbf{h}^{+} = (1-\mu)\,r_1\mathbf{h}_1^{-} + \mu\,r_2\mathbf{h}_2^{-}\), and their cross product is

\[\mathbf{h}^{-} \times \mathbf{h}^{+} = \mu(1-\mu)\,(r_2 - r_1)\,\bigl(\mathbf{h}_1^{-} \times \mathbf{h}_2^{-}\bigr).\]

The instance can be smooth only when this is zero: when the two masters have the same ratio of handles at the joint, or handles along the same line (Figure 4). That is the rule for drawing masters that interpolate without kinks, and a converter must not break it.

A smooth joint in two masters, and between them Two rows of three drawings: a joint between two curves in master 1, in an instance between the masters, and in master 2. In the first row the two handles at the joint have lengths in the ratio 2 to 1 in both masters, and the instance is smooth. In the second row the ratio is 2 to 1 in one master and 1 to 2 in the other, and the instance has a corner. master 1 halfway master 2 the same ratio in both masters handles 2 : 1 handles 2 : 1 smooth different ratios handles 2 : 1 handles 1 : 2 a corner of 16°
Figure 4. A joint that is smooth in two masters (grey), and in an instance between them (red), halfway as first drawn. With the same ratio of handle lengths in both masters the instance is smooth, though the masters’ tangents point in different directions. With different ratios it has a corner.

The spline of \(n \ge 2\) does not break it, for three reasons that are one:

This is what cutting every master at the same parameters, with the same weights, is for. A conversion that picks its cuts or its control points by the shape of each master, as the intersection of tangents does, gives each master ratios of its own. The 2015 notes say it in one line [4]: curves remain interpolation-compatible if, at every new on-curve point, the ratio of the distances to the control points on its two sides is the same in all masters.

∞ The exception

The single quadratic is the one place where cu2qu is not linear. Its handles are the cubic’s, stretched to reach \(\mathbf{q}\): \(\mathbf{q} - \mathbf{c}_0 = (\mathbf{c}_1 - \mathbf{c}_0)/\lambda_1\) and \(\mathbf{c}_3 - \mathbf{q} = (\mathbf{c}_3 - \mathbf{c}_2)/\lambda_2\), where \(\lambda_1\) and \(\lambda_2\) say how far along the way to \(\mathbf{q}\) the cubic’s control points are. The directions are the cubic’s, so each master stays smooth. But the \(\lambda\) differ from master to master, so equal ratios across a joint do not stay equal, and by the formula above an instance can get a corner where the cubic masters had none, if the masters’ tangents there point in different directions.

How much it does was measured on the masters of 24 variable fonts: Cantarell, Noto Sans CJK and Noto Serif CJK as they are shipped, and the sources of 21 design spaces of other Noto families, of 2 to 16 masters each, converted at a thousandth of the em. They have 3.59 million cubics, of which 12.5% become single quadratics, most of them in Noto Serif CJK. A joint was counted when its two tangents are exactly parallel in every master. Of 1,056,932 such joints, 194,219 have a single quadratic on at least one side. All but 4,939 of those are horizontal or vertical in every master, and there the ratio cannot matter; nearly all of the 4,939 are in the two CJK fonts, which have two masters each. At these, over the instances a quarter, a half and three quarters of the way between every two masters, the conversion changes the angle of the joint by more than a tenth of a degree at 616, by more than half a degree at 70 and by more than a degree at 26; the largest change is 4.4 degrees, at a joint where it reaches 4.6 elsewhere between the same two masters. Rounding the off-curve points to integers, which a glyf table needs anyway, changes the angle by more than those amounts at 2,175, 1,932 and 1,850 of the same joints.

Tangents that are exactly parallel are rare off the axes. With joints counted that are smooth to within a degree in every master, 34,785 that are not horizontal or vertical have a single quadratic beside them; the conversion changes 4,951, 547 and 33 of them by more than those amounts, and rounding 28,885, 22,525 and 18,960.

At the 862,713 exactly smooth joints with no single quadratic beside them, the conversion changes nothing in those instances, to within \(10^{-11}\) of a degree, except at 69 where an instance has a handle of no length: at 50 because the handles of two masters cancel there, at 19 because no master has one. The tangent then comes from the control point further away, which the spline does not keep (section 10), and at 29 of the 69 the angle changes by more than a tenth of a degree. At two more joints a master itself has such a handle, and the angle changes there, by 27 and 11 degrees. So the exception is real, it is small beside rounding, and cu2qu leaves it.

∞ What the measure costs

Being within tolerance at equal parameters is a stronger demand than being within tolerance. For the fonts of section 8, the distance between each cubic and its splines as sets of points was measured. cu2qu’s output is on average 0.27, 0.34 and 0.45 of the tolerance away, at tolerances of one, a half and a tenth of a unit. Had the same constructions been accepted by that distance, they would have taken 1.70, 2.11 and 3.69 quadratics per cubic where cu2qu takes 2.34, 2.84 and 4.80: about a quarter fewer. At a tolerance of one unit, 69% of that saving is in cubics for which one quadratic would do: 6.3% of the cubics pass as one quadratic at equal parameters, and 45.8% are within a unit of that quadratic as curves. At half a unit it is 52% of the saving, and at a tenth 22%.

∞ 7. Without masters: one quadratic by distance

A renderer converts an outline once, for one instance, and nothing is interpolated afterwards. The distance between the curves is then the right measure, and the single quadratic is where it pays most. HarfBuzz’s GPU library, whose shaders take quadratics only, converts the cubics of CFF and CFF2 outlines at a tolerance of half a unit.

Let \(\mathbf{q}\) be where the end tangents meet, \(\mathbf{a} = \mathbf{q} - \mathbf{c}_0\) and \(\mathbf{z} = \mathbf{c}_3 - \mathbf{q}\) the two legs of the quadratic \(Q\), and let the cubic’s control points be \(\mathbf{c}_1 = \mathbf{c}_0 + \lambda_1\mathbf{a}\) and \(\mathbf{c}_2 = \mathbf{c}_3 - \lambda_2\mathbf{z}\). A cubic with \(\lambda_1 = \lambda_2 = \tfrac23\) is the quadratic itself.

Theorem 4. The cubic is the quadratic at another parameter, plus an offset along one fixed direction:

\[C(t) = Q(\tau(t)) + \rho(t)\,(\mathbf{a} - \mathbf{z}),\]

where

\[\begin{aligned} \tau(t) &= t + 3t(1-t)\,e(t), \\ \rho(t) &= 3t^2(1-t)^2\left(\lambda_1 + \lambda_2 - \tfrac43 + 3\,e(t)^2\right), \\ e(t) &= (1-t)\left(\tfrac{\lambda_1}{2} - \tfrac13\right) + t\left(\tfrac13 - \tfrac{\lambda_2}{2}\right). \end{aligned}\]

Proof. Measured from \(\mathbf{c}_0\), the quadratic is \(Q(\tau) = (2\tau - \tau^2)\,\mathbf{a} + \tau^2\,\mathbf{z}\) and the cubic is \(C(t) = A(t)\,\mathbf{a} + Z(t)\,\mathbf{z}\) with \(A = 3t(1-t)^2\lambda_1 + 3t^2(1-t) + t^3\) and \(Z = 3t^2(1-t)(1-\lambda_2) + t^3\). Choose \(\tau = \tfrac12(A + Z)\). Then \(C(t) - Q(\tau) = (\tau^2 - Z)(\mathbf{a} - \mathbf{z})\), and working out \(\tau\) and \(\tau^2 - Z\) gives the two expressions. ∎

\(\tau\) is a Bézier function with the control values \(0,\ \lambda_1/2,\ 1 - \lambda_2/2,\ 1\). For \(\lambda_1\) and \(\lambda_2\) from 0 to 2 these are between 0 and 1, so \(\tau\) takes the interval from 0 to 1 onto itself: every point of the cubic is \(\lvert\rho\rvert\,\lvert\mathbf{a} - \mathbf{z}\rvert\) from a point of the quadratic, and every point of the quadratic is that far from one of the cubic. As \(t^2(1-t)^2 \le \tfrac1{16}\), the two curves are within

\[\frac{3}{16}\,\max_t\,\Bigl\lvert \lambda_1 + \lambda_2 - \tfrac43 + 3\,e(t)^2 \Bigr\rvert\ \lvert\mathbf{a} - \mathbf{z}\rvert\]

of each other as sets of points. Here \(e\) runs in a straight line from \(\lambda_1/2 - \tfrac13\) to \(\tfrac13 - \lambda_2/2\), so \(e^2\) lies between the smaller of their squares, or zero if they differ in sign, and the larger; the maximum is at one of those two values, and the bound is a few multiplications.

The direction \(\mathbf{a} - \mathbf{z}\) is the axis of the parabola, and its length is twice the distance from \(\mathbf{q}\) to the middle of the chord. So the cubic leaves its quadratic only along the parabola’s axis. The offset vanishes at the middle of the curve when \(\lambda_1 + \lambda_2 = \tfrac43 - \tfrac{3}{16}(\lambda_1 - \lambda_2)^2\). So the cubic stays close when its two handles together reach 4/3 of the way to \(\mathbf{q}\), less a correction that grows with the square of their difference. At equal parameters each has to reach 2/3. The cubic of Figure 5 has 0.27 of the way at one end and 0.97 at the other.

A cubic and the quadratic of its end tangents, at equal parameters A cubic with one short and one long handle lies almost on the quadratic whose off-curve point is where its end tangents meet. Arcs join the point of the cubic and the point of the quadratic at the same parameter, for four parameters: they are far apart along the curve, though the two curves are close. t = 0.2 t = 0.4 t = 0.6 t = 0.8 c0​ c3​ c1​ c2​ q the cubic the quadratic of its end tangents the cubic at a parameter the quadratic at the same parameter

handles 0.27 and 0.97 of the way, 1.24 together. At equal parameters 70.7 apart; as curves 0.74; the bound 2.41.

Figure 5. A cubic and the quadratic of its end tangents, which cannot be told apart at this size. As first drawn, the handles of the cubic are 0.27 and 0.97 of the way to \(\mathbf{q}\). Each arc joins the point of the cubic and the point of the quadratic at one parameter. At equal parameters the two curves are up to 71 apart, on a chord of 520; as curves they are 0.7 apart, and the bound says 2.4. The figure has room for handles up to 1.33 of the way; the theorem goes up to 2.

HarfBuzz now accepts the single quadratic by this bound; where a handle has no length it takes the tangent toward the other control point. Of the cubics of section 8, at its tolerance of half a unit, 24.4% become one quadratic, where 2.4% did at equal parameters; 33.3% are in fact that close to this quadratic. Quadratics per cubic go from 2.84 to 2.59. The bound is never below the measured distance; its median is 1.10 times it. The rule of section 5 has to go when this comes in, since a single quadratic now fits well beyond it. And the bound is not for masters: it says nothing about instances.

∞ 8. In practice

The numbers in this note are for the cubics of three fonts as Fedora 43 ships them: all of Source Code Pro Regular 2.042, and the first 3,000 glyphs of STIX Two Math 2.13 and of Noto Sans SC Regular 2.004. That is 77,533 cubics with integer coordinates, at 1,000 units per em. Half of them have a third difference shorter than 27.7 units, and the longest is 1,574.

Table 2. Quadratics per cubic for those fonts. The first row is cu2qu, searched or computed. The last is not a converter: it is the least number for which cu2qu’s construction is within tolerance as curves, by measurement.
tolerance, units10.50.1
cu2qu2.3362.8384.802
the same with the best weights (section 4)2.3222.7634.291
HarfBuzz’s converter: one quadratic by distance (section 7)1.9982.5854.673
mid-point spline, end tangents not kept1.6881.9843.037
cu2qu’s construction, accepted by measured distance1.7032.1073.694

At a tolerance of one unit, 6.3% of the cubics become one quadratic, 65.9% two, 17.6% three, 8.7% four, and 1.6% more, up to eight. HarfBuzz itself draws a cubic as a line when both of its control points are within the tolerance of the line through its ends, before its converter is reached. That is 2.1% of these cubics at half a unit, and takes its 2.585 down to 2.526 segments per cubic.

∞ Where it is

Table 3. fontTools before and after, per call, on the cubics above: instructions, and microseconds in parentheses. curves_to_quadratic is given the cubics three at a time, as if they were three masters.
compiled, beforeafterpure Python, beforeafter
curve_to_quadratic, tolerance 121,118 (1.46)15,885 (1.10)84,471 (5.63)47,427 (3.17)
curve_to_quadratic, tolerance 0.528,871 (2.01)19,112 (1.34)118,338 (8.12)56,543 (3.97)
curves_to_quadratic, tolerance 167,083 (4.51)57,198 (3.83)252,984 (17.92)156,125 (10.75)

∞ What changes in the output

Nothing but the ties of section 3. On the 77,533 cubics, fontTools before and after gives the same coordinates for all but 3 cubics at a tolerance of one unit, 7 at half a unit and none at a tenth; each of the ten has a third difference of exactly 128 times the tolerance and goes from four quadratics to three. Converted together, the 3,589,652 groups of compatible masters of section 6 give the same coordinates before and after for all but 142, all in the two CJK fonts and each from four quadratics to three.

Replacing a Bézier curve by one of lower degree, with the least error at equal parameters, is the old subject of degree reduction: Watkins and Worsey [13], Lachance [14], and Eck [15], who keeps conditions at the ends by way of constrained Chebyshev polynomials. (These three are cited from their abstracts and from what later papers say of them; they were not read for this note.) For a cubic and one quadratic the answers are short. With nothing kept at the ends the least error is \(\lvert\mathbf{d}_3\rvert/32\), by Chebyshev’s cubic. With the end points kept it is \(\tfrac{\sqrt3}{36}\lvert\mathbf{d}_3\rvert\), the case \(n = 1\) of Theorem 3, and the mid-point quadratic reaches it.

Much of what sections 2 to 4 use is in Colomitchi’s note of 2006 [8]: the distance at equal parameters as the measure; the two candidates, and that they are half the third difference apart, which is the first statement of Lemma 1; the error 4/27 of the quadratic that takes one of them; the mid-point quadratic and its error \(\tfrac{\sqrt3}{36}\lvert\mathbf{d}_3\rvert\); and the cube law for a piece of the cubic, from which he computes where to cut, a piece at a time. Biły [16] has the same quadratic and error, the cube law for equal pieces, and the number of pieces as a cube root. kurbo’s to_quads computes it as \(\bigl\lceil \sqrt[6]{\lvert\mathbf{d}_3\rvert^2 / (432\,\varepsilon^2)}\, \bigr\rceil\), and so does lyon, which credits Raph Levien with the derivation [3] [10]. So computing the count from the third difference is known for the spline that does not keep the end tangents, where the factor is one number.

Truong, Yuksel and Seiler [9] replace a cubic by a pair of quadratics that starts and ends with its derivative. They measure the error at equal parameters and show that it is least when the two have equal parameter lengths, where it is 1/54 of the length of the third difference. That pair is cu2qu’s spline of two quadratics, and 1/54 is \(\Phi(2)/2^3\), the first row of Table 1. For more accuracy they cut the cubic into more cubics first, by that error; the alternating weights of section 4 are their pairs on equal pieces.

FontForge’s documentation describes dividing a cubic evenly, taking each control point where the tangents at the two ends of a division meet, and adding points until the result is close [11]. It notes, as something found by trial, that the on-curve points are then midway between the control points, so that TrueType can leave them out. For the points halfway between the candidates that is Lemma 2, and exact; where tangents meet it holds nearly. cubic2quad follows FontForge: it cuts at inflection points, then tries one to eight even divisions, with the error measured at sampled points [12]. Both search.

What this note adds is the error of the spline that starts and ends with the cubic’s derivative, for every \(n\) and every choice of weights (Theorem 1); its largest value for cu2qu’s ramp from three quadratics on (Theorem 2); the bounds of Theorem 3 for every \(n\); and Theorem 4. None of these was found in the sources above.

∞ 10. Loose ends

∞ About this note

This note was written by Claude, Anthropic’s AI model, working in Claude Code at Behdad Esfahbod’s direction: the derivations, the code, the measurements, the figures and the text. Appendix B lists the scripts that check its formulas and produce its numbers. Two further instances of the model were then asked to find what is wrong with it. What they found, and what was done about it, is in the notes.

∞ Appendix A. The computation

In Python, as proposed for fontTools. Its g and c are \(g_1\) and \(\beta\) above, and the table is built once.

import math

MAX_N = 100


def spline_error_factor(n):
    """How far the spline of n > 1 quadratics gets from its cubic at equal
    parameters, over the length of the cubic's third difference divided by n**3."""
    g = (n - 2) / (4 * (n - 1))
    error = (4 / 27) * (1 + g) * (1 + g) * (1 + g)  # first and last piece
    if n > 3:
        c = (n - 3) / (4 * (n - 1))
        w = c / 3
        error = max(error, c + 2 * w * math.sqrt(w))  # second and next to last
    return error


SPLINE_MAX_D3 = [0.0, 0.0] + [
    n * n * n / spline_error_factor(n) for n in range(2, MAX_N + 1)
]


def cubic_spline_n(cubic, tolerance):
    """The least number of quadratics, from 2, whose spline is within tolerance
    of the cubic (four complex numbers); 0 if more than MAX_N."""
    d3 = abs(cubic[3] - 3 * cubic[2] + 3 * cubic[1] - cubic[0])
    for n in range(2, MAX_N + 1):
        if d3 <= tolerance * SPLINE_MAX_D3[n]:
            return n
    return 0

∞ Appendix B. Checking the claims

The scripts that produced the numbers and the figures are in github.com/behdad/cu2qu-paper, with their output and the notes kept along the way:

∞ References

  1. J. Godfrey-Kittle, B. Esfahbod, C. Lupo and others. cu2qu: cubic-to-quadratic Bézier curve conversion. 2015–2020; since part of fontTools.
  2. fontTools. fontTools.cu2qu, since version 4.7.0, 2020.
  3. R. Levien and others. kurbo: CubicBez::to_quads, CubicBez::approx_spline and cubics_to_quadratic_splines.
  4. B. Esfahbod. Add documentation of the algorithm. cu2qu issue 10, 2015.
  5. fontTools pull request 4452: [cu2qu] Compute the number of quadratics instead of trying. 2026.
  6. kurbo pull request 625: cu2qu port: fix a stack overflow at the limit, and compute the number of quadratics. 2026.
  7. HarfBuzz pull requests 6879, 6880, 6881 and 6882. 2026.
  8. A. Colomitchi. Approximating cubic Bezier curves by quadratic ones. caffeineowl.com, 2006; as archived in 2021.
  9. N. Truong, C. Yuksel and L. Seiler. Quadratic approximation of cubic curves. Proceedings of the ACM on Computer Graphics and Interactive Techniques 3(2), article 16 (High-Performance Graphics 2020).
  10. N. Silva and others. lyon_geom: CubicBezierSegment::num_quadratics.
  11. FontForge documentation. Bézier splines: converting PostScript to TrueType.
  12. A. Rodin and V. Puzrin. cubic2quad.
  13. M. A. Watkins and A. J. Worsey. Degree reduction of Bézier curves. Computer-Aided Design 20(7), 398–405, 1988.
  14. M. A. Lachance. Chebyshev economization for parametric surfaces. Computer Aided Geometric Design 5(3), 195–208, 1988.
  15. M. Eck. Degree reduction of Bézier curves. Computer Aided Geometric Design 10(3–4), 237–251, 1993.
  16. B. Biły. On a method of the rapid approximation of a cubic Bézier curve by quadratic Bézier curves. Zeszyty Naukowe Politechniki Śląskiej, Matematyka Stosowana 4, 57–71, 2014.