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

Skip to content

Commit c924688

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 436e99e commit c924688

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
@@ -82,12 +82,8 @@ def _convert_path(ctx, path, transform, clip=None):
8282

8383

8484
def _convert_paths(ctx, paths, transforms, clip=None):
85-
if HAS_CAIRO_CFFI:
86-
try:
87-
return _convert_paths_fast(ctx, paths, transforms, clip)
88-
except NotImplementedError:
89-
pass
90-
return _convert_paths_slow(ctx, paths, transforms, clip)
85+
return (_convert_paths_fast if HAS_CAIRO_CFFI else _convert_paths_slow)(
86+
ctx, paths, transforms, clip)
9187

9288

9389
def _convert_paths_slow(ctx, paths, transforms, clip=None):
@@ -100,9 +96,10 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
10096
elif code == Path.LINETO:
10197
ctx.line_to(*points)
10298
elif code == Path.CURVE3:
103-
ctx.curve_to(points[0], points[1],
104-
points[0], points[1],
105-
points[2], points[3])
99+
cur = ctx.get_current_point()
100+
ctx.curve_to(
101+
*np.concatenate([cur / 3 + points[:2] * 2 / 3,
102+
points[:2] * 2 / 3 + points[-2:] / 3]))
106103
elif code == Path.CURVE4:
107104
ctx.curve_to(*points)
108105

@@ -115,17 +112,15 @@ def _convert_paths_fast(ctx, paths, transforms, clip=None):
115112
# with the size in bytes in parentheses, and (X, Y) repeated as many times
116113
# as there are points for the current code.
117114
ffi = cairo.ffi
118-
cleaneds = [path.cleaned(transform=transform, clip=clip)
115+
116+
# Convert curves to segment, so that 1. we don't have to handle
117+
# variable-sized CURVE-n codes, and 2. we don't have to implement degree
118+
# elevation for quadratic Beziers.
119+
cleaneds = [path.cleaned(transform=transform, clip=clip, curves=False)
119120
for path, transform in zip(paths, transforms)]
120121
vertices = np.concatenate([cleaned.vertices for cleaned in cleaneds])
121122
codes = np.concatenate([cleaned.codes for cleaned in cleaneds])
122123

123-
# TODO: Implement Bezier degree elevation formula. For now, fall back to
124-
# the "slow" implementation, though note that that implementation is, in
125-
# fact, also incorrect...
126-
if np.any(codes == Path.CURVE3):
127-
raise NotImplementedError("Quadratic Bezier curves are not supported")
128-
129124
# Remove unused vertices and convert to cairo codes. Note that unlike
130125
# cairo_close_path, we do not explicitly insert an extraneous MOVE_TO after
131126
# CLOSE_PATH, so our resulting buffer may be smaller.

0 commit comments

Comments
 (0)