8000 Don't disable path clipping on paths with codes. by QuLogic · Pull Request #20363 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Don't disable path clipping on paths with codes. #20363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_patheffects.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def test_collection():
'edgecolor': 'blue'})


@image_comparison(['tickedstroke'], remove_text=True, extensions=['png'])
@image_comparison(['tickedstroke'], remove_text=True, extensions=['png'],
tol=0.22) # Increased tolerance due to fixed clipping.
def test_tickedstroke():
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12, 4))
path = Path.unit_circle()
Expand Down
23 changes: 23 additions & 0 deletions lib/matplotlib/tests/test_simplification.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,29 @@ def test_diamond():
ax.set_ylim(-0.6, 0.6)


def test_clipping_out_of_bounds():
# Should work on a Path *without* codes.
path = Path([(0, 0), (1, 2), (2, 1)])
simplified = path.cleaned(clip=(10, 10, 20, 20))
assert_array_equal(simplified.vertices, [(0, 0)])
assert simplified.codes == [Path.STOP]

# Should work on a Path *with* codes, and no curves.
path = Path([(0, 0), (1, 2), (2, 1)],
[Path.MOVETO, Path.LINETO, Path.LINETO])
simplified = path.cleaned(clip=(10, 10, 20, 20))
assert_array_equal(simplified.vertices, [(0, 0)])
assert simplified.codes == [Path.STOP]

# A Path with curves does not do any clipping yet.
path = Path([(0, 0), (1, 2), (2, 3)],
[Path.MOVETO, Path.CURVE3, Path.CURVE3])
simplified = path.cleaned()
simplified_clipped = path.cleaned(clip=(10, 10, 20, 20))
assert_array_equal(simplified.vertices, simplified_clipped.vertices)
assert_array_equal(simplified.codes, simplified_clipped.codes)


def test_noise():
np.random.seed(0)
x = np.random.uniform(size=50000) * 50
Expand Down
4 changes: 2 additions & 2 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ RendererAgg::draw_path(GCAgg &gc, PathIterator &path, agg::trans_affine &trans,

trans *= agg::trans_affine_scaling(1.0, -1.0);
trans *= agg::trans_affine_translation(0.0, (double)height);
bool clip = !face.first && !gc.has_hatchpath() && !path.has_curves();
bool clip = !face.first && !gc.has_hatchpath();
bool simplify = path.should_simplify() && clip;
double snapping_linewidth = points_to_pixels(gc.linewidth);
if (gc.color.a == 0.0) {
Expand Down Expand Up @@ -992,7 +992,7 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
}
}

bool do_clip = !face.first && !gc.has_hatchpath() && !has_curves;
bool do_clip = !face.first && !gc.has_hatchpath();

if (check_snap) {
gc.isaa = antialiaseds(i % Naa);
Expand Down
6 changes: 3 additions & 3 deletions src/_path.h< C311 /a>
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ void convert_path_to_polygons(PathIterator &path,

transformed_path_t tpath(path, trans);
nan_removal_t nan_removed(tpath, true, path.has_curves());
clipped_t clipped(nan_removed, do_clip && !path.has_curves(), width, height);
clipped_t clipped(nan_removed, do_clip, width, height);
simplify_t simplified(clipped, simplify, path.simplify_threshold());
curve_t curve(simplified);

Expand Down Expand Up @@ -1050,7 +1050,7 @@ void cleanup_path(PathIterator &path,

transformed_path_t tpath(path, trans);
nan_removal_t nan_removed(tpath, remove_nans, path.has_curves());
clipped_t clipped(nan_removed, do_clip && !path.has_curves(), rect);
clipped_t clipped(nan_removed, do_clip, rect);
snapped_t snapped(clipped, snap_mode, path.total_vertices(), stroke_width);
simplify_t simplified(snapped, do_simplify, path.simplify_threshold());

Expand Down Expand Up @@ -1209,7 +1209,7 @@ bool convert_to_string(PathIterator &path,

transformed_path_t tpath(path, trans);
nan_removal_t nan_removed(tpath, true, path.has_curves());
clipped_t clipped(nan_removed, do_clip && !path.has_curves(), clip_rect);
clipped_t clipped(nan_removed, do_clip, clip_rect);
simplify_t simplified(clipped, simplify, path.simplify_threshold());

buffersize = path.total_vertices() * (precision + 5) * 4;
Expand Down
0