From ef563cf9209d1e145fcf5f5037491952f7acf20f Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 25 Aug 2014 16:14:01 -0400 Subject: [PATCH 1/2] Fix path clipping --- .../test_path/path_clipping.svg | 1458 +++++++++++++++++ lib/matplotlib/tests/test_path.py | 24 + lib/matplotlib/tests/test_transforms.py | 1 - src/path_converters.h | 17 +- 4 files changed, 1492 insertions(+), 8 deletions(-) create mode 100644 lib/matplotlib/tests/baseline_images/test_path/path_clipping.svg diff --git a/lib/matplotlib/tests/baseline_images/test_path/path_clipping.svg b/lib/matplotlib/tests/baseline_images/test_path/path_clipping.svg new file mode 100644 index 000000000000..110e933f65f7 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_path/path_clipping.svg @@ -0,0 +1,1458 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index a1721da09325..fefb059d176d 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -6,7 +6,10 @@ import numpy as np from matplotlib.path import Path +from matplotlib.patches import Polygon from nose.tools import assert_raises +from matplotlib.testing.decorators import image_comparison +import matplotlib.pyplot as plt def test_readonly_path(): @@ -36,6 +39,27 @@ def test_contains_points_negative_radius(): assert np.all(path.contains_points(points, radius=-0.5) == expected) + +@image_comparison(baseline_images=['path_clipping'], + extensions=['svg'], remove_text=True) +def test_path_clipping(): + fig = plt.figure(figsize=(6.0, 6.2)) + + for i, xy in enumerate([ + [(200, 200), (200, 350), (400, 350), (400, 200)], + [(200, 200), (200, 350), (400, 350), (400, 100)], + [(200, 100), (200, 350), (400, 350), (400, 100)], + [(200, 100), (200, 415), (400, 350), (400, 100)], + [(200, 100), (200, 415), (400, 415), (400, 100)], + [(200, 415), (400, 415), (400, 100), (200, 100)], + [(400, 415), (400, 100), (200, 100), (200, 415)]]): + ax = fig.add_subplot(4, 2, i) + bbox = [0, 140, 640, 260] + ax.set_xlim(bbox[0], bbox[0] + bbox[2]) + ax.set_ylim(bbox[1], bbox[1] + bbox[3]) + ax.add_patch(Polygon(xy, facecolor='none', edgecolor='red', closed=True)) + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/lib/matplotlib/tests/test_transforms.py b/lib/matplotlib/tests/test_transforms.py index a096f77e5f1c..77d7eff5e015 100644 --- a/lib/matplotlib/tests/test_transforms.py +++ b/lib/matplotlib/tests/test_transforms.py @@ -207,7 +207,6 @@ def test_clipping_of_log(): # line segment is effectively removed. That means that the closepoly # operation must be replaced by a move to the first point. assert np.allclose(tcodes, [ M, M, L, L, L ]) - assert np.allclose(tpoints[-1], tpoints[0]) class NonAffineForTest(mtrans.Transform): diff --git a/src/path_converters.h b/src/path_converters.h index 8c606f4b65a5..1fa0d9f2f874 100644 --- a/src/path_converters.h +++ b/src/path_converters.h @@ -341,6 +341,16 @@ class PathClipper while ((code = m_source->vertex(x, y)) != agg::path_cmd_stop) { + if (code == (agg::path_cmd_end_poly | agg::path_flags_close)) { + if (m_has_init) { + *x = m_initX; + *y = m_initY; + code = agg::path_cmd_line_to; + } else { + continue; + } + } + if (code == agg::path_cmd_move_to) { m_initX = *x; @@ -384,13 +394,6 @@ class PathClipper return code; } } - else if (code == (agg::path_cmd_end_poly | agg::path_flags_close) - && m_broke_path && m_has_init) - { - *x = m_initX; - *y = m_initY; - return agg::path_cmd_line_to; - } else { break; From 81f5d569c558e0203f8e318dc4e66b268d8c35b9 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 26 Aug 2014 11:05:24 -0400 Subject: [PATCH 2/2] PEP8 --- lib/matplotlib/tests/test_path.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index fefb059d176d..8250e37b9f88 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -57,7 +57,8 @@ def test_path_clipping(): bbox = [0, 140, 640, 260] ax.set_xlim(bbox[0], bbox[0] + bbox[2]) ax.set_ylim(bbox[1], bbox[1] + bbox[3]) - ax.add_patch(Polygon(xy, facecolor='none', edgecolor='red', closed=True)) + ax.add_patch(Polygon( + xy, facecolor='none', edgecolor='red', closed=True)) if __name__ == '__main__':