incorrect rendering of quadratic bezier path in ps and pdf backend


It seems that the pdf and ps backends draw the quadratic bezier line
Here is a little test script.

# -- begin test script --
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.path import Path
from matplotlib.patches import PathPatch

ax = plt.gca()
pp1 = PathPatch(Path([(0, 0), (1, 0), (1, 1), (0, 0)], [1, 3, 3, 5]), fc="none",

ax.plot([0.75], [0.25], "ro")

plt.savefig("test_quad_bezier_%s" % (matplotlib.get_backend()))

# -- end --

I'm attaching the result for the pdf backend. The lower-right
(quadratic bezier) path is supposed to path through the red dot.
The agg backends are fine, and so is the svg backend. I haven't tested
with others.
I tracked down this to an incorrect conversion of quadratic bezier
curve to cubic one.
Given (q0, q1, q2) as control points of quadratic one, these backends
simply produce a cubic one with (q0, q1, q1, q2) as its control
points, which is not correct (see for example).

I'm attaching a patch (for pdf and ps backends) which I believe
correctly handle this.
I hope this patch is reviewed and applied. Note that the function
_quad2cubic is duplicated in both backends. This function might be
moved to some common place.



test_quad_bezier_pdf.pdf (9.92 KB)

bezier_pdf_ps.diff (3.66 KB)