From: <md...@us...> - 2009-02-05 16:01:02
|
Revision: 6882 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6882&view=rev Author: mdboom Date: 2009-02-05 16:00:51 +0000 (Thu, 05 Feb 2009) Log Message: ----------- Speed up nan-handling on curves. Add test case for this. Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py trunk/matplotlib/src/path_converters.h Modified: trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py 2009-02-05 15:35:24 UTC (rev 6881) +++ trunk/matplotlib/examples/pylab_examples/simplification_clipping_test.py 2009-02-05 16:00:51 UTC (rev 6882) @@ -1,5 +1,8 @@ from pylab import * import numpy as np +from matplotlib import patches, path +nan = np.nan +Path = path.Path t = arange(0.0, 2.0, 0.01) s = sin(2*pi*t) @@ -55,4 +58,15 @@ title("Original length: %d, simplified length: %d" % (len(path.vertices), len(simplified))) +figure() +pp1 = patches.PathPatch( + Path([(0, 0), (1, 0), (1, 1), (nan, 1), (0, 0), (2, 0), (2, 2), (0, 0)], + [Path.MOVETO, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CURVE3, Path.CLOSEPOLY]), + fc="none") + +gca().add_patch(pp1) +gca().set_xlim((0, 2)) +gca().set_ylim((0, 2)) +title("Should be one line with two curves below it") + show() Modified: trunk/matplotlib/src/path_converters.h =================================================================== --- trunk/matplotlib/src/path_converters.h 2009-02-05 15:35:24 UTC (rev 6881) +++ trunk/matplotlib/src/path_converters.h 2009-02-05 16:00:51 UTC (rev 6882) @@ -149,7 +149,7 @@ return code; } - bool skipped = false; + bool needs_move_to = false; while (true) { code = m_source->vertex(x, y); if (code == agg::path_cmd_stop || @@ -158,38 +158,38 @@ return code; } + if (needs_move_to) { + queue_push(agg::path_cmd_move_to, *x, *y); + } + size_t num_extra_points = num_extra_points_map[code & 0xF]; bool has_nan = (MPL_notisfinite64(*x) || MPL_notisfinite64(*y)); - double xc[2], yc[2]; + queue_push(code, *x, *y); /* Note: this test can not be short-circuited, since we need to advance through the entire curve no matter what */ for (size_t i = 0; i < num_extra_points; ++i) { - m_source->vertex(&xc[i], &yc[i]); - has_nan |= (MPL_notisfinite64(xc[i]) || MPL_notisfinite64(yc[i])); + m_source->vertex(x, y); + has_nan |= (MPL_notisfinite64(*x) || MPL_notisfinite64(*y)); + queue_push(code, *x, *y); } - if (has_nan) + if (!has_nan) { - skipped = true; + break; } - else - { - if (skipped) - { - queue_push(agg::path_cmd_move_to, *x, *y); - } - if (!skipped || code != agg::path_cmd_line_to) { - queue_push(code, *x, *y); - for (size_t i = 0; i < num_extra_points; ++i) - { - queue_push(code, xc[i], yc[i]); - } - } + queue_clear(); - break; + if (!(MPL_notisfinite64(*x) || MPL_notisfinite64(*y))) + { + queue_push(agg::path_cmd_move_to, *x, *y); + needs_move_to = false; } + else + { + needs_move_to = true; + } } if (queue_flush(&code, x, y)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |