� �)�Uc@s�dZddlZddlmZddlZddlmZddlmZm Z m Z m Z m Z m Z mZmZddlmZmZddlmZdefd ��YZe Zd �Z dS( s2 Contains a class for managing paths (polylines). i����N(tWeakValueDictionary(tma(t point_in_pathtget_path_extentstpoint_in_path_collectiontget_path_collection_extentst path_in_pathtpath_intersects_pathtconvert_path_to_polygonst cleanup_path(tsimple_linear_interpolationtmaxdict(trcParamstPathcBs�eZdZdZdZdZdZdZdZddddddddddddddddgZ e j Z d"dd�Zed��Zed ��Zd �Zd �Zd"ed"ed d"ed �Zd�Zd"d�Zd"d�Zd"d�Zed�Zed�Zd�Zd"ddd�Zd"Zed��Z e!�Z"ed��Z#e!�Z$edd��Z%ed��Z&d"Z'ed��Z(d"Z)ed��Z*ed"ed��Z+ed"d��Z,e-d�Z.ed d!��Z/RS(#s~ :class:`Path` represents a series of possibly disconnected, possibly closed, line and curve segments. The underlying storage is made up of two parallel numpy arrays: - *vertices*: an Nx2 float array of vertices - *codes*: an N-length uint8 array of vertex types These two arrays always have the same length in the first dimension. For example, to represent a cubic curve, you must provide three vertices as well as three codes ``CURVE3``. The code types are: - ``STOP`` : 1 vertex (ignored) A marker for the end of the entire path (currently not required and ignored) - ``MOVETO`` : 1 vertex Pick up the pen and move to the given vertex. - ``LINETO`` : 1 vertex Draw a line from the current position to the given vertex. - ``CURVE3`` : 1 control point, 1 endpoint Draw a quadratic Bezier curve from the current position, with the given control point, to the given end point. - ``CURVE4`` : 2 control points, 1 endpoint Draw a cubic Bezier curve from the current position, with the given control points, to the given end point. - ``CLOSEPOLY`` : 1 vertex (ignored) Draw a line segment to the start point of the current polyline. Users of Path objects should not access the vertices and codes arrays directly. Instead, they should use :meth:`iter_segments` to get the vertex/code pairs. This is important, since many :class:`Path` objects, as an optimization, do not store a *codes* at all, but have a default one provided for them by :meth:`iter_segments`. Note also that the vertices and codes arrays should be treated as immutable -- there are a number of optimizations and assumptions made up front in the constructor that will not change when the data changes. iiiiiiOcCsztj|�r0|jtj�jtj�}ntj|tj�}|dk r�tj||j �}|j dks{t �t |�t |�ks�t �t |�r�|d|j ks�t �q�n|j dks�t �|jddks�t �tdo/t |�dko/|dkp/tj|tjk�|_td|_tj|�j� |_||_||_||_dS(s� Create a new path with the given vertices and codes. *vertices* is an Nx2 numpy float array, masked array or Python sequence. *codes* is an N-length numpy array or Python sequence of type :attr:`matplotlib.path.Path.code_type`. These two arrays must have the same length in the first dimension. If *codes* is None, *vertices* will be treated as a series of line segments. If *vertices* contains masked values, they will be converted to NaNs which are then handled correctly by the Agg PathIterator and other consumers of path data, such as :meth:`iter_segments`. *interpolation_steps* is used as a hint to certain projections, such as Polar, that this path should be linearly interpolated immediately before drawing. This attribute is primarily an implementation detail and is not intended for public use. iiis path.simplifyi�spath.simplify_thresholdN(Rt isMaskedArraytastypetnptfloat_tfilledtnantasarraytNonet code_typetndimtAssertionErrortlentMOVETOtshapeR tallR tLINETOtshould_simplifytsimplify_thresholdtisfinitet has_nonfinitetcodestverticest_interpolation_steps(tselfR#R"R$((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt__init__Ss&!   '   c Cs�|j\}}}|dks$t�|d}||}tj|df�}tj|t�|j}|j|dd|�<|j||d|�<x7t |�D])} |dd�| f|| d|�<q�W|||�S(s' (static method) Make a compound path object to draw a number of polygons with equal numbers of sides XY is a (numpolys x numsides x 2) numpy array of vertices. Return object is a :class:`Path` .. plot:: mpl_examples/api/histogram_path_demo.py iiiN( RRRtzerostonestintRRt CLOSEPOLYtrange( tclstXYtnumpolystnumsidesttwotstridetnvertstvertsR"ti((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytmake_compound_path_from_polys�s  'c Gs�x#|D]}|jdkst�qWg|D]}t|�^q-}t|�}tjg|D]}|j^q^�}|j|df�|j tj |�}d}x%|D]} |j ||<|| 7}q�W|||�S(s� (staticmethod) Make a compound path from a list of Path objects. Only polygons (not curves) are supported. iiN( R"RRRtsumRtvstackR#treshapeRR(R( R,targstptxtlengthst total_lengthR#R"R4tlength((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytmake_compound_path�s  %  cCsd|j|jfS(Ns Path(%s, %s)(R#R"(R%((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt__repr__�scCs t|j�S(N(RR#(R%((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt__len__�sg�?c cs�|j}t|�sdS|j} |j} |j} |j} |j} |j}t||||||||�\}} t|�}d}xj||kr�| |}||kr�dS| t |�d@}||||!j �}||fV||7}q�WdS(sl Iterates over all of the curve segments in the path. Each iteration returns a 2-tuple (*vertices*, *code*), where *vertices* is a sequence of 1 - 3 coordinate pairs, and *code* is one of the :class:`Path` codes. Additionally, this method can provide a number of standard cleanups and conversions to the path. *transform*: if not None, the given affine transformation will be applied to the path. *remove_nans*: if True, will remove all NaNs from the path and insert MOVETO commands to skip over them. *clip*: if not None, must be a four-tuple (x1, y1, x2, y2) defining a rectangle in which to clip the path. *snap*: if None, auto-snap to pixels, to reduce fuzziness of rectilinear lines. If True, force snapping, and if False, don't snap. *stroke_width*: the width of the stroke being drawn. Needed as a hint for the snapping algorithm. *simplify*: if True, perform simplification, to remove vertices that do not affect the appearance of the path. If False, perform no simplification. If None, use the should_simplify member variable. *curves*: If True, curve segments will be returned as curve segments. If False, all curves will be converted to line segments. Nii( R#RR"t NUM_VERTICESRRR*tSTOPR R)tflatten(R%t transformt remove_nanstcliptsnapt stroke_widthtsimplifytcurvesR#R"RBRRR*RCt len_verticesR4tcodet num_verticest curr_vertices((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt iter_segments�s*%            cCs"t|j|j�|j|j�S(s/ Return a transformed copy of the path. .. seealso:: :class:`matplotlib.transforms.TransformedPath` A specialized path class that will cache the transformed result and automatically update when the transform changes. (R RER#R"R$(R%RE((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt transformed�s cCs6|dk r|j�}nt|d|d||�S(s� Returns *True* if the path contains the given point. If *transform* is not *None*, the path will be transformed before performing the test. iiN(RtfrozenR(R%tpointRE((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytcontains_point s cCs.|dk r|j�}nt|d||�S(s� Returns *True* if this path completely contains the given path. If *transform* is not *None*, the path will be transformed before performing the test. N(RRRR(R%tpathRE((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt contains_paths cCseddlm}|}|dk rR|j�}|jsR|j|�}d}qRn|t||��S(s Returns the extents (*xmin*, *ymin*, *xmax*, *ymax*) of the path. Unlike computing the extents on the *vertices* alone, this algorithm will take into account the curves and deal with control points appropriately. i����(tBboxN(t transformsRWRRRt is_affineRQR(R%RERWRU((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt get_extents"s     cCst|||�S(s Returns *True* if this path intersects another given path. *filled*, when True, treats the paths as if they were filled. That is, if one path completely encloses the other, :meth:`intersects_path` will return True. (R(R%totherR((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytintersects_path4scCsAddlm}|j�j||��}|j||�}|S(s Returns *True* if this path intersects a given :class:`~matplotlib.transforms.Bbox`. *filled*, when True, treats the path as if it was filled. That is, if one path completely encloses the other, :meth:`intersects_path` will return True. i����(tBboxTransformTo(RXR]tunit_rectangleRQR\(R%tbboxRR]t rectangletresult((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytintersects_bbox>s  cCs�|dkr|St|j|�}|j}|dk rxtjtjt|�d|df�}||dd|�<nd}t||�S(s| Returns a new path resampled to length N x steps. Does not currently handle interpolating curves. iiN( R R#R"RR RRR(R(R%tstepsR#R"t new_codes((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt interpolatedMs   +cCs�t|j�dkrgS|dk r4|j�}n|jdkr�|dks[|dkr�|dkrq|jgS|j|j�gSnt||||�S(s� Convert this path to a list of polygons. Each polygon is an Nx2 array of vertices. In other words, each polygon has no ``MOVETO`` instructions or curves. This is useful for displaying in backends that do not support compound paths or Bezier curves, such as GDK. If *width* and *height* are both non-zero then the lines will be simplified so that vertices outside of (0, 0), (width, height) will be clipped. iN(RR#RRRR"RER(R%REtwidththeight((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt to_polygons^s  '  cCsv|jdkro|ddgddgddgddgddgg|j|j|j|j|jg�|_n|jS(sm (staticmethod) Returns a :class:`Path` of the unit rectangle from (0, 0) to (1, 1). gg�?N(t_unit_rectangleRRRR*(R,((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyR^{s3-cCs|dkr!|jj|�}nd}|dkrdtj|tj|d�j|ddf�}|tjd7}tjtj|�tj |�fd�}tj |df�}|j |d<|j |dd+|j |d<|||�}|dkr||j|<qn|S(s� (staticmethod) Returns a :class:`Path` for a unit regular polygon with the given *numVertices* and radius of 1.0, centered at (0, 0). iiig@ii����N(t_unit_regular_polygonstgetRRtpitarangeR8t concatenatetcostsintemptyRRR*(R,t numVerticesRUtthetaR3R"((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytunit_regular_polygon�s   '*   g�?c CsI|dkr'|jj||f�}nd}|dkrE|d}dtj|tj|d�}|tjd7}tj|d�}||ddd�<tj|tj|�|tj |�f�j �}tj |df�}|j |d<|j |dd+|j|d<|||�}|dkrE||j||f<qEn|S(s� (staticmethod) Returns a :class:`Path` for a unit regular star with the given numVertices and radius of 1.0, centered at (0, 0). iiig@Nii����(t_unit_regular_starsRkRRRlRmR(R7RoRpt transposeRqRRR*Rj( R,Rrt innerCircleRUtns2RstrR3R"((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytunit_regular_star�s$   "5   cCs|j|d�S(s� (staticmethod) Returns a :class:`Path` for a unit regular asterisk with the given numVertices and radius of 1.0, centered at (0, 0). g(Rz(R,Rr((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytunit_regular_asterisk�scCs�|jd kr�d}tjd�}tj||d�}tjddg|dg||| |g|| g||| |gd| gddgd|g||||g||g||||g|dgddg| dg| |||g| |g| |||gd|gddgd| g| || |g| | g| || |g| dgddgddggtj�}|jtjd�}|j|d<|j |d <|||�|_n|jS( s} (staticmethod) Returns a :class:`Path` of the unit circle. The circle is approximated using cubic Bezier curves. This uses 8 splines around the circle using the approach presented here: Lancaster, Don. `Approximating a Circle or an Ellipse Using Four Bezier Cubic Splines <http://www.tinaja.com/glib/ellipse4.pdf>`_. grSl��?g�?g@gg�g�?iii����N( t _unit_circleRRtsqrttarrayRtCURVE4R(RR*(R,tMAGICtSQRTHALFtMAGIC45R#R"((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt unit_circle�sJ                      cCs>|jd kr7d}tjd�}tj||d�}tjddg|dg||| |g|| g||| |gd| gddgd|g||||g||g||||g|dgddgddggtj�}|jtjd�}|j|d<|j |d <|||�|_n|jS( s� (staticmethod) Returns a :class:`Path` of the right half of a unit circle. The circle is approximated using cubic Bezier curves. This uses 4 splines around the circle using the approach presented here: Lancaster, Don. `Approximating a Circle or an Ellipse Using Four Bezier Cubic Splines <http://www.tinaja.com/glib/ellipse4.pdf>`_. grSl��?g�?g@gg�g�?iii����N( t_unit_circle_righthalfRRR}R~RRR(RR*(R,R�R�R�R#R"((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytunit_circle_righthalf s2              cCs�|tjd9}|tjd9}tjd}tjd}tjtj|�tj|��}tjtj|�tj|��}||tj|||�8}||tjkr�||tjkr�||7}n|dkrtdtj|||��}n|dkr!t d��n|||} tj d| �} tj| �tj dd| | �dd} tj |||dt �} tj| �} tj| �}| d }|d }| }|}| d}|d}| }|}|r�|d d }tj|dftj�}|jtj|f|j�}|d |d g|d<|j|jg|d d+|j|jg|d )d}|d}ny|d d}tj|dftj�}|jtj|f|j�}|d |d g|d <|j|d <d}|}|| ||||d �d f<|| ||||d �df<|| |||d|d �d f<|| |||d|d �df<|||d|d �d f<|||d|d �df<|||�S(s (staticmethod) Returns an arc on the unit circle from angle *theta1* to angle *theta2* (in degrees). If *n* is provided, it is the number of spline segments to make. If *n* is not provided, the number of spline segments is determined based on the delta between *theta1* and *theta2*. Masionobe, L. 2003. `Drawing an elliptical arc using polylines, quadratic or cubic Bezier curves <http://www.spaceroots.org/documents/ellipse/index.html>`_. g�f@g@g�?iisn must be >= 1 or Noneg@g@i����iiii����N(RRltarctan2RpRotfloorRR)tceilt ValueErrorttanR}tlinspacetTrueRqRRR(RRRR*(R,ttheta1ttheta2tntis_wedgettwopithalfpiteta1teta2tdetatttalphaRctcos_etatsin_etatxAtyAtxA_dottyA_dottxBtyBtxB_dottyB_dotR>R#R"t vertex_offsettend((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytarc;sd  $$&  $ 0      !!%%cCs|j|||t�S(sO (staticmethod) Returns a wedge of the unit circle from angle *theta1* to angle *theta2* (in degrees). If *n* is provided, it is the number of spline segments to make. If *n* is not provided, the number of spline segments is determined based on the delta between *theta1* and *theta2*. (R�R�(R,R�R�R�((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pytwedge�s iicCsnddlm}|dkr dS|jj||f�}|dk rH|S|||�}||j||f<|S(s� Given a hatch specifier, *hatchpattern*, generates a Path that can be used in a repeated hatching pattern. *density* is the number of lines per unit square. i����(tget_pathN(tmatplotlib.hatchR�Rt _hatch_dictRk(R,t hatchpatterntdensityR�t hatch_path((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pythatch�s  N(0t__name__t __module__t__doc__RCRRtCURVE3RR*RBRtuint8RRR&t classmethodR5R?R@RAR�tFalseRPRQRTRVRZR\RbReRhRiR^RRjRtRuRzR{R|R�R�R�R�R�R R�R�(((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyR s^0    2     >       =.M cGsHddlm}t|d�dkr5td��n|jt|��S(sp Given a sequence of :class:`Path` objects, returns the bounding box that encapsulates all of them. i����(RWiisNo paths provided(RXRWRR�t from_extentst_get_path_collection_extents(R9RW((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyR�s(R�tmathtweakrefRtnumpyRRtmatplotlib._pathRRRRRRRR tmatplotlib.cbookR R t matplotlibR tobjectR R�(((sB/opt/alt/python27/lib64/python2.7/site-packages/matplotlib/path.pyt<module>s  :���