11"""
22Contains a class for managing paths (polylines).
3-
4- October 2007 Michael Droettboom
53"""
64
75import math
@@ -21,42 +19,42 @@ class Path(object):
2119 closed, line and curve segments.
2220
2321 The underlying storage is made up of two parallel numpy arrays:
24- vertices: an Nx2 float array of vertices
25- codes: an N-length uint8 array of vertex types
22+ - vertices: an Nx2 float array of vertices
23+ - codes: an N-length uint8 array of vertex types
2624
2725 These two arrays always have the same length in the first
28- dimension. Therefore , to represent a cubic curve, you must
26+ dimension. For example , to represent a cubic curve, you must
2927 provide three vertices as well as three codes "CURVE3".
3028
3129 The code types are:
3230
33- STOP : 1 vertex (ignored)
34- A marker for the end of the entire path (currently not
35- required and ignored)
31+ - `` STOP`` : 1 vertex (ignored)
32+ A marker for the end of the entire path (currently not
33+ required and ignored)
3634
37- MOVETO : 1 vertex
38- Pick up the pen and move to the given vertex.
35+ - `` MOVETO`` : 1 vertex
36+ Pick up the pen and move to the given vertex.
3937
40- LINETO : 1 vertex
41- Draw a line from the current position to the given vertex.
38+ - `` LINETO`` : 1 vertex
39+ Draw a line from the current position to the given vertex.
4240
43- CURVE3 : 1 control point, 1 endpoint
41+ - `` CURVE3`` : 1 control point, 1 endpoint
4442 Draw a quadratic Bezier curve from the current position,
4543 with the given control point, to the given end point.
4644
47- CURVE4 : 2 control points, 1 endpoint
45+ - `` CURVE4`` : 2 control points, 1 endpoint
4846 Draw a cubic Bezier curve from the current position, with
4947 the given control points, to the given end point.
5048
51- CLOSEPOLY : 1 vertex (ignored)
49+ - `` CLOSEPOLY`` : 1 vertex (ignored)
5250 Draw a line segment to the start point of the current
5351 polyline.
5452
5553 Users of Path objects should not access the vertices and codes
56- arrays directly. Instead, they should use iter_segments to get
57- the vertex/code pairs. This is important since many Paths do not
58- store a codes array at all, but have a default one provided for
59- them by iter_segments.
54+ arrays directly. Instead, they should use :meth:` iter_segments`
55+ to get the vertex/code pairs. This is important since many Paths,
56+ as an optimization, do not store a codes array at all, but have a
57+ default one provided for them by :meth:` iter_segments` .
6058 """
6159
6260 # Path codes
@@ -81,9 +79,6 @@ def __init__(self, vertices, codes=None):
8179 codes is an N-length numpy array or Python sequence of type
8280 Path.code_type.
8381
84- See the docstring of Path for a description of the various
85- codes.
86-
8782 These two arrays must have the same length in the first
8883 dimension.
8984
@@ -133,8 +128,8 @@ def __init__(self, vertices, codes=None):
133128 #@staticmethod
134129 def make_compound_path (* args ):
135130 """
136- Make a compound path from a list of Path objects. Only
137- polygons (not curves) are supported.
131+ (staticmethod) Make a compound path from a list of Path
132+ objects. Only polygons (not curves) are supported.
138133 """
139134 for p in args :
140135 assert p .codes is None
@@ -162,7 +157,10 @@ def __len__(self):
162157
163158 def iter_segments (self ):
164159 """
165- Iterates over all of the curve segments in the path.
160+ Iterates over all of the curve segments in the path. Each
161+ iteration returns a 2-tuple ``(vertices, code)``, where
162+ vertices is a sequence of 1 - 3 coordinate pairs, and code is
163+ one of the ``Path`` codes.
166164 """
167165 vertices = self .vertices
168166 if not len (vertices ):
@@ -213,9 +211,9 @@ def transformed(self, transform):
213211 """
214212 Return a transformed copy of the path.
215213
216- See transforms.TransformedPath for a path that will cache the
217- transformed result and automatically update when the transform
218- changes.
214+ See :class:`matplotlib. transforms.TransformedPath` for a path
215+ that will cache the transformed result and automatically
216+ update when the transform changes.
219217 """
220218 return Path (transform .transform (self .vertices ), self .codes )
221219
@@ -233,6 +231,9 @@ def contains_point(self, point, transform=None):
233231 def contains_path (self , path , transform = None ):
234232 """
235233 Returns True if this path completely contains the given path.
234+
235+ If transform is not None, the path will be transformed before
236+ performing the test.
236237 """
237238 if transform is not None :
238239 transform = transform .frozen ()
@@ -259,7 +260,8 @@ def intersects_path(self, other):
259260
260261 def intersects_bbox (self , bbox ):
261262 """
262- Returns True if this path intersects a given Bbox.
263+ Returns True if this path intersects a given
264+ :class:`~matplotlib.transforms.Bbox`.
263265 """
264266 from transforms import BboxTransformTo
265267 rectangle = self .unit_rectangle ().transformed (
@@ -285,7 +287,9 @@ def to_polygons(self, transform=None, width=0, height=0):
285287 """
286288 Convert this path to a list of polygons. Each polygon is an
287289 Nx2 array of vertices. In other words, each polygon has no
288- "move to" instructions or curves.
290+ ``MOVETO`` instructions or curves. This is useful for
291+ displaying in backends that do not support compound paths or
292+ Bezier curves, such as GDK.
289293 """
290294 if transform is not None :
291295 transform = transform .frozen ()
@@ -302,7 +306,8 @@ def to_polygons(self, transform=None, width=0, height=0):
302306 #@classmethod
303307 def unit_rectangle (cls ):
304308 """
305- Returns a Path of the unit rectangle from (0, 0) to (1, 1).
309+ (staticmethod) Returns a :class:`Path` of the unit rectangle
310+ from (0, 0) to (1, 1).
306311 """
307312 if cls ._unit_rectangle is None :
308313 cls ._unit_rectangle = \
@@ -314,8 +319,9 @@ def unit_rectangle(cls):
314319 #@classmethod
315320 def unit_regular_polygon (cls , numVertices ):
316321 """
317- Returns a Path for a unit regular polygon with the given
318- numVertices and radius of 1.0, centered at (0, 0).
322+ (staticmethod) Returns a :class:`Path` for a unit regular
323+ polygon with the given numVertices and radius of 1.0, centered
324+ at (0, 0).
319325 """
320326 if numVertices <= 16 :
321327 path = cls ._unit_regular_polygons .get (numVertices )
@@ -337,8 +343,9 @@ def unit_regular_polygon(cls, numVertices):
337343 #@classmethod
338344 def unit_regular_star (cls , numVertices , innerCircle = 0.5 ):
339345 """
340- Returns a Path for a unit regular star with the given
341- numVertices and radius of 1.0, centered at (0, 0).
346+ (staticmethod) Returns a :class:`Path` for a unit regular star
347+ with the given numVertices and radius of 1.0, centered at (0,
348+ 0).
342349 """
343350 if numVertices <= 16 :
344351 path = cls ._unit_regular_stars .get ((numVertices , innerCircle ))
@@ -361,8 +368,9 @@ def unit_regular_star(cls, numVertices, innerCircle=0.5):
361368 #@classmethod
362369 def unit_regular_asterisk (cls , numVertices ):
363370 """
364- Returns a Path for a unit regular asterisk with the given
365- numVertices and radius of 1.0, centered at (0, 0).
371+ (staticmethod) Returns a :class:`Path` for a unit regular
372+ asterisk with the given numVertices and radius of 1.0,
373+ centered at (0, 0).
366374 """
367375 return cls .unit_regular_star (numVertices , 0.0 )
368376 unit_regular_asterisk = classmethod (unit_regular_asterisk )
@@ -371,14 +379,13 @@ def unit_regular_asterisk(cls, numVertices):
371379 #@classmethod
372380 def unit_circle (cls ):
373381 """
374- Returns a Path of the unit circle. The circle is approximated
375- using cubic Bezier curves. This uses 8 splines around the
376- circle using the approach presented here:
382+ (staticmethod) Returns a :class:`Path` of the unit circle.
383+ The circle is approximated using cubic Bezier curves. This
384+ uses 8 splines around the circle using the approach presented
385+ here:
377386
378- Lancaster, Don. Approximating a Circle or an Ellipse Using Four
379- Bezier Cubic Splines.
380-
381- http://www.tinaja.com/glib/ellipse4.pdf
387+ Lancaster, Don. `Approximating a Circle or an Ellipse Using Four
388+ Bezier Cubic Splines <http://www.tinaja.com/glib/ellipse4.pdf>`_.
382389 """
383390 if cls ._unit_circle is None :
384391 MAGIC = 0.2652031
@@ -434,18 +441,17 @@ def unit_circle(cls):
434441 #@classmethod
435442 def arc (cls , theta1 , theta2 , n = None , is_wedge = False ):
436443 """
437- Returns an arc on the unit circle from angle theta1 to angle
438- theta2 (in degrees).
444+ (staticmethod) Returns an arc on the unit circle from angle
445+ theta1 to angle theta2 (in degrees).
439446
440447 If n is provided, it is the number of spline segments to make.
441- If n is not provided, the number of spline segments is determined
442- based on the delta between theta1 and theta2.
443- """
444- # From Masionobe, L. 2003. "Drawing an elliptical arc using
445- # polylines, quadratic or cubic Bezier curves".
446- #
447- # http://www.spaceroots.org/documents/ellipse/index.html
448+ If n is not provided, the number of spline segments is
449+ determined based on the delta between theta1 and theta2.
448450
451+ Masionobe, L. 2003. `Drawing an elliptical arc using
452+ polylines, quadratic or cubic Bezier curves
453+ <http://www.spaceroots.org/documents/ellipse/index.html>`_.
454+ """
449455 # degrees to radians
450456 theta1 *= np .pi / 180.0
451457 theta2 *= np .pi / 180.0
@@ -514,14 +520,18 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False):
514520 #@classmethod
515521 def wedge (cls , theta1 , theta2 , n = None ):
516522 """
517- Returns a wedge of the unit circle from angle theta1 to angle
518- theta2 (in degrees).
523+ (staticmethod) Returns a wedge of the unit circle from angle
524+ theta1 to angle theta2 (in degrees).
519525 """
520526 return cls .arc (theta1 , theta2 , n , True )
521527 wedge = classmethod (wedge )
522528
523529_get_path_collection_extents = get_path_collection_extents
524530def get_path_collection_extents (* args ):
531+ """
532+ Given a sequence of :class:`Path` objects, returns the bounding
533+ box that encapsulates all of them.
534+ """
525535 from transforms import Bbox
526536 if len (args [1 ]) == 0 :
527537 raise ValueError ("No paths provided" )
0 commit comments