Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 241a306

Browse files
committed
Actually support quadratic Beziers.
For the slow code path, implement the degree elevation formula. For the fast code path, the path cleaner was already handling this for us, converting everything to lines.
1 parent cf2e7c6 commit 241a306

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,8 @@ def _convert_path(ctx, path, transform, clip=None):
9696

9797

9898
def _convert_paths(ctx, paths, transforms, clip=None):
99-
if HAS_CAIRO_CFFI:
100-
try:
101-
return _convert_paths_fast(ctx, paths, transforms, clip)
102-
except NotImplementedError:
103-
pass
104-
return _convert_paths_slow(ctx, paths, transforms, clip)
99+
return (_convert_paths_fast if HAS_CAIRO_CFFI else _convert_paths_slow)(
100+
ctx, paths, transforms, clip)
105101

106102

107103
def _convert_paths_slow(ctx, paths, transforms, clip=None):
@@ -114,9 +110,10 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
114110
elif code == Path.LINETO:
115111
ctx.line_to(*points)
116112
elif code == Path.CURVE3:
117-
ctx.curve_to(points[0], points[1],
118-
points[0], points[1],
119-
points[2], points[3])
113+
cur = ctx.get_current_point()
114+
ctx.curve_to(
115+
*np.concatenate([cur / 3 + points[:2] * 2 / 3,
116+
points[:2] * 2 / 3 + points[-2:] / 3]))
120117
elif code == Path.CURVE4:
121118
ctx.curve_to(*points)
122119

@@ -129,17 +126,15 @@ def _convert_paths_fast(ctx, paths, transforms, clip=None):
129126
# with the size in bytes in parentheses, and (X, Y) repeated as many times
130127
# as there are points for the current code.
131128
ffi = cairo.ffi
132-
cleaneds = [path.cleaned(transform=transform, clip=clip)
129+
130+
# Convert curves to segment, so that 1. we don't have to handle
131+
# variable-sized CURVE-n codes, and 2. we don't have to implement degree
132+
# elevation for quadratic Beziers.
133+
cleaneds = [path.cleaned(transform=transform, clip=clip, curves=False)
133134
for path, transform in zip(paths, transforms)]
134135
vertices = np.concatenate([cleaned.vertices for cleaned in cleaneds])
135136
codes = np.concatenate([cleaned.codes for cleaned in cleaneds])
136137

137-
# TODO: Implement Bezier degree elevation formula. For now, fall back to
138-
# the "slow" implementation, though note that that implementation is, in
139-
# fact, also incorrect...
140-
if np.any(codes == Path.CURVE3):
141-
raise NotImplementedError("Quadratic Bezier curves are not supported")
142-
143138
# Remove unused vertices and convert to cairo codes. Note that unlike
144139
# cairo_close_path, we do not explicitly insert an extraneous MOVE_TO after
145140
# CLOSE_PATH, so our resulting buffer may be smaller.

0 commit comments

Comments
 (0)