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

Skip to content

Commit 9a9d70e

Browse files
committed
Support getting the vertices of curved paths.
svn path=/trunk/matplotlib/; revision=5570
1 parent 8b3c123 commit 9a9d70e

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

lib/matplotlib/patches.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,17 @@ def __init__(self,
8383
def get_verts(self):
8484
"""
8585
return a copy of the vertices used in this patch
86+
87+
If the patch contains Bezier curves, the curves will be
88+
interpolated by line segments. To access the curves as
89+
curves, use :meth:`get_path`.
8690
"""
8791
trans = self.get_transform()
8892
path = self.get_path()
89-
tverts = trans.transform(path.vertices)
90-
return tverts
93+
polygons = path.to_polygons(trans)
94+
if len(polygons):
95+
return polygons[0]
96+
return []
9197

9298
def contains(self, mouseevent):
9399
"""Test whether the mouse event occurred in the patch.

lib/matplotlib/path.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,21 @@ def to_polygons(self, transform=None, width=0, height=0):
290290
``MOVETO`` instructions or curves. This is useful for
291291
displaying in backends that do not support compound paths or
292292
Bezier curves, such as GDK.
293+
294+
If width and height are both non-zero then the lines will be
295+
simplified so that vertices outside of (0, 0), (width, height)
296+
will be clipped.
293297
"""
298+
if len(self.vertices) == 0:
299+
return []
300+
294301
if transform is not None:
295302
transform = transform.frozen()
296-
# Deal with the common and simple case
297-
if self.codes is None and len(self.vertices) < 100:
298-
if len(self.vertices):
303+
if self.codes is None:
299304
return [transform.transform(self.vertices)]
300-
return []
305+
else:
306+
if self.codes is None:
307+
return [self.vertices]
301308
# Deal with the case where there are curves and/or multiple
302309
# subpaths (using extension code)
303310
return convert_path_to_polygons(self, transform, width, height)

src/_path.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class _path_module : public Py::ExtensionModule<_path_module>
5252
add_varargs_method("path_intersects_path", &_path_module::path_intersects_path,
5353
"path_intersects_path(p1, p2)");
5454
add_varargs_method("convert_path_to_polygons", &_path_module::convert_path_to_polygons,
55-
"convert_path_to_polygons(path, trans)");
55+
"convert_path_to_polygons(path, trans, width, height)");
5656

5757
initialize("Helper functions for paths");
5858
}
@@ -1115,7 +1115,7 @@ Py::Object _path_module::convert_path_to_polygons(const Py::Tuple& args)
11151115
double width = Py::Float(args[2]);
11161116
double height = Py::Float(args[3]);
11171117

1118-
bool simplify = !path.has_curves();
1118+
bool simplify = !path.has_curves() && width != 0.0 && height != 0.0;
11191119

11201120
transformed_path_t tpath(path, trans);
11211121
simplify_t simplified(tpath, false, simplify, width, height);

0 commit comments

Comments
 (0)