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

Skip to content

Commit cf2e7c6

Browse files
committed
Document a bit the cairo fast path.
1 parent 001d435 commit cf2e7c6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,31 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
122122

123123

124124
def _convert_paths_fast(ctx, paths, transforms, clip=None):
125+
# We directly convert to the internal representation used by cairo, for
126+
# which ABI compatibility is guaranteed. The layout is for each item is
127+
# --CODE(4)-- -LENGTH(4)- ---------PAD(8)---------
128+
# ----------X(8)---------- ----------Y(8)----------
129+
# with the size in bytes in parentheses, and (X, Y) repeated as many times
130+
# as there are points for the current code.
125131
ffi = cairo.ffi
126132
cleaneds = [path.cleaned(transform=transform, clip=clip)
127133
for path, transform in zip(paths, transforms)]
128134
vertices = np.concatenate([cleaned.vertices for cleaned in cleaneds])
129135
codes = np.concatenate([cleaned.codes for cleaned in cleaneds])
130136

131-
# TODO: Implement Bezier degree elevation formula. Note that the "slow"
132-
# implementation is, in fact, also incorrect...
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...
133140
if np.any(codes == Path.CURVE3):
134141
raise NotImplementedError("Quadratic Bezier curves are not supported")
142+
135143
# Remove unused vertices and convert to cairo codes. Note that unlike
136144
# cairo_close_path, we do not explicitly insert an extraneous MOVE_TO after
137145
# CLOSE_PATH, so our resulting buffer may be smaller.
138146
vertices = vertices[(codes != Path.STOP) & (codes != Path.CLOSEPOLY)]
139147
codes = codes[codes != Path.STOP]
140148
codes = _MPL_TO_CAIRO_PATH_TYPE[codes]
149+
141150
# Where are the headers of each cairo portions?
142151
cairo_type_sizes = _CAIRO_PATH_TYPE_SIZES[codes]
143152
cairo_type_positions = np.insert(np.cumsum(cairo_type_sizes), 0, 0)
@@ -300,6 +309,7 @@ def _draw_paths():
300309
return
301310
gc_vars, rgb_fc = reuse_key
302311
gc = copy.copy(gc0)
312+
# We actually need to call the setters to reset the internal state.
303313
vars(gc).update(gc_vars)
304314
for k, v in gc_vars.items():
305315
try:

0 commit comments

Comments
 (0)