
     hF                      d Z ddlmZ ddlZ	 ddlmZ ddlm	Z	 ddl
mZ ddlZddlmZ ddlmZ dd	lmZmZmZmZmZmZmZmZmZmZmZ dd
lmZmZ m!Z"m#Z# 	 ddl$m%Z% dZ&ddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2m3Z3m4Z4m5Z5 	 e6Z7 e9d      Z: e9d      Z; ejx                  d      Z= ejx                  d      Z>dZ?dZ@dZAdZBdZCdZDdZEdZF eGd      ZHdZId ZJd ZKd ZLd ZMd ZNd  ZOd! ZPd" ZQd# ZRd>d$ZSd?d%ZTd& ZUd@d'ZVd( ZWdAd)ZXd* ZYd+ ZZd>d,Z[d>d-Z\d. Z]d/ Z^d0 Z_e@e?dfd1Z`eDeEeCeBfd2Zad3 Zb G d4 d5ec      Zd G d6 d7ec      Ze G d8 d9ec      Zf G d: d;ec      Zg G d< d=e      Zhy# e$ r
 ddlmZ Y `w xY w#  dZ&Y  xY w# e8$ r Y w xY w)BzThis submodule contains the class definitions of the the main five classes
svgpathtools is built around: Path, Line, QuadraticBezier, CubicBezier, and
Arc.    )annotationsN)MutableSequence)warn)
itemgetter)tee)reduce)sqrtcossintanarccosarcsindegreesradianslogpiceil)expr	   angleisnan)quadTF   )bezier_intersectionsbezier_bounding_boxsplit_bezierbezier_by_line_intersectionspolynomial2bezierbezier2polynomial)BugException)rational_limit	polyrootspolyroots01imagrealMmZzLlHhVvCcSsQqTtAa
MZLHVCSQTAz([MmZzLlHhVvCcSsQqTtAa])z([-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?   -q=i'  z9This method has not yet been implemented for Arc objects.a  The name of this method is somewhat misleading (yet kept for compatibility with scripts created using svg.path 2.0).  This method is meant only for d-string creation and should NOT be used to check for kinks.  To check a segment for differentiability, use the joins_smoothly_with() method instead or the kinks() function (in smoothing.py).
To turn off this warning, set warning_on=False.c                     t        |       dk(  r| \  }}t        ||      S t        |       dk(  r| \  }}}}t        ||||      S t        |       dk(  r| \  }}}t        |||      S t        |       dv sJ y )N         )r*   r,   r+   )lenLineCubicBezierQuadraticBezier)bpointsstartendcontrol1control2controls         m/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/svgpathtools/path.pybezier_segmentr8   R   s    
7|q
sE3	W	)0&x35(Hc::	W	%wugs337|y(((    c                j    t        | t              xs" t        | t              xs t        | t              S N)
isinstancer.   r0   r/   segs    r7   is_bezier_segmentr?   `   s/    sD! )sO,)sK(*r9   c                <    t        |       xs t        | t              S r;   )r?   r<   Arcr=   s    r7   is_path_segmentrB   f   s    S!9ZS%99r9   c                X    t        | t              xr t        t        t        |             S )zXChecks that all segments in path are a Line, QuadraticBezier, or
    CubicBezier object.)r<   Pathallmapr?   )paths    r7   is_bezier_pathrH   j   s#     dD!Gc#.?*F&GGr9   c                L    t        | D cg c]  }|D ]  }|  c}} S c c}}w )zTakes in a sequence of paths and returns their concatenations into a
    single path (following the order of the input sequence).)rD   )list_of_pathsrG   r>   s      r7   concatpathsrK   p   s)     -@$4@C#@#@AA@s    
c                   t        | d|z  z   |d|z  z         }t        | d|z  z   |d|z  z         }t        |d|z  z   |d|z  z         }t        | d|z  z   | d|z  z         }t        |||j                         |j                               S )z1Converts a bounding box 4-tuple to a Path object.              ?)r.   rD   reversed)xminxmaxyminymaxbtrls           r7   	bbox2pathrW   v   s    TBtG^TBtG^,ATBtG^TBtG^,ATBtG^TBtG^,ATBtG^TBtG^,A1ajjlAJJL11r9   c                     t        t        t        |       dz
        D cg c]  }t        | |   | |dz             c} S c c}w )zConverts a list of points to a Path composed of lines connecting those 
    points (i.e. a linear spline or polyline).  See also `polygon()`.r   rD   ranger-   r.   pointsis     r7   polyliner^      sL      Vq13 vay&1+. 3 4 4 3s   ?c                     t        t        t        |             D cg c]#  }t        | |   | |dz   t        |       z           % c} S c c}w )zConverts a list of points to a Path composed of lines connecting those 
    points, then closes the path by connecting the last point to the first.  
    See also `polyline()`.r   rY   r[   s     r7   polygonr`      sR      V-/ vay&!a%3v;)>"?@ / 0 0 /s   (Ac                    t        |       dz
  }|dk(  rt        |  S |dk(  rt        |  S |dk(  rt        |  S t        |       dv sJ y)zConverts a list of length 2, 3, or 4 to a CubicBezier, QuadraticBezier,
    or Line object, respectively.
    See also: poly2bez.r   r,   r*   >   r*   r,   r+   N)r-   r/   r0   r.   )r1   orders     r7   bpoints2bezierrc      sY     L1EzG$$	!((	!W~7|y(((r9   c                6    t        |       }|r|S t        |      S )a  Converts a cubic or lower order Polynomial object (or a sequence of
    coefficients) to a CubicBezier, QuadraticBezier, or Line object as
    appropriate.  If return_bpoints=True then this will instead only return
    the control points of the corresponding Bezier curve.
    Note: The inverse operation is available as a method of CubicBezier,
    QuadraticBezier and Line objects.)r   rc   )polyreturn_bpointsr1   s      r7   poly2bezrg      s!      %Gg&&r9   c                T    t        |       r| j                         } t        | ||      S )a  Converts a Bezier object or tuple of Bezier control points to a tuple
    of coefficients of the expanded polynomial.
    return_poly1d : returns a numpy.poly1d object.  This makes computations
    of derivatives/anti-derivatives and many other operations quite quick.
    numpy_ordering : By default (to accommodate numpy) the coefficients will
    be output in reverse standard order.
    Note:  This function is redundant thanks to the .poly() method included
    with all bezier segment classes.)numpy_orderingreturn_poly1d)r?   r1   r   )bezri   rj   s      r7   bez2polyrl      s,     kkmS,:+8: :r9   c                   | D cg c]
  } ||       }}t        | j                               D ]H  \  }\  }}|j                  |j                  k(  s#||dz   t	        |       z     j                  ||   _        J t        | S c c}w )zBMakes sure that, if joints were continuous, they're kept that way.r   )	enumeratejointsr3   r2   r-   rD   )rG   transformationr>   transformed_segsr]   sasbs          r7   transform_segments_togetherrt      s    7;<s+<< / R8B66RXX&6AT7J&K&Q&QQ#R !"" =s   Bc                *   fd}.t        | t              r| j                  n| j                  d      t        | t              rfd}t        | |      S t        |       r-t        | j                         D cg c]
  } ||       c}      S t        | t              rb || j                        } || j                        }| j                  z   }t        || j                  || j                  | j                  |      S t        d      c c}w )zReturns curve rotated by `degs` degrees (CCW) around the point `origin`
    (a complex number).  By default origin is either `curve.point(0.5)`, or in
    the case that curve is an Arc object, `origin` defaults to `curve.center`.
    c                D    t        dt              z        | z
  z  z   S )NrM   )r   r   )zdegsorigins    r7   rotate_pointzrotate.<locals>.rotate_point   s%    2gdm#$a&j1F::r9   g      ?c                     t        |       S )Nry   rotate)r>   rx   ry   s    r7   <lambda>zrotate.<locals>.<lambda>   s    VCf%E r9   radiusrotation	large_arcsweepr3   RInput `curve` should be a Path, Line, QuadraticBezier, CubicBezier, or Arc object.)r<   rA   centerpointrD   rt   r?   rc   r1   r2   r3   r   r   r   r   	TypeError)	curverx   ry   rz   rp   bpt	new_startnew_endnew_rotations	    ``      r7   r~   r~      s    
; ~eS!\\F[[%F%E*5.AA	5	!EMMOLS|C0LMM	E3	 -	uyy)~~,9U\\L"__EKKWN 	N  G H 	H Ms   =Dc                   t        | t              rfd}t        | |      S t        |       r*t	        | j                         D cg c]  }|z   	 c}      S t        | t              rW| j                  z   }| j                  z   }t        || j                  | j                  | j                  | j                  |      S t        d      c c}w )zlShifts the curve by the complex quantity z such that
    translate(curve, z0).point(t) = curve.point(t) + z0c                    t        |       S r;   	translate)r>   z0s    r7   r   ztranslate.<locals>.<lambda>       YsB%7 r9   r   r   )r<   rD   rt   r?   rc   r1   rA   r2   r3   r   r   r   r   r   )r   r   rp   r   r   r   s    `    r7   r   r      s     %7*5.AA	5	!5==?CCsRxCDD	E3	KK"$	))b.9U\\ENN"__EKKWN 	N  G H 	H Ds   C
c           
        dz  ndz  fdfd}t        | t              rfd}t        | |      S t        |       r ||       S t        | t              rtk(  rbt	        | j
                  z
  z  z   | j                  z  | j                  | j                  | j                  | j                  z
  z  z         S t        d      t        d      )a]  Scales `curve`, about `origin`, by diagonal matrix `[[sx,0],[0,sy]]`.

    Notes:
    ------
    * If `sy` is not specified, it is assumed to be equal to `sx` and 
    a scalar transformation of `curve` about `origin` will be returned.
    I.e.
        scale(curve, sx, origin).point(t) == 
            ((curve.point(t) - origin) * sx) + origin
    rM   c                P    | z  S | j                   z  | j                  z  z   S r;   )r$   r#   )rw   isysxsys    r7   _scalezscale.<locals>._scale	  s,    :a4K!&&y3qvv:%%r9   c                    t        |       D cg c]
  } |       }}|dxx          z
  z  cc<   t        |      S c c}w )N)rl   rg   )rk   cpr   ry   s      r7   scale_bezierzscale.<locals>.scale_bezier  sD     (.1VAY..	"&.(({ /s   Ac                     t        |       S r;   scale)r>   ry   r   r   s    r7   r   zscale.<locals>.<lambda>  s    U3B%? r9   r2   r   r   r   r   r3   zG
For `Arc` objects, only scale transforms with sx==sy are implemented.
r   )r<   rD   rt   r?   rA   r2   r   r   r   r   r3   	Exceptionr   )r   r   r   ry   r   rp   r   r   s    ```  @@r7   r   r      s     
zee&

 %?*5.AA	5	!E""	E3	:rRv!56? o %!&"[[uyy612V;= =  = > >  G H 	Hr9   c                   t        t        j                  d      k(  j                               r| S d }d }d }t	        | t
              rfd}t        | |      S t        |       rBt        | j                         D cg c]  } |j                   ||                  ! c}      S t	        | t              r |j                   || j                                    } |j                   || j                                    }| j                  j                  dz  }	| j                  j                   dz  }
t        j"                  d|	z  dgdd|
z  gg      }t        j$                  j'                  d	dd	df         }t)        t        j*                  |j,                  ||g      }t        j$                  j/                  |      \  }}dt        j0                  |d         z  }dt        j0                  |d         z  }t3        ||      }|d	d	df   }t        j4                  t        j6                  |d   |d               }|j                  dk(  s|j                   dk(  rt9        ||      S d   d   d   d   z  d
k\  r| j:                  }n| j:                   }t        ||| j<                  |z   | j>                  ||d      S tA        d      c c}w )z@Transforms the curve by the homogeneous transformation matrix tfr,   c                `    t        j                  | j                  g| j                  gdgg      S )N      ?nparrayr$   r#   )r   s    r7   to_pointztransform.<locals>.to_point.  &    xx!&&AFF8cU344r9   c                `    t        j                  | j                  g| j                  gdgg      S )N        r   )rw   s    r7   	to_vectorztransform.<locals>.to_vector1  r   r9   c                N    | j                  d      d| j                  d      z  z   S )Nr   rM   r   )item)vs    r7   
to_complexztransform.<locals>.to_complex4  s!    vvay2q	>))r9   c                    t        |       S r;   )	transform)r>   tfs    r7   r   ztransform.<locals>.<lambda>8  r   r9   r*   r   r   Nr   Tr   r   r   r   r3   autoscale_radiusr   )!rE   r   eyeravelr<   rD   rt   r?   rc   r1   dotrA   r2   r3   r   r$   r#   r   linalginvr   matmulTeigr	   complexr   arctan2r.   r   r   r   r   )r   r   r   r   r   rp   r   r   r   rx2ry2QinvTDeigvalseigvecsrxry
new_radiusxeigvecrot	new_sweeps    `                    r7   r   r   (  s}    B"&&)O""$%55* %7*5.AA	5	!(-9#$  *"&&!*=> 9 : 	:	E3	rvvhu{{&;<=	RVVHUYY$789 ll1$ll1$HHquaj1ae*-.yy}}R2A2Y'299tvvq$/099==+$$$$R_
!Q$-jjGAJ
;<??a:??a#7	7++!uQx"Q%("c)!KK	 %O	yenns>R!&	w(,. .
  G H 	HI9s   ?$Kc                R   | j                  |      }	 |t        |      z  }|S # t        t        f$ r | j	                         j                         }t        |      dz  t        |      dz  z   }	 t        t        |dz  ||            }Y |S # t        $ r  | j	                         j                         |dz
        } | j	                         j                         |dz         }dj                  |      dj                  |      z   dj                  |      z   }t        |      w xY ww xY w)a#  Returns the unit tangent of the segment at t.

    Notes
    -----
    If you receive a RuntimeWarning, try the following:
    >>> import numpy
    >>> old_numpy_error_settings = numpy.seterr(invalid='raise')
    This can be undone with:
    >>> numpy.seterr(**old_numpy_error_settings)
    r*   -C6?z8Unit tangent appears to not be well-defined at t = {}, 
z"seg.poly().deriv()(t - 1e-4) = {}
z!seg.poly().deriv()(t + 1e-4) = {})
derivativeabsZeroDivisionErrorFloatingPointErrorre   derivr$   r#   csqrtr    
ValueErrorformat)	r>   rT   dsegunit_tangent	dseg_polydseg_abs_squared_polybefaftmess	            r7   bezier_unit_tangentr   d  s9    >>!D"CI~& % 12 " HHJ$$&	!%iA!5!%iA!5"6
	" 	1,A1"F GL   	"$#((*""$QX.C$#((*""$QX.C  &q	8??DE 7==cBCC S/!	""s   # A
D&.B

BD""D&c                   | j                  |      }| j                  |d      }|j                  |j                  }}|j                  |j                  }}t        j                  d      }		 t        ||z  ||z  z
        t        ||z  ||z  z         dz  z  }
t        j                  di |	 |
S # t        t        f$ r | j                         }|j                         }|j                         }t        |      t        |      }}t        |      t        |      }}||z  ||z  z
  dz  }||z  ||z  z   dz  }t        |||      }|dk  rY t        j                  di |	 yt        |      }
Y w xY w# t        j                  di |	 w xY w)zreturns the curvature of the segment at t.

    Notes
    -----
    If you receive a RuntimeWarning, run command
    >>> old = np.seterr(invalid='raise')
    This can be undone with
    >>> np.seterr(**old)
    r*   nraise)invalidr,   r    )r   r$   r#   r   seterrr   r	   r   r   re   r   r    )selfrT   use_infdzddzdxdyddxddyold_np_seterrkappar   dpddpf2g2lim2s                    r7   segment_curvaturer     sl    
	B
//!q/
!CWWbggBxxCIIg.M#BsFRVO$T"R%"R%-%8!%;; 			"M"L 12 IIKWWYhhjb48B9d3iSfr#vo!ebemab"a(!8 			"M" T
 			"M"s1   ,,B/ /BE-E0 E-*E0 ,E--E0 0Fc                V     fd} j                         z
  }t        |      dz  t        |      dz  z   }ddgt        |j	                               z   }|D cg c]  } ||      |f }}|rt
        t        |t        d            }	t        |t        d            }
|	|
fS c c}w )aP  returns the tuples (d_min, t_min) and (d_max, t_max) which minimize and
    maximize, respectively, the distance d = |self.point(t)-origin|.
    return_all_global_extrema:  Multiple such t_min or t_max values can exist.
    By default, this will only return one. Set return_all_global_extrema=True
    to return all such global extrema.c                >    t        j                  |       z
        S r;   r   r   )taury   r>   s    r7   _radiusz#bezier_radialrange.<locals>._radius  s    399S>F*++r9   r*   r   r   key)	re   r$   r#   r"   r   NotImplementedErrorminr   max)r>   ry   return_all_global_extremar   shifted_seg_poly	r_squaredextremizersrT   extremaseg_global_minseg_global_maxs   ``         r7   bezier_radialranger	    s    , xxzF*%&!+%&!+,Ia&;y'899K(341
A4G4 !!W*Q-8W*Q-8~-- 5s   B&c                *    |j                  |       d   S )zreturns (|path.seg.point(t)-pt|, t, seg_idx) where t and seg_idx
    minimize the distance between pt and curve path[idx].point(t) for 0<=t<=1
    and any seg_idx.
    Warning:  Multiple such global minima can exist.  This will only return
    one.r   radialrangeptrG   s     r7   closest_point_in_pathr    s     B""r9   c                *    |j                  |       d   S )a,  returns (|path.seg.point(t)-pt|, t, seg_idx) where t and seg_idx
    maximize the distance between pt and curve path[idx].point(t) for 0<=t<=1
    and any seg_idx.
    :rtype : object
    :param pt:
    :param path:
    Warning:  Multiple such global maxima can exist.  This will only return
    one.r   r  r  s     r7   farthest_point_in_pathr    s     B""r9   c                    |j                         sJ t        t        | |            j                  |      }t	        |      dz  ryy)zreturns true if pt is a point enclosed by path (which must be a Path
    object satisfying path.isclosed==True).  opt is a point you know is
    NOT enclosed by path.r*   TF)isclosedrD   r.   	intersectr-   )r  optrG   intersectionss       r7   path_encloses_ptr    s@     ==??b#'11$7M
=Ar9   c                   ||z   dz  }| j                  |      }	t        ||z
        }
t        |	|z
        }t        ||	z
        }||z   }||
z
  |kD  s||k  r*|dz  }t        | ||||	|||      t        | |||	||||      z   S |S )z5Recursively approximates the length by straight linesr*   r   )r   r   segment_length)r   r2   r3   start_point	end_pointerror	min_depthdepthmid	mid_pointlength
first_halfsecond_halflength2s                 r7   r  r    s     3;/CC I[()FY,-Ji)+,K;&G&5 ei&7
ueS+y$i8uc3	9$i88 	9
 Nr9   c           	        | j                  ||      }|dkD  sJ d|cxk  r|k  st        d       t        d      |dk(  ry||k(  ryt        | t              rw| D cg c]  }|j                  ||       }}d}	t	        |      D ]F  \  }
}|	|cxk  r|	|z   k  r.n n+t        | |
   ||	z
  ||||      }| j                  |
|      c S |	|z  }	H yt        | t              r|| j                  ||      z  S t        | t              s t        | t              st        | t              rd}d}d}||k  rq|dz  }||z   dz  }| j                  |||      }t        ||z
        |k  r|S ||k  r|}n|}||k(  r(t        dj                  t        ||z
                     |S ||k  rqt        d	j                  |z
              t        d
      c c}w )aw  INPUT: curve should be a CubicBezier, Line, of Path of CubicBezier
    and/or Line objects.
    OUTPUT: Returns a float, t, such that the arc length of curve from 0 to
    t is approximately s.
    s_tol - exit when |s(t) - s| < s_tol where
        s(t) = seg.length(0, t, error, min_depth) and seg is either curve or,
        if curve is a Path object, then seg is a segment in curve.
    error - used to compute lengths of cubics and arcs
    min_depth - used to compute lengths of cubics and arcs
    Note:  This function is not designed to be efficient, but if it's slower
    than you need, make sure you have scipy installed.r  r  r   z)s is not in interval [0, curve.length()].r   s_tolmaxitsr  r  r*   )t1r  r  zQt is as close as a float can be to the correct value, but |s(t) - s| = {} > s_tolz.Maximum iterations reached with s(t) - s = {}.zQFirst argument must be a Line, QuadraticBezier, CubicBezier, Arc, or Path object.)r!  r   r<   rD   rn   inv_arclengtht2Tr.   r0   r/   rA   r   r   r   r   r   )r   sr(  r)  r  r  curve_lengthr>   seg_lengthslsumklen_krT   t_uppert_lower	iterations_ts                    r7   r+  r+    s     <<ey<AL!!\!DEE "DEEAvL%"') zzzC ) )!+. 	HAuq(D5L(!%(AHE)/u,57 yyA&EMD	 	E4	 5<<ey<AAA
UO
,
UK
(
UC
 	& NI7"A%A,,!5I,FC37|e#q'! 3396#c!e*3EG &   !6#'?, 	,  < = 	=O)s   G
c                   ||k  sJ |dk(  r| j                  |      d   }|S |dk(  r| j                  |      d   }|S | j                  |      }t        | |d      }|j                  |      d   d   }t        |d|      }|S )zECrop a copy of this `self` from `self.point(t0)` to `self.point(t1)`.r   r   )splitr   crop_bezierr  )r>   t0r*  cropped_segpt1trimmed_segt1_adjs          r7   r9  r9  B  s    7N7	QwiimA&  
qiimA&  iim "#r1- ((-a03!+q&9r9   c                      e Zd Zd ZddZd Zd Zd Zd Zd Z	ddZ
d	 Zd
 Zd dZeeeefdZd ZddZd!dZd"dZd"dZd Zd Zd"dZd Zd Zd Zd Zd Zd"dZ d Z!d#dZ"y)$r.   c                     || _         || _        y r;   r2   r3   )r   r2   r3   s      r7   __init__zLine.__init__Z  s    
r9   c                D    t        | j                  | j                  f      S r;   )hashr2   r3   r   s    r7   __hash__zLine.__hash__^  s    TZZ*++r9   c                <    d| j                   d| j                  dS )NzLine(start=, end=)rA  rE  s    r7   __repr__zLine.__repr__a  s    +/::txx@@r9   c                    t        |t              sy| j                  |j                  k(  xr | j                  |j                  k(  S NF)r<   r.   r2   r3   r   others     r7   __eq__zLine.__eq__d  s4    %&zzU[[(BTXX-BBr9   c                :    t        |t              st        S | |k(   S r;   )r<   r.   NotImplementedrM  s     r7   __ne__zLine.__ne__i      %&!!5=  r9   c                (    | j                         |   S r;   r1   r   r   s     r7   __getitem__zLine.__getitem__n      ||~d##r9   c                     y)Nr*   r   rE  s    r7   __len__zLine.__len__q      r9   c                B   |rO| j                   |j                  k(  xr4 t        j                  | j	                  d      |j	                  d            S | j                   |j                  k(  xr4 t        j                  | j                  d      |j                  d            S aJ  Checks if this segment joins smoothly with previous segment.  By
        default, this only checks that this segment starts moving (at t=0) in
        the same direction (and from the same positive) as previous stopped
        moving (at t=1).  To check if the tangent magnitudes also match, set
        wrt_parameterization=True.r   r   r2   r3   r   iscloser   r   r   previouswrt_parameterizations      r7   joins_smoothly_withzLine.joins_smoothly_witht        ::- <"**"H$7$7$:3< < ::- @"**!!!$h&;&;A&>3@ @r9   c                X    | j                   | j                  z
  }| j                  ||z  z   S );returns the coordinates of the Bezier curve evaluated at t.r3   r2   )r   rT   distances      r7   r   z
Line.point  s'    88djj(zzHQJ&&r9   c                .     | j                         |      S z*Faster than running Path.point many times.re   r   tss     r7   r\   zLine.points      tyy{2r9   Nc                R    t        | j                  | j                  z
        ||z
  z  S )z9returns the length of the line segment between t0 and t1.)r   r3   r2   )r   r:  r*  r  r  s        r7   r!  zLine.length  s#    488djj()2b511r9   c                $    t        | |||||      S zReturns a float, t, such that self.length(0, t) is approximately s.
        See the inv_arclength() docstring for more details.r'  r+  r   r-  r(  r)  r  r  s         r7   ilengthzLine.ilength       T1E&'02 	2r9   c                2    | j                   | j                  fS z1returns the Bezier control points of the segment.rA  rE  s    r7   r1   zLine.bpoints  s    zz488##r9   c                t    | j                         }|d   |d   z
  |d   g}|r|S t        j                  |      S )z(returns the line as a Polynomial object.r   r   r1   r   poly1dr   return_coeffsr   coeffss       r7   re   z	Line.poly  s>    LLNQ4!A$;!%M99V$$r9   c                    | j                   | j                  k7  sJ |dk(  r| j                   | j                  z
  S |dkD  ryt        d      )/returns the nth derivative of the segment at t.r   r   n should be a positive integer.)r3   r2   r   )r   rT   r   s      r7   r   zLine.derivative  sH    xx4::%%%688djj((U>??r9   c                    | j                   | j                  k7  sJ | j                   | j                  z
  }|t        |      z  S )z-returns the unit tangent of the segment at t.)r3   r2   r   r   rT   r   s      r7   r   zLine.unit_tangent  s8    xx4::%%%xx$**$CI~r9   c                *    d| j                  |      z  S z>returns the (right hand rule) unit normal vector to self at t.y             r   r   rT   s     r7   normalzLine.normal      4$$Q'''r9   c                     y)z8returns the curvature of the line, which is always zero.r   r   r  s     r7   	curvaturezLine.curvature  s    r9   c                B    t        | j                  | j                        S )z@returns a copy of the Line object with its orientation reversed.)r.   r3   r2   rE  s    r7   rN   zLine.reversed  s    DHHdjj))r9   c                   t        |t        t        t        f      r |j	                         D cg c]  }|j
                   }}| j	                         D cg c]  }|j
                   }}t        |      t        |      kD  rg S t        |      t        |      k  rg S |j	                         D cg c]  }|j                   }}| j	                         D cg c]  }|j                   }}t        |      t        |      kD  rg S t        |      t        |      k  rg S t        |t              r|j                  |j                  k7  r| j                  | j                  k7  sJ | |k7  sJ | j                  j
                  | j                  j
                  f}| j                  j                  | j                  j                  f}|j                  j
                  |j                  j
                  f}|j                  j                  |j                  j                  f}	|d   |d   z
  |	d   |	d   z
  z  |d   |d   z
  |d   |d   z
  z  z
  }
t        j                  |
d      rg S |d   |d   |	d   z
  z  |d   |d   |	d   z
  z  z
  |d   |	d   |	d   z
  z  z
  |
z  }|d   |d   |	d   z
  z  |d   |d   |	d   z
  z  z
  |d   |d   |d   z
  z  z
   |
z  }d|cxk  rdk  rn g S d|cxk  rdk  r	n g S ||fgS g S t        |t              r#t        ||       }|D cg c]	  \  }}||f c}}S t        |t              r#t        ||       }|D cg c]	  \  }}||f c}}S t        |t              r(|j                  |       }|D cg c]	  \  }}||f c}}S t        |t               rt#        d      t#        d      c c}w c c}w c c}w c c}w c c}}w c c}}w c c}}w )a  Finds the intersections of two segments.
        returns a list of tuples (t1, t2) such that
        self.point(t1) == other_seg.point(t2).
        Note: This will fail if the two segments coincide for more than a
        finite collection of points.
        tol is not used.r   r   Jother_seg must be a path segment, not a Path object, use Path.intersect().!other_seg must be a path segment.)r<   r.   r0   r/   r1   r$   r   r  r#   r3   r2   r   r_  r   rA   r  rD   r   )r   	other_segtoleobrs   arS   r   ddenomr*  t2t2t1ss                 r7   r  zLine.intersect  s    i$!EF"+"3"3"56Q!&&6B6"&,,.1Q!&&1B12wR 	2wR 	"+"3"3"56Q!&&6B6"&,,.1Q!&&1B12wR 	2wR 	i&==IOO3DJJ8NNN9$$$ $((--0A$((--0A%%y}}'9'9:A%%y}}'9'9:AdQqTkAaD1Q4K0dQqTkAaD1Q4K01Ezz%#	A$!qt$A$!qt$%A$!qt$%&+,B Q41!%Q41!%&Q41!%& '',-B B|!|I !"R1I Rz!I	?30DAE+01RRH11	;/0DAE+01RRH11	3'''-E+01RRH11	4($% % ?@@a 71
 71: 2 2 2s)   N:N?/OO	O
OOc                   t        | j                  j                  | j                  j                        }t	        | j                  j                  | j                  j                        }t        | j                  j
                  | j                  j
                        }t	        | j                  j
                  | j                  j
                        }||||fS zVreturns the bounding box for the segment in the form
        (xmin, xmax, ymin, ymax).)r   r2   r$   r3   r  r#   )r   rO   rP   rQ   rR   s        r7   bboxz	Line.bbox  s     4::??DHHMM24::??DHHMM24::??DHHMM24::??DHHMM2T4%%r9   c                d   t        j                  || j                  dd      ryt        j                  || j                  dd      ry| j	                         }||d   z
  |d   z  }t        j                  |j
                  d      r*|j                  dk\  r|j                  dk  r|j                  S y)zvIf the point lies on the Line, returns its `t` parameter.
        If the point does not lie on the Line, returns None.r   ư>rtolatolr   r   r   N)r   r_  r2   r3   re   r#   r$   )r   r   r   rT   s       r7   
point_to_tzLine.point_to_t  s     ::eTZZad;ZZtxxad; IIK QqT\QqT!::affa affm!&&C-66Mr9   c                V    t        | j                  |      | j                  |            S ireturns a cropped copy of this segment which starts at
        self.point(t0) and ends at self.point(t1).)r.   r   r   r:  r*  s      r7   croppedzLine.cropped"  s!     DJJrNDJJrN33r9   c                |    | j                  |      }t        | j                  |      t        || j                        fS zZreturns two segments, whose union is this segment and which join at
        self.point(t).)r   r.   r2   r3   )r   rT   r  s      r7   r8  z
Line.split'  s2     ZZ]DJJ#T"dhh%777r9   c                8   |j                   |j                  }}| j                  | j                  }}|j                   |j                  |j                   |j                  f\  }}}	}
|	|z
  |
|z
  }}|||z
  z  |||z
  z  z   ||z  ||z  z   }}||z  }d|cxk  rdk  rQn nNt	        ||z
        t	        ||z
        t	        | j                  |      |z
        }}}||k  r||f|dffS ||f|dffS t	        ||z
        t	        ||z
        }}||k  r|df|dffS |df|dffS )a<  compute points in self that are min and max distance to origin.

        Args:
            origin (complex): the point extremize distance to

        Returns:
            tuples (d_min, t_min) and (d_max, t_max) which minimize and
            maximize, respectively, the distance d = |self.point(t)-origin|.
        r   r   )r$   r#   r2   r3   r   r   )r   ry   kwargsxyp0p1x0y0x1y1r   r   	numeratordenominatorrT   d0d1dts                      r7   r  zLine.radialrange-  sN    {{FKK1TXXB"''277BGG;BBb"r'B!#q2vq2v!>R"r'@Q;	#q919 BK BK DJJqMF*+ B
 BwAwQ''7RG## f%s2;'7BBwAwQ''7RG##r9   c                    t        | ||      S zReturns a copy of self rotated by `degs` degrees (CCW) around the
        point `origin` (a complex number).  By default `origin` is either
        `self.point(0.5)`, or in the case that self is an Arc object,
        `origin` defaults to `self.center`.r|   r}   r   rx   ry   s      r7   rotatedzLine.rotatedQ      
 dD00r9   c                    t        | |      S zReturns a copy of self shifted by the complex quantity `z0` such
        that self.translated(z0).point(t) = self.point(t) + z0 for any t.r   r   r   s     r7   
translatedzLine.translatedX       r""r9   c                     t        | |||      S z?Scale transform.  See `scale` function for further explanation.)r   r   ry   r   r   r   r   ry   s       r7   scaledzLine.scaled]      TbR77r9   returnintFr   r   NN)Nr   r;   N                )#__name__
__module____qualname__rB  rF  rJ  rO  rR  rW  rZ  rc  r   r\   r!  ILENGTH_S_TOLILENGTH_MAXITSILENGTH_ERRORILENGTH_MIN_DEPTHrt  r1   re   r   r   r  r  rN   r  r  r  r  r8  r  r  r  r  r   r9   r7   r.   r.   Y  s    ,AC
!
$@'
2  -^#/@2$%@(*8At&.4
8"$H1#
8r9   r.   c                      e Zd ZdddZd ZddZd Zd Zd Zd Z	d	 Z
d d
Z	 	 d!dZd Zd Zd"dZeeeefdZd Zd#dZd$dZd Zd Zd Zd Zd%dZd Zd Zd Zd#dZ d&dZ!d Z"d'dZ#y)(r0   Nr!  r1   c                B    || _         || _        || _        d d d| _        y )Nr  )r2   r3   r6   _length_info)r   r2   r6   r3   s       r7   rB  zQuadraticBezier.__init__f  s&    
 (,=r9   c                Z    t        | j                  | j                  | j                  f      S r;   )rD  r2   r6   r3   rE  s    r7   rF  zQuadraticBezier.__hash__n  s     TZZtxx899r9   c                V    d| j                   d| j                  d| j                  dS )NzQuadraticBezier(start=z
, control=rH  rI  r2   r6   r3   rE  s    r7   rJ  zQuadraticBezier.__repr__q  s    JJdhh0 	0r9   c                    t        |t              sy| j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S rL  )r<   r0   r2   r3   r6   rM  s     r7   rO  zQuadraticBezier.__eq__u  sM    %1zzU[[( .TXX-B .-	.r9   c                :    t        |t              st        S | |k(   S r;   )r<   r0   rQ  rM  s     r7   rR  zQuadraticBezier.__ne__{  s    %1!!5=  r9   c                (    | j                         |   S r;   rU  rV  s     r7   rW  zQuadraticBezier.__getitem__  rX  r9   c                     y)Nr,   r   rE  s    r7   rZ  zQuadraticBezier.__len__  r[  r9   c                   |rt        t               t        |t              rN| j                  |j
                  k(  xr3 | j                  | j                  z
  |j
                  |j                  z
  k(  S | j                  | j                  k(  S aT  [Warning: The name of this method is somewhat misleading (yet kept
        for compatibility with scripts created using svg.path 2.0).  This
        method is meant only for d string creation and should not be used to
        check for kinks.  To check a segment for differentiability, use the
        joins_smoothly_with() method instead.])r   _is_smooth_from_warningr<   r0   r2   r3   r6   r   ra  
warning_ons      r7   is_smooth_fromzQuadraticBezier.is_smooth_from  sp     ()h0JJ(,,. 9\\DJJ. x'7'779: <<4::--r9   c                .   |rJ| j                   |j                  k(  xr/ t        | j                  d      |j                  d      z
        |k  S | j                   |j                  k(  xr/ t        | j	                  d      |j	                  d      z
        |k  S r]  r2   r3   r   r   r   r   ra  rb  r  s       r7   rc  z#QuadraticBezier.joins_smoothly_with        ::- F#"X%8%8%;;3=@E3F F ::- J#!!!$x'<'<Q'??3ADI3J Jr9   c                    d|z
  }||z  | j                   z  d|z  |z  | j                  z  z   ||z  | j                  z  z   S )rf  r   r*   r  )r   rT   tcs      r7   r   zQuadraticBezier.point  sE    U"uTZZ!B$q&"55!DHHDDr9   c                .     | j                         |      S rj  rk  rl  s     r7   r\   zQuadraticBezier.points  rn  r9   c                   |dk(  r4|dk(  r/| j                   d   | j                         k(  r| j                   d   S | j                  d| j                  z  z
  | j                  z   }d| j                  | j                  z
  z  }|j
                  |j
                  z  |j                  |j                  z  z   }t        |      dk  rt        |      ||z
  z  }nd|j
                  dz  |j                  dz  z   z  }	d|z  }
|j
                  dz  |j                  dz  z   }|
d|	z  z  }||	z  |dz  z
  }t        |	|dz  z  |
|z  z   |z         }t        |	|dz  z  |
|z  z   |z         }t        |	      ||z   z  |z   t        |	      ||z   z  |z   z  }||z   |z  ||z   |z  z
  |t        |	      z  t        |      z  z   }|dz  }t        |      rt        |      dt        |      z  z  }||k  r)t        |      |dz  |dz  z
  z  t        |      ||z
  z  z
  S ||k  r)t        |      |dz  |dz  z
  z  t        |      ||z
  z  z
  S t        |      |dz  |dz  z   z  t        |      ||z   z  z
  t        |      dz  dt        |      z  z  z   S |dk(  r@|dk(  r;|| j                   d<   | j                         | j                   d<   | j                   d   S |S )Nr   r   r1   r!  r*   r(   r+   )r  r1   r2   r6   r3   r$   r#   r   r	   r   r   )r   r:  r*  r  r  r  rS   a_dot_br-  c2c1c0betagammadq1_magdq0_maglogarandtstars                     r7   r!  zQuadraticBezier.length  s   7rQw  +t||~=((22JJ4<<'$((2t||djj()&&-!&&-/q6E>AR AaffkAFFaK/0BWB1qvv{*BR=DGdai'E2a<"r'1B67G2a<"r'1B67GRBI.8RBI.8:Hdg%dg(==R 3x=01AFAQxA!c!f*-:q6R1WrQw%67#a&BG:LLLRZq6R1WrQw%67#a&BG:LLLq6R1WrQw%67#a&BG:LLq6Q;!c!f*56 6 7rQw*+Dh'+/<<>Di($$X..Hr9   c                $    t        | |||||      S rq  rr  rs  s         r7   rt  zQuadraticBezier.ilength  ru  r9   c                H    | j                   | j                  | j                  fS rw  r  rE  s    r7   r1   zQuadraticBezier.bpoints  s    zz4<<11r9   c                    | j                         }|d   d|d   z  z
  |d   z   d|d   |d   z
  z  |d   f}|r|S t        j                  |      S )z-returns the quadratic as a Polynomial object.r   r*   r   ry  r{  s       r7   re   zQuadraticBezier.poly  s]    LLNA$1Q4-!A$&1Q4!A$;1>M99V$$r9   c                    | j                         }|dk(  r#d|d   |d   z
  d|z
  z  |d   |d   z
  |z  z   z  S |dk(  rd|d   d|d   z  z
  |d   z   z  S |dkD  ryt        d      )returns the nth derivative of the segment at t.
        Note: Bezier curves can have points where their derivative vanishes.
        If you are interested in the tangent direction, use the unit_tangent()
        method instead.r   r*   r   r  r1   r   r   rT   r   r   s       r7   r   zQuadraticBezier.derivative  s    
 LLN6qtad{QU+qtad{Ao=>>!VadQqtVmad*++U>??r9   c                    t        | |      S a  returns the unit tangent vector of the segment at t (centered at
        the origin and expressed as a complex number).  If the tangent
        vector's magnitude is zero, this method will find the limit of
        self.derivative(tau)/abs(self.derivative(tau)) as tau approaches t.r   r  s     r7   r   zQuadraticBezier.unit_tangent      
 #4++r9   c                *    d| j                  |      z  S r  r  r  s     r7   r  zQuadraticBezier.normal   r  r9   c                    t        | |      S z*returns the curvature of the segment at t.r   r  s     r7   r  zQuadraticBezier.curvature       q))r9   c                    t        | j                  | j                  | j                        }| j                  d   rA| j                  |_        | j                  | j                  | j                  f|j                  d<   |S )zSreturns a copy of the QuadraticBezier object with its orientation
        reversed.r!  r1   )r0   r3   r6   r2   r  )r   new_quads     r7   rN   zQuadraticBezier.reversed  sd     #488T\\4::FX&$($5$5H!$,,

04H!!),r9   c                   t        |t        t        t        f      r |j	                         D cg c]  }|j
                   }}| j	                         D cg c]  }|j
                   }}t        |      t        |      kD  rg S t        |      t        |      k  rg S |j	                         D cg c]  }|j                   }}| j	                         D cg c]  }|j                   }}t        |      t        |      kD  rg S t        |      t        |      k  rg S t        |t              rt        | |      S t        |t              r?| |k7  sJ t        | j                         |j                               }t        | ||||      S t        |t              r8t        | j                         |j                               }t        | ||||      S t        |t              r(|j                  |       }|D 	cg c]	  \  }}	|	|f c}	}S t        |t              rt        d      t        d      c c}w c c}w c c}w c c}w c c}	}w )zFinds the intersections of two segments.
        returns a list of tuples (t1, t2) such that
        self.point(t1) == other_seg.point(t2).
        Note: This will fail if the two segments coincide for more than a
        finite collection of points.longer_lengthr  tol_deCr  r  r<   r.   r0   r/   r1   r$   r   r  r#   r   r!  r   rA   r  rD   r   )
r   r  r  r  r  rs   r  r  r  r*  s
             r7   r  zQuadraticBezier.intersect  s    i$!EF"+"3"3"56Q!&&6B6"&,,.1Q!&&1B12wR 	2wR 	"+"3"3"56Q!&&6B6"&,,.1Q!&&1B12wR 	2wR 	i&/i@@	?39$$$y/?/?/ABM'i6C,/> > 	;/y/?/?/ABM'i6C,/> > 	3'''-E+01RRH11	4($% % ?@@C 71
 71( 2s   H.H3/H8H=6Ic                    t        |       S r  r   rE  s    r7   r  zQuadraticBezier.bboxG  s     #4((r9   c                \    t        | j                         |      \  }}t        | t        | fS r  )r   r1   r0   r   rT   bpoints1bpoints2s       r7   r8  zQuadraticBezier.splitL  s0     *$,,.!<()?H+EEEr9   c                (    t        t        | ||       S r  )r0   r9  r  s      r7   r  zQuadraticBezier.croppedR  s     D"b 9::r9   c                    t        | ||      S zreturns the tuples (d_min, t_min) and (d_max, t_max) which minimize
        and maximize, respectively, the distance d = |self.point(t)-origin|.)r  r	  r   ry   r  s      r7   r  zQuadraticBezier.radialrangeW  s     "$*CE 	Er9   c                    t        | ||      S r  r}   r  s      r7   r  zQuadraticBezier.rotated]  r  r9   c                    t        | |      S r  r   r  s     r7   r  zQuadraticBezier.translatedd  r  r9   c                     t        | |||      S r  r   r  s       r7   r  zQuadraticBezier.scaledi  r  r9   r  TFr   r  r  r   r(   r;   r  )$r  r  r  r  rB  rF  rJ  rO  rR  rW  rZ  r  rc  r   r\   r!  r  r  r  r  rt  r1   re   r   r   r  r  rN   r  r  r8  r  r  r  r  r  r   r9   r7   r0   r0   b  s    "t4L>:0.!
$. BG"#JE
(T  -^#/@22%@,(*(AT)
F;
E1#
8r9   r0   c                      e Zd ZdddddZd Zd!dZd Zd Zd Zd Z	d	 Z
d"d
Zd#dZd Zd ZddeefdZeeeefdZd Zd#dZd$dZd Zd Zd Zd Zd%dZd Zd Z d Z!d#dZ"d&dZ#d Z$d'd Z%y)(r/   Nr!  r1   r  r  c                T    || _         || _        || _        || _        d d d d d| _        y )Nr!  )r2   r4   r5   r3   r  )r   r2   r4   r5   r3   s        r7   rB  zCubicBezier.__init__s  s4    
   (,t*.0r9   c                p    t        | j                  | j                  | j                  | j                  f      S r;   )rD  r2   r4   r5   r3   rE  s    r7   rF  zCubicBezier.__hash__}  s&    TZZtxxHIIr9   c           	     p    d| j                   d| j                  d| j                  d| j                  d	S )NzCubicBezier(start=z, control1=z, control2=rH  rI  r2   r4   r5   r3   rE  s    r7   rJ  zCubicBezier.__repr__  s'    JJt}}dhh@ 	@r9   c                    t        |t              sy| j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S rL  )r<   r/   r2   r3   r4   r5   rM  s     r7   rO  zCubicBezier.__eq__  sb    %-zzU[[( 0TXX-B 0/0/	0r9   c                :    t        |t              st        S | |k(   S r;   )r<   r/   rQ  rM  s     r7   rR  zCubicBezier.__ne__  s    %-!!5=  r9   c                (    | j                         |   S r;   rU  rV  s     r7   rW  zCubicBezier.__getitem__  rX  r9   c                     y)Nr+   r   rE  s    r7   rZ  zCubicBezier.__len__  r[  r9   c                   |rt        t               t        |t              rN| j                  |j
                  k(  xr3 | j                  | j                  z
  |j
                  |j                  z
  k(  S | j                  | j                  k(  S r  )r   r  r<   r/   r2   r3   r4   r5   r  s      r7   r  zCubicBezier.is_smooth_from  sp     ()h,JJ(,,. :]]TZZ/ x'8'88:; ==DJJ..r9   c                B   |rO| j                   |j                  k(  xr4 t        j                  | j	                  d      |j	                  d            S | j                   |j                  k(  xr4 t        j                  | j                  d      |j                  d            S r]  r^  r`  s      r7   rc  zCubicBezier.joins_smoothly_with  rd  r9   c           
     0   | j                   |d| j                  | j                   z
  z  |d| j                   | j                  z   z  d| j                  z  z
  || j                    d| j                  | j                  z
  z  z   | j                  z   z  z   z  z   z  z   S )z9Evaluate the cubic Bezier curve at t using Horner's rule.r,      r%  r  s     r7   r   zCubicBezier.point  s    
 zzAt}}tzz)*Q4::-.4==@1ZZK!T]]T]]%B"CCdhhND .   	r9   c                .     | j                         |      S rj  rk  rl  s     r7   r\   zCubicBezier.points  rn  r9   r   r   c           
     "    |dk(  rX|dk(  rS j                   d    j                         k(  r3 j                   d   |k\  r! j                   d   |k\  r j                   d   S t        rt         fd|||d	      d   }n0t	         || j                  |       j                  |      ||d      }|dk(  r^|dk(  rY| j                   d<    j                          j                   d<   | j                   d<   | j                   d<    j                   d   S |S )
z9Calculate the length of the path up to a certain positionr   r   r1   r  r  r!  c                8    t        j                  |             S r;   r   r   r   r   s    r7   r   z$CubicBezier.length.<locals>.<lambda>  s    T__S%9!: r9     epsabslimit)r  r1   _quad_availabler   r  r   )r   r:  r*  r  r  r-  s   `     r7   r!  zCubicBezier.length  s   7rQw  +t||~=))'2e;))+6)C((22 :B#(6679A tRTZZ^TZZ^$i4A 7rQw*+Dh'+/<<>Di().Dg&-6Dk*$$X..Hr9   c                $    t        | |||||      S rq  rr  rs  s         r7   rt  zCubicBezier.ilength  ru  r9   c                ^    | j                   | j                  | j                  | j                  fS rw  r%  rE  s    r7   r1   zCubicBezier.bpoints  s!    zz4==$--AAr9   c                    | j                         }|d    d|d   |d   z
  z  z   |d   z   d|d   d|d   z  z
  |d   z   z  d|d    |d   z   z  |d   f}|r|S t        j                  |      S )z+Returns a the cubic as a Polynomial object.r   r,   r   r*   ry  r{  s       r7   re   zCubicBezier.poly  s    LLNQ4%!QqTAaD[/)AaD0QqTAadF]QqT)*adUQqT\"A$ M99V$$r9   c                   | j                         }|dk(  rDd|d   |d   z
  z  d|z
  dz  z  d|d   |d   z
  z  d|z
  z  |z  z   d|d   |d   z
  z  |dz  z  z   S |dk(  r5dd|z
  |d   d|d   z  z
  |d   z   z  ||d   d|d   z  z
  |d   z   z  z   z  S |dk(  rd|d   d|d   |d   z
  z  z
  |d   z
  z  S |dkD  ryt        d      )r  r   r,   r   r*   r-  r  r  r  s       r7   r   zCubicBezier.derivative  s/   
 LLN6adQqTk?AEA:-1Q4!A$;Q0G0IIA!qtMTM" " "!VQ1!A$1-.AaD1QqT6MAaD4H1IIK K!VadQ!qt_,qt344U>??r9   c                    t        | |      S r  r   r  s     r7   r   zCubicBezier.unit_tangent  r  r9   c                *    d| j                  |      z  S r  r  r  s     r7   r  zCubicBezier.normal  s    T&&q)))r9   c                    t        | |      S r  r  r  s     r7   r  zCubicBezier.curvature  r  r9   c                (   t        | j                  | j                  | j                  | j                        }| j
                  d   rL| j
                  |_        | j                  | j                  | j                  | j                  f|j
                  d<   |S )zOreturns a copy of the CubicBezier object with its orientation
        reversed.r!  r1   )r/   r3   r5   r4   r2   r  )r   new_cubs     r7   rN   zCubicBezier.reversed  st     dhht}}"jj*X&#'#4#4G $--

/DG  +r9   c                   t        |t        t        t        f      r |j	                         D cg c]  }|j
                   }}| j	                         D cg c]  }|j
                   }}t        |      t        |      kD  rg S t        |      t        |      k  rg S |j	                         D cg c]  }|j                   }}| j	                         D cg c]  }|j                   }}t        |      t        |      kD  rg S t        |      t        |      k  rg S t        |t              rt        | |      S t        |t              st        |t              r?| |k7  sJ t        | j                         |j                               }t        | ||||      S t        |t              r&|j                  |       D cg c]	  \  }}||f c}}S t        |t              rt        d      t        d      c c}w c c}w c c}w c c}w c c}}w )a<  Finds the intersections of two segments.

        Returns:
            (list[tuple[float]]) a list of tuples (t1, t2) such that
            self.point(t1) == other_seg.point(t2).

        Scope:
            This will fail if the two segments coincide for more than a
            finite collection of points.
        r
  zP`other_seg` must be a path segment, not a `Path` object, use `Path.intersect()`.z#`other_seg` must be a path segment.r  )	r   r  r  r  r  rs   r  r  r*  s	            r7   r  zCubicBezier.intersect)  s    i$!EF"+"3"3"56Q!&&6B6"&,,.1Q!&&1B12wR 	2wR 	"+"3"3"56Q!&&6B6"&,,.1Q!&&1B12wR 	2wR 	i&/i@@O4K09$$$y/?/?/ABM'i}#s  	3'+4+>+>t+DERRHEE	4( E F F ABB7 71
 71 Fs   G4G9/G>H<Hc                    t        |       S )z8returns bounding box in format (xmin, xmax, ymin, ymax).r  rE  s    r7   r  zCubicBezier.bboxR  s    "4((r9   c                \    t        | j                         |      \  }}t        | t        | fS )z=Splits a copy of `self` at t and returns the two subsegments.)r   r1   r/   r  s       r7   r8  zCubicBezier.splitV  s.    )$,,.!<(H%{H'===r9   c                (    t        t        | ||       S r  )r/   r9  r  s      r7   r  zCubicBezier.cropped[  s     Kb"566r9   c                    t        | ||      S r  r  r  s      r7   r  zCubicBezier.radialrange`  s     "&4MO 	Or9   c                    t        | ||      S r  r}   r  s      r7   r  zCubicBezier.rotatedf  r  r9   c                    t        | |      S r  r   r  s     r7   r  zCubicBezier.translatedm  r  r9   c                     t        | |||      S r  r   r  s       r7   r  zCubicBezier.scaledr  r  r9   r  r  r  r  r  r;   r  )&r  r  r  r  rB  rF  rJ  rO  rR  rW  rZ  r  rc  r   r\   LENGTH_ERRORLENGTH_MIN_DEPTHr!  r  r  r  r  rt  r1   re   r   r   r  r  rN   r  r  r8  r  r  r  r  r  r   r9   r7   r/   r/   n  s    "td!%'L0J@0!
$/@	 a|?O 2  -^#/@2B
%@&,**	'CR)>
7
O1#
8r9   r/   c                      e Zd Z	 d$dZd%dZd&dZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZddeefdZeeeefdZ	 	 d'dZd(dZd Zd Zd Zd Zd Zd)dZd Z d Z!d Z"d*dZ#d+dZ$d  Z%d,d!Z&d(d"Z'd(d#Z(y)-rA   c                   ||k7  sJ |j                   dk7  r|j                  dk7  sJ || _        t        |j                         dt        |j                        z  z   | _        || _        t        |      | _        t        |      | _        || _	        || _
        d| _        d| _        t        | j
                        | _        t        d| j                  z        | _        | j#                          y)a  
        This should be thought of as a part of an ellipse connecting two
        points on that ellipse, start and end.
        Parameters
        ----------
        start : complex
            The start point of the curve. Note: `start` and `end` cannot be the
            same.  To make a full ellipse or circle, use two `Arc` objects.
        radius : complex
            rx + 1j*ry, where rx and ry are the radii of the ellipse (also
            known as its semi-major and semi-minor axes, or vice-versa or if
            rx < ry).
            Note: If rx = 0 or ry = 0 then this arc is treated as a
            straight line segment joining the endpoints.
            Note: If rx or ry has a negative sign, the sign is dropped; the
            absolute value is used instead.
            Note:  If no such ellipse exists, the radius will be scaled so
            that one does (unless autoscale_radius is set to False).
        rotation : float
            This is the CCW angle (in degrees) from the positive x-axis of the
            current coordinate system to the x-axis of the ellipse.
        large_arc : bool
            Given two points on an ellipse, there are two elliptical arcs
            connecting those points, the first going the short way around the
            ellipse, and the second going the long way around the ellipse.  If
            `large_arc == False`, the shorter elliptical arc will be used.  If
            `large_arc == True`, then longer elliptical will be used.
            In other words, `large_arc` should be 0 for arcs spanning less than
            or equal to 180 degrees and 1 for arcs spanning greater than 180
            degrees.
        sweep : bool
            For any acceptable parameters `start`, `end`, `rotation`, and
            `radius`, there are two ellipses with the given major and minor
            axes (radii) which connect `start` and `end`.  One which connects
            them in a CCW fashion and one which connected them in a CW
            fashion.  If `sweep == True`, the CCW ellipse will be used.  If
            `sweep == False`, the CW ellipse will be used.  See note on curve
            orientation below.
        end : complex
            The end point of the curve. Note: `start` and `end` cannot be the
            same.  To make a full ellipse or circle, use two `Arc` objects.
        autoscale_radius : bool
            If `autoscale_radius == True`, then will also scale `self.radius`
            in the case that no ellipse exists with the input parameters
            (see inline comments for further explanation).

        Derived Parameters/Attributes
        -----------------------------
        self.theta : float
            This is the phase (in degrees) of self.u1transform(self.start).
            It is $\theta_1$ in the official documentation and ranges from
            -180 to 180.
        self.delta : float
            This is the angular distance (in degrees) between the start and
            end of the arc after the arc has been sent to the unit circle
            through self.u1transform().
            It is $\Delta\theta$ in the official documentation and ranges from
            -360 to 360; being positive when the arc travels CCW and negative
            otherwise (i.e. is positive/negative when sweep == True/False).
        self.center : complex
            This is the center of the arc's ellipse.
        self.phi : float
            The arc's rotation in radians, i.e. `radians(self.rotation)`.
        self.rot_matrix : complex
            Equal to `exp(1j * self.phi)` which is also equal to
            `cos(self.phi) + 1j*sin(self.phi)`.


        Note on curve orientation (CW vs CCW)
        -------------------------------------
        The notions of clockwise (CW) and counter-clockwise (CCW) are reversed
        in some sense when viewing SVGs (as the y coordinate starts at the top
        of the image and increases towards the bottom).
        r   rM   N)r$   r#   r2   r   r   r   boolr   r   r3   r   segment_length_hashr  r   phir   
rot_matrix_parameterize)r   r2   r   r   r   r   r3   r   s           r7   rB  zArc.__init__x  s    X ||{{aFKK1$444
&++&C,<)<< i%[
 0#' " 4==)bk* 	r9   c                    | j                   | j                  | j                  | j                  | j                  | j
                  fS )z>Analog of the Bezier path method, .bpoints(), for Arc objects.r   rE  s    r7   apointszArc.apoints  s0    zz4;;t~~tzzSWS[S[[[r9   c                4    t        | j                               S r;   )rD  rS  rE  s    r7   rF  zArc.__hash__  s    DLLN##r9   c                    | j                   | j                  | j                  | j                  | j                  | j
                  f} dj                  | S )NzEArc(start={}, radius={}, rotation={}, large_arc={}, sweep={}, end={}))r2   r   r   r   r   r3   r   )r   paramss     r7   rJ  zArc.__repr__  sL    **dkk4==..$**dhh89 228&&B 	Cr9   c                d   t        |t              sy| j                  |j                  k(  xr | j                  |j                  k(  xrj | j                  |j                  k(  xrO | j
                  |j
                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S rL  )r<   rA   r2   r3   r   r   r   r   rM  s     r7   rO  z
Arc.__eq__  s    %%zzU[[( PTXX-B Pu||+P/P %//1P 7;jjEKK6O	Pr9   c                :    t        |t              st        S | |k(   S r;   )r<   rA   rQ  rM  s     r7   rR  z
Arc.__ne__  s    %%!!5=  r9   c                &	   | j                   j                  }| j                   j                  }||z  }||z  }d| j                  z  | j                  | j
                  z
  z  dz  }|j                  |j                  }}||z  }||z  }	||z  |	|z  z   }
|
dkD  rK| j                  r4|t        |
      z  }|t        |
      z  }|d|z  z   | _         ||z  }||z  }nt        d      ||	z  ||z  z   }||z  |z
  |z  }t        j                  |d      rdn
t        |      }| j                  | j                  k(  r| ||z  |z  d|z  |z  |z  z
  z  }n|||z  |z  d|z  |z  |z  z
  z  }t        d| j                  z        |z  | j                  | j
                  z   dz  z   | _        ||j                  z
  |z  d||j                  z
  z  |z  z   }| |j                  z
  |z  d| |j                  z
  z  |z  z   }t        j                   |j                  dd      dt        j                   |j                  dd      z  z   }t        j                   |j                  dd      dt        j                   |j                  dd      z  z   }|j                  dkD  r$t#        t%        |j                              | _        nR|j                  dk  r%t#        t%        |j                               | _        n|j                  dkD  rd| _        nd| _        |j                  |j                  z  |j                  |j                  z  z
  }|j                  |j                  z  |j                  |j                  z  z   }t        j                   |j                  dd      t        j                   |j                  dd      z   }|dkD  rt#        t%        |            | _        ne|dk  rt#        t%        |             | _        nE|j                  |j                  z  |j                  |j                  z  z   dkD  rd| _        nd| _        | j                  s%| j(                  dk\  r| xj(                  dz  c_        y | j                  r&| j(                  dk  r| xj(                  dz  c_        y y y )	Nr   r*   rM   zNo such elliptic arc exists.r   r      h  )r   r$   r#   rP  r2   r3   r   r	   r   r   r_  r   r   r   rO  r   clipr   acosthetadelta)r   r   r   rx_sqdry_sqdzp1x1py1px1p_sqdy1p_sqdradius_checktmpradicandradicalcpu1u2det_uvacosands                      r7   rQ  zArc._parameterize  s    [[[[BB  4::#89!;88SXXSc'c'
  76>:!$$d<((d<(( 2b5jBB !?@@ Wnvg~-6MC'3.zz(A.!DN>>TZZ'2c6"9r"uSy|34B"S&)beCil23B "TXX+&r)TZZ$((-BA,EE BGGmR"cBGGm"4R"77dRWWnb 2tbgg~#6r#99 WWRWWb!$r"''"''2q*A'AAWWRWWb!$rBGGBGGR,C'CC 77Q; bgg/DJWWq[!$rww-00DJww{

 !
277277?2''"''/BGGBGGO3''',,A.r11MMA: g/DJaZ!$w-00DJwwrww014
 !
zzdjjAoJJ#J^^

aJJ#J !0^r9   c                   | j                   || j                  z  z   t        z  dz  }| j                  j                  }| j                  j
                  }| j                  j                  }| j                  j
                  }||z  t        |      z  ||z  t        |      z  z
  | j                  j                  z   }||z  t        |      z  ||z  t        |      z  z   | j                  j
                  z   }||dz  z   S )NrZ  rM   )
r^  r_  r   rP  r$   r#   r   r
   r   r   )	r   rT   r   cosphisinphir   r   r  r  s	            r7   r   z	Arc.point[  s    a

l*B.s2%%%%[[[[vIc%j 2f9SZ#77$++:J:JJvIc%j 2f9SZ#77$++:J:JJ1R4xr9   c                   d }t        j                  || j                  dd      ryt        j                  || j                  dd      ry| j                  dk7  rt        d      || j                  z
  }t        |j                  |j                  z  |j                  |j                  z  z         }t        | j                  j                  | j                  j                        }t        | j                  j                  | j                  j                        }||k  rt        j                  ||      sy||kD  rt        j                  ||      sy|j                  }|j                  }| j                  | j                  z   }	t        | j                  |	      }
t        | j                  |	      }|| j                  j                  z
  | j                  j                  z  }|dkD  rd}n|dk  rd}t        t!        |            }||
k  r|d	z  }||
k  r||kD  r|d	z  }||kD  rd|z  }||
k  r|d	z  }||
k  r||kD  r|d	z  }||kD  r|| j                  z
  | j                  z  }|| j                  z
  | j                  z  }|| j                  j                  z
  | j                  j                  z  }|dkD  rd}n|dk  rd}t        t#        |            }||
k  r|d	z  }||
k  r||kD  r|d	z  }||kD  rd
|z
  }||
k  r|d	z  }||
k  r||kD  r|d	z  }||kD  r|| j                  z
  | j                  z  }|| j                  z
  | j                  z  }d}t        j                  ||      r	||z   dz  }n^t        j                  ||      r	||z   dz  }n?t        j                  ||      r	||z   dz  }n t        j                  ||      r	||z   dz  }ny|dk\  r|dk  r|S y)zIf the point lies on the Arc, returns its `t` parameter.
        If the point does not lie on the Arc, returns None.
        This function only works on Arcs with rotation == 0.0c                    | |k  xr ||k\  S r;   r   )r   r  vals      r7   in_rangez Arc.point_to_t.<locals>.in_rangel  s    3J0SCZ0r9   r   r  r  r   z0Arc.point_to_t() only works on non-rotated Arcs.Ng      g     v@rZ         @)r   r_  r2   r3   r   r   r   r	   r$   r#   r   r   r  r^  r_  r   r]  asin)r   r   rv  r   distance_from_center
min_radius
max_radiusr  r  	end_angle	min_angle	max_angleacos_arg	x_angle_0	x_angle_1t_x_0t_x_1asin_arg	y_angle_0	y_angle_1t_y_0t_y_1rT   s                          r7   r  zArc.point_to_tg  s   
	1
 ::eTZZc=ZZtxxc===COPPDKK#QVVaff_!&&$IJ))4;;+;+;<
))4;;+;+;<
 :-rzzBVXb7c :-rzzBVXb7c JJJJ JJ+	

I.	

I.	(((DKK,<,<<c>H_HDN+	)#I )#)#I )# 9$	)#I )#)#I )# TZZ'4::5TZZ'4::5(((DKK,<,<<c>H_HDN+	)#I )#)#I )# )O	)#I )#)#I )# TZZ'4::5TZZ'4::5::eU##%AZZu%#%AZZu%#%AZZu%#%A H18Hr9   c                @    d| j                   z  || j                  z
  z  S )a[  Isometry to a centered aligned ellipse.

        This is an isometry that shifts and rotates `self`'s underlying
        ellipse so that it's centered on the origin and has its axes
        aligned with the xy-axes.

        Args:
            z (:obj:`complex` or :obj:`numpy.ndarray[complex]`): a point
                to send through the above-described isometry.

        Returns:
            (:obj:`complex` or :obj:`numpy.ndarray[complex]`) The point(s) f(z),
                where f is the above described isometry of the xy-plane (i.e.
                the one-dimensional complex plane).
        r   rP  r   )r   rw   s     r7   	centerisozArc.centeriso  s       $//!AO44r9   c                :    | j                   |z  | j                  z   S )z(The inverse of the `centeriso()` method.r  )r   zetas     r7   
icenterisozArc.icenteriso  s    t#dkk11r9   c                    | j                  |      }t        |      t        |      }}|| j                  j                  z  d|z  | j                  j                  z  z   S )zASimilar to the `centeriso()` method, but maps to the unit circle.rM   )r  r$   r#   r   )r   rw   r  r  r  s        r7   u1transformzArc.u1transform  sN    ~~a Dz4:1!!!BqD)9)9$999r9   c                    t        |      }t        |      }|| j                  j                   z  || j                  j                  z  z   }| j                  |z  | j                  z   S )z*The inverse of the `u1transform()` method.)r$   r#   r   rP  r   )r   r  r  r  rw   s        r7   iu1transformzArc.iu1transform  sT    JJdkk4;;#3#3!33q 4;;..r9   r   r   c           
     $    d|cxk  rdk  rn J d|cxk  rdk  sJ  J |dk(  r|dk(  rt               } j                   j                  |k7  ri| _        t        r't         fd|||d      d    _         j                  S t	         || j                  |       j                  |      ||d       _         j                  S t        rt         fd|||d      d   S t	         || j                  |       j                  |      ||d      S )a  Computes the length of the Arc segment, `self`, from t0 to t1.

        Notes:
        * The length of an elliptical large_arc segment requires numerical
        integration, and in that case it's simpler to just do a geometric
        approximation, as for cubic bezier curves.
        r   r   c                8    t        j                  |             S r;   r1  r2  s    r7   r   zArc.length.<locals>.<lambda>  s    3ts?S;T r9   r3  r4  c                8    t        j                  |             S r;   r1  r2  s    r7   r   zArc.length.<locals>.<lambda>  s    C(<$= r9   )rD  rN  r7  r   r  r   )r   r:  r*  r  r  hs   `     r7   r!  z
Arc.length  s-    B|!|,,R1,,,,7rQwT
A''/43K3Kq3P+,("*./T/12e4+QQR+TD'
 &&& +9r2tzzRT~9=BPY[\+^D'&&&=r2$D2235 5 "$B

2

2"'A7 7r9   c                $    t        | |||||      S )a8  Approximates the unique `t` such that self.length(0, t) = s.

        Args:
            s (float): A length between 0 and `self.length()`.

        Returns:
             (float) The t, such that self.length(0, t) is approximately s.

        For more info:
            See the inv_arclength() docstring.
        r'  rr  rs  s         r7   rt  zArc.ilength!  s     T1E&'02 	2r9   c                .   |rJ| j                   |j                  k(  xr/ t        | j                  d      |j                  d      z
        |k  S | j                   |j                  k(  xr/ t        | j	                  d      |j	                  d      z
        |k  S r]  r  r  s       r7   rc  zArc.joins_smoothly_with1  r  r9   c                   t        | j                  || j                  z  z         }t        | j                        }| j                  j
                  }| j                  j                  }| j                  t        z  dz  |z  }|dz  dk(  rs|dkD  rn|t        |      z  t        |      z  |t        |      z  t        |      z  z
  d|t        |      z  t        |      z  |t        |      z  t        |      z  z   z  z   S |dz  dk(  rs|| t        |      z  t        |      z  |t        |      z  t        |      z  z
  d| t        |      z  t        |      z  |t        |      z  t        |      z  z   z  z   z  S |dz  dk(  rs|| t        |      z  t        |      z  |t        |      z  t        |      z  z   d| t        |      z  t        |      z  |t        |      z  t        |      z  z
  z  z   z  S |dz  dk(  rq||t        |      z  t        |      z  |t        |      z  t        |      z  z   d|t        |      z  t        |      z  |t        |      z  t        |      z  z
  z  z   z  S t        d      )	r  rZ  r+   r   rM   r   r*   r,   r  )r   r^  r_  r   r   r$   r#   r   r
   r   r   )r   rT   r   r   rO  r   r   r1  s           r7   r   zArc.derivative?  sd   

Qtzz\12dmm$[[[[ZZ]3"q5A:!a%c#h;s5z)Bs3xKE
,BBR3s8CJ&CHSZ)??FA A AUaZrc#c(l3u:-3s8CJ0FFCHSZ'"SX+c%j*@@JB B C CUaZrc#c(l3u:-3s8CJ0FFCHSZ'"SX+c%j*@@JB B C CUaZbSk#e*,r#c({3u:/EE3s8CJ&CHSZ)??IA A B B >??r9   c                @    | j                  |      }|t        |      z  S )zwreturns the unit tangent vector of the segment at t (centered at
        the origin and expressed as a complex number).)r   r   r  s      r7   r   zArc.unit_tangentV  s      q!CI~r9   c                *    d| j                  |      z  S r  r  r  s     r7   r  z
Arc.normal\  r  r9   c                    t        | |      S r  r  r  s     r7   r  zArc.curvature`  r  r9   c                    t        | j                  | j                  | j                  | j                  | j
                   | j                        S )z?returns a copy of the Arc object with its orientation reversed.)rA   r3   r   r   r   r   r2   rE  s    r7   rN   zArc.reversed  s6    488T[[$--zz>4::/ 	/r9   c                    d }| j                   dkD  r ||| j                        }n ||| j                        }|| j                  z
  | j                   z  S )aZ  Converts phase to t-value.

        I.e. given phase, psi, such that -np.pi < psi <= np.pi, approximates
        the unique t-value such that `self.u1transform(self.point(t))` equals
        `np.exp(1j*psi)`.

        Args:
            psi (float): The phase in radians.

        Returns:
            (float): the corresponding t-value.

        c                ^    t        | dt        z  z        }|dz  }||dz  z  }||k  r|dz  }|S )Nr*   r[  )r   r   )radsdomain_lower_limitrx   r1  s       r7   _degzArc.phase2t.<locals>._deg  sD    41R4=)D #c)AAGOD((Kr9   r   )r  )r_  r^  )r   psir  rx   s       r7   phase2tzArc.phase2t  sL    		 ::>

;D

;Dtzz!4::--r9   c           
     ^     j                   dk(  r4t        t              r# j                  j                  } j                  j
                  }t        j                   j                  z
  j                   j                  z
        }|j                         }|d   j                  dk(  rD|d   j                  }|g}d||z  ||z  z  z
  }	|	dk  rg S |	dk(  rdg}
n|t        |	      z  }|| g}
n|d   j
                  |d   j                  z  }| |d   j                  z  |d   j
                  z   }||z  |z  |z  ||z  z   }|||z  z
  }	|	dk  rg S ||z  t        |	      z  }||z  |z  |z   |z   |z  }||z  |z  |z   |z
  |z  }|g}||k7  r|j                  |       ||z  }||z  |z  |z   |z  }||z  |z  |z
  |z  }|g}
||k7  r|
j                  |       g }|D ]c  }|
D ]\  }t        ||       j                  z   } j                  |      }|dk(  r3j                  |      }|dk(  rJ|j                  ||g       ^ e |S t              rt        j                    j#                  j                                     }t	        |      dz  t        |      dz  z   }t%        |dz
        D cg c]  }d|cxk  rdk  sn n| }}|D cg c]"  } j'                  t)         ||                  $ }}t+        ||      D cg c]  \  }}d|cxk  rdk  sn n||f c}}S t        t,              r[ k7  sJ ddl}  j                   dk(  ru j                  j                   j                  j
                  k(  rGj                   dk(  r7j                  j                  j                  j
                  k(  r	 j                  j                  }!j                  j                  }" j                  }#j                  }$t1        |#|$z
        }%g }&|%|!|"z   kD  rn.|%t1        |!|"z
        k  rnt        j2                  |%ddd      r{t        j2                  |!|"dd      rad	 }' |' j                        s9 |' j                        s& |'j                         s |'j                         rg S  j                  j                  k(  r* j4                  j4                  k7  r|&j                  d
        j                  j                  k(  r* j4                  j4                  k(  r|&j                  d        j                  j                  k(  r* j4                  j4                  k(  r|&j                  d        j                  j                  k(  r j4                  j4                  k7  r|&j                  d       nt        j2                  |%|!|"z   dd      rTt        |#|$      }|j7                  |!|%z        }|&j                   j                  |      j                  |      f       nt        j2                  |%t1        |!|"z
        dd      rkt        |#|$      }|!}(|!|"kD  rt        |$|#      }|"}(|j7                  |( |%z        }|&j                   j                  |      j                  |      f       nt9        |!d      t9        |"d      z
  t9        |%d      z   d|%z  z  }t        t9        |!d      t9        |d      z
        })|#||$|#z
  z  |%z  z   }*|*j                  |)|$j
                  |#j
                  z
  z  |%z  z   }+|*j                  |)|$j
                  |#j
                  z
  z  |%z  z
  },|*j
                  |)|$j                  |#j                  z
  z  |%z  z
  }-|*j
                  |)|$j                  |#j                  z
  z  |%z  z   }.t        |+|-      }/t        |,|.      }0|&j                   j                  |/      j                  |/      f       |&j                   j                  |0      j                  |0      f       g }1|&D ]t  }|d   }2|2
|2dk  s|2dkD  r|d   }|
|dk  s|dkD  r't        j2                   j7                  |2      j7                  |      dd      sJ |2|f}3|1j                  |3       v |1S t;         j=                         j=                               }4t?         |4||      }1tA        |1      dkD  r fd}5|1jC                  |5       tE        dtA        |1      dz
        D ]F  }6t1        |1|6   d   |1|6dz      d   z
        t1        |1|6   d   |1d   d   z
        k  s<|1d   |1|6   gc S  |1d   |1d   gS |1S tG        d      c c}w c c}w c c}}w )aB  NOT FULLY IMPLEMENTED.  Finds the intersections of two segments.
        returns a list of tuples (t1, t2) such that
        self.point(t1) == other_seg.point(t2).
        Note: This will fail if the two segments coincide for more than a
        finite collection of points.

        Note: Arc related intersections are only partially supported, i.e. are
        only half-heartedly implemented and not well tested.  Please feel free
        to let me know if you're interested in such a feature -- or even better
        please submit an implementation if you want to code one.r   rA  r   r   Nr*   r  r  c                    |j                  |       }|r2t        j                  |ddd      st        j                  |ddd      ryy)Nr   r  r  r   FT)r  r   r_  )r   r>   rT   s      r7   point_in_seg_interiorz,Arc.intersect.<locals>.point_in_seg_interior]  s=    NN51 ! "

1c$ G "

1c$ G#(#r9   )r   r   )r   r   )r   r   )r   r   rw  r   r
  c                f    | \  }}t        j                  |      j                  |      z
        S r;   r   )tpairr*  r  r  r   s      r7   keyfcnzArc.intersect.<locals>.keyfcn  s-    "FBtzz"~	0CCDDr9   r   r   zHother_seg should be a Arc, Line, QuadraticBezier, or CubicBezier object.)$r   r<   r.   r   r$   r#   r2   r   r3   re   r	   appendr   r  r?   r   rz  r  r"   r  phaseziprA   sysr   r_  r   r   powr  r!  r   r-   sortrZ   r   )7r   r  r  r  rS   rV   r   r   x_valuesdiscriminanty_valuesru  mr  x_sqrtr  x2y_sqrtr  y2r  r  r  my_tother_tu1polyu1poly_mag2rT   t2sr  t1sr*  r  r0r1r  r  r  possible_intersr  little_rr  p2x30x31y30y31p30p31intersself_tr]   r  r  idxs7   ``                                                     r7   r  zArc.intersect  sG	    MMQJy$$?  A  A IOODKK7y}}T[[?XZA AtyyCaDII3  !AEAE?2!#I!Q& !sHd<00C #cT{H& aDII!		)R!A$))^qtyy0:  !1uqy1}Q7*a!e4!#IQl!33A	A&/;>A	A&/;>48OOB'!1uqyF*k91uqyF*k948OOB'M 	:! :A13A??1-Dt| '2215G$ !(($9:	: ! y) YYt//	0@ABFv,/DL!O;K)+/:Ja1kk1JCJ=@Ar4<<fRj 12ACA+.sC=IRALqLRHII	3'$$$ ")9)9T[[=M=M)MT]TfTfjkTkr{  sC  sC  sH  sH  LU  L\  L\  La  La  sa[[%%%%**[[%%RL"$R= R"W% jjACd;"**RQSZ]dhBi$ 2$**iH1$((IF1)//4H1)--F!	 

ioo5DJJ)//<Y'..z:

imm3$**	:W'..z:IOO3$**	:W'..z:IMM1

ioo8U'..z:ZZ274@ 22.A1A#**DOOA,>	@T@TUV@W+XYZZ3rBw<cE 22.A!HBw rr2#%	!,A#**DOOA,>	@T@TUV@W+XY RB4s1c{BsQwOASS\C3K78AqBG}q01B''Q"''BGG*;%<q%@AC''Q"''BGG*;%<q%@AC''Q"''BGG*;%<q%@AC''Q"''BGG*;%<q%@AC!#s+C!#s+C#**DOOC,@)BVBVWZB[+\]#**DOOC,@)BVBVWZB[+\]( %AqTFFSLfslXdGWs]#PX::djj&8)//':RY\cghih)AMM!$%   y/?/?/ABM)$	8E.13@F
 6{QE ' CKM2 3CF3KNVC!G_Q-??@"6#;q>F1IaL#@AB &q	6#;773
 #1Ivbz22M  F G Gg KAIs   1ff'f$f)	f)c                    ddl m}m} t         j                        dk(  rt
        dz  }d}nt         j                        dk(  rd}t
        dz  }ni j                  j                   j                  j                  }} |||z    | j                        z        } |||z   | j                        z        } fd} j                  j                   j                  j                  g} j                  j                   j                  j                  g}	t        dd      D ]  }
 |||
      } |||
      }d|cxk  rdk  r-n n*|j                   j                  |      j                         d|cxk  rdk  sYn \|	j                   j                  |      j                          t        |      }t!        |      t        |      t!        |	      t        |	      fS )zTreturns a bounding box for the segment in the form
        (xmin, xmax, ymin, ymax).r   )atanr   r*   c                j    | t         |z  z   ddt         z  z  z  j                  z
  j                  z  S )Nr[  r*   )r   r^  r_  )angr1  r   s     r7   	angle_invzArc.bbox.<locals>.angle_inv  s0    2a4Z#qt*-

:DJJFFr9   r'   r   )mathr  r   r
   rO  r   r   r   r$   r#   r2   r3   rZ   r  r   r  r   )r   r  r   atan_xatan_yr   r   r  xtremaytremar1  txtyrO   s   `             r7   r  zArc.bbox  sv   & 	#txx=ATFF]aFTF[[%%t{{'7'7BBrE(3txx=01F2b5#dhh-/0F	G **//488==1**//488==1r1 	3A61%B61%BB|!|djjn112B|!|djjn112	3 6{6{CKVc&kAAr9   c                J    | j                  d|      | j                  |d      fS )zZreturns two segments, whose union is this segment and which join
        at self.point(t).r   r   )r  r  s     r7   r8  z	Arc.split  s%     ||Aq!4<<1#555r9   c           
         t        | j                  ||z
  z        dk  rd}nd}t        | j                  |      | j                  | j
                  || j                  | j                  |      | j                        S )r  rZ  r   r   r   )r   r_  rA   r   r   r   r   r   )r   r:  r*  new_large_arcs       r7   r  zArc.cropped	  si     tzz27#$+MM4::b>$++*$**zz"~8M8MO 	Or9   c                    t         )zreturns the tuples (d_min, t_min) and (d_max, t_max) which minimize
        and maximize, respectively, the distance,
        d = |self.point(t)-origin|.)_NotImplemented4ArcExceptionr  s      r7   r  zArc.radialrange	  s    \ +*r9   Nc                    t        | ||      S r  r}   r  s      r7   r  zArc.rotated=	  r  r9   c                    t        | |      S r  r   r  s     r7   r  zArc.translatedD	  r  r9   c                     t        | |||      S r  r   r  s       r7   r  z
Arc.scaledI	  r  r9   c              #  n  K   t        | j                        t        |      z  }t        | j                        }| j                  j
                  }| j                  j                  }| j                  }t        | j                        }| j                  j
                  }| j                  j                  }	t        |      }
t        |      }t        |      D ]]  }||z   }t        |      t        ddt        t        |dz        d      z  z         dz
  z  dz  }t        |      }t        |      }| |
z  |z  ||z  |z  z
  }| |z  |z  ||
z  |z  z   }t        |      }t        |      }|||z  |
z  z   ||z  |z  z
  }|	||z  |z  z   ||z  |
z  z   }||dz  z   }||dz
  k(  r| j                   }| |
z  |z  ||z  |z  z
  }| |z  |z  ||
z  |z  z   }|j
                  ||z  z   |j                  ||z  z   dz  z   }|j
                  ||z  z
  |j                  ||z  z
  dz  z   }t#        ||||       |}|}` yw)	z.Generates cubic curves to approximate this arcr+   r,   rw  r*   r         @rM   N)r   r_  floatr^  r   r$   r#   r2   r   r   r
   r   rZ   r	   r  r   r3   r/   )r   curvesslice_t	current_tr   r   p_startr^  r  r  	cos_theta	sin_thetar]   next_talphacos_start_tsin_start_t	ePrimen1x	ePrimen1y	cos_end_t	sin_end_tp2En2xp2En2yp_end	ePrimen2x	ePrimen2yp_c1p_c2s                               r7   as_cubic_curveszArc.as_cubic_curvesM	  sZ    $**%f5DJJ'	[[[[**&[[[[J	J	v 	A(FLDQS'S5I11M-M)M$NQR$RSVYYEi.Ki.Ki+5Y8TTIi+5Y8TTIFIFI"y.944rI~	7QQF"y.944rI~	7QQFVb[(EFQJi)3b9ny6PPIi)3b9ny6PPILL59#44PYHY9Y]_8__DJJ!22uzzEIDU7UY[6[[DgtT599GI9	s   H3H5c              #  `  K   t        | j                        t        |      z  }t        | j                        }| j                  j
                  }| j                  j                  }| j                  }t        | j                        }| j                  j
                  }| j                  j                  }	t        |      }
t        |      }t        |      D ]  }||z   }||z   dz  }t        |      }t        |      }|||z  |
z  z   ||z  |z  z
  }|	||z  |z  z   ||z  |
z  z   }||dz  z   }||dz
  k(  r| j                  }t        |      }t        |      }dt        |      z
  dz  }||||z  |
z  ||z  |z  z
  z  z   }|	|||z  |z  ||z  |
z  z   z  z   }t        |||dz  z   |       |}|} yw)z2Generates quadratic curves to approximate this arcr*   rM   r   g      @r  N)r   r_  r  r^  r   r$   r#   r2   r   r   r
   r   rZ   r3   r0   )r   r  r  r  r  rS   r  r^  cxcyr  r  r]   r  mid_tr  r  r  r  r  	cos_mid_t	sin_mid_tr  pxpys                            r7   as_quad_curveszArc.as_quad_curvesz	  s    $**%f5DJJ'	KKKK**&[[[[J	J	v 	A(Fi'1,EFIFI!i-)33a)mi6OOF!i-)33a)mi6OOFVb[(EFQJE
IE
I3w<'3.Eeq9}y81y=9;TTUUBeq9}y81y=9;TTUUB!'2R<??GI#	s   F,F.r  )r  z3tuple[complex, complex, float, bool, bool, complex]r  r  r  r  r  r;   r  ))r  r  r  rB  rS  rF  rJ  rO  rR  rQ  r   r  r  r  r  r  rI  rJ  r!  r  r  r  r  rt  rc  r   r   r  r  rN   r  r  r  r8  r  r  r  r  r  r  r  r   r9   r7   rA   rA   w  s    "&_B\$CP!
fP
xt5$2:/ a|?O 7:  -^#/@2  BG"#J@.(*R/
.>^G@	.B`6
	O.+`1#
8+Z!r9   rA   c                     e Zd ZdZdZdZdZdZdZdZ	d Z
d8dZd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd ZeefdZd ZddeefdZeeeefdZ d Z!d Z"d Z#d Z$d Z%e&e'fd       Z(e(jR                  d        Z(e&d        Z*e*jR                  d        Z*e&d         Z+e+jR                  d!        Z+d9d"Z,d:d#Z-d$ Z.d% Z/d;d&Z0d' Z1d( Z2d) Z3d<d*Z4d=d+Z5d, Z6d- Z7d:d.Z8d>d/Z9d0 Z:d?d1Z;d2 Z<d@d3Z=d@d4Z>d5 Z?d6 Z@dAd7ZAy)BrD   z%A Path is a sequence of path segmentsFNc                   d | _         d | _        d|v r
|d   | _        t        |      dk\  rit	        |d   t
              rEt        |      dk\  r|d   }nd|v r|d   }nd}t               | _        | j                  |d   |       n t        |      | _        nt               | _        | j                  r=| j                  d   j                  | _
        | j                  d   j                  | _        nd | _
        d | _        d|v r|d   | _        y y )	Nclosedr   r   r*   current_posr  r   tree_element)_length_lengthsr  r-   r<   strlist	_segments_parse_pathr2   _startr3   _end_tree_element)r   segmentskwr  s       r7   rB  zPath.__init__	  s    r>X,DKx=A(1+s+x=A%"*1+K"b("$]"3K"$K!%  !k:!%h!VDN>>..+11DKr*..DIDKDIR!#N!3D  r9   c                x    d t        fd| j                  D              }t        || j                  fz         S )Nc                b    t        | t              r| j                         S | j                         S r;   )r<   rA   rS  r1   )segments    r7   	_pointifyz Path.__hash__.<locals>._pointify	  s$    (27C(@7??$WgooFWWr9   c              3  <   K   | ]  } |      D ]  }|   y wr;   r   ).0r  r  r  s      r7   	<genexpr>z Path.__hash__.<locals>.<genexpr>	  s"     P'Yw=OPAPAPs   )tupler  rD  _closed)r   ptsr  s     @r7   rF  zPath.__hash__	  s5    	X PT^^PPC4<</)**r9   c                     | j                   |   S r;   )r  r   indexs     r7   rW  zPath.__getitem__	  s    ~~e$$r9   c                    || j                   |<   d | _        | j                   d   j                  | _        | j                   d   j                  | _        y Nr   r   )r  r	  r2   r  r3   r  r   r   values      r7   __setitem__zPath.__setitem__	  sC     %unnQ'--NN2&**	r9   c                    | j                   |= d | _        t        | j                         dkD  r=| j                   d   j                  | _        | j                   d   j
                  | _        y d | _        d | _        y r"  )r  r	  r-   r2   r  r3   r  r  s     r7   __delitem__zPath.__delitem__	  s`    NN5!t~~"..+11DKr*..DIDKDIr9   c                6    | j                   j                         S r;   )r  __iter__rE  s    r7   r)  zPath.__iter__	  s    ~~&&((r9   c                8    | j                   j                  |      S r;   )r  __contains__)r   r  s     r7   r+  zPath.__contains__	  s    ~~**1--r9   c                    | j                   j                  ||       d | _        | j                   d   j                  | _        | j                   d   j
                  | _        y r"  )r  insertr	  r2   r  r3   r  r#  s      r7   r-  zPath.insert	  sI    eU+nnQ'--NN2&**	r9   c                v    | D cg c]  }|j                          }}|j                          t        | S c c}w )z@returns a copy of the Path object with its orientation reversed.)rN   reverserD   )r   r>   newpaths      r7   rN   zPath.reversed	  s4    -12c3<<>22W~ 3s   6c                ,    t        | j                        S r;   )r-   r  rE  s    r7   rZ  zPath.__len__	  s    4>>""r9   c                d    dj                  dj                  d | j                  D                    S )NzPath({})z,
     c              3  2   K   | ]  }t        |        y wr;   )repr)r  r  s     r7   r  z Path.__repr__.<locals>.<genexpr>	  s     <DG<s   )r   joinr  rE  s    r7   rJ  zPath.__repr__	  s+      OO<T^^<<> 	>r9   c                    t        |t              syt        |       t        |      k7  ryt        | j                  |j                        D ]  \  }}||k(  r y y)NFT)r<   rD   r-   r  r  )r   rN  r-  os       r7   rO  zPath.__eq__	  sS    %&t9E
"8 	DAq6	 r9   c                :    t        |t              st        S | |k(   S r;   )r<   rD   rQ  rM  s     r7   rR  zPath.__ne__
  rS  r9   c                   | j                   y | j                  D cg c]  }|j                  ||       }}t        |      | _         | j                   dk(  r|| _        y |D cg c]  }|| j                   z   c}| _        y c c}w c c}w )Nr&  r   )r	  r  r!  sumr
  )r   r  r  eachlengthss        r7   _calc_lengthszPath._calc_lengths	
  s    <<# >>#T4;;Ui;@ # #7|<<1#DM=DETTDLL0EDM# Fs   B#Bc                   t        | j                        dk(  rt        d      |dk(  r| j                  d   j                  |      S |dk(  r| j                  d   j                  |      S | j	                          d}t        | j                        D ]<  \  }}|| j                  |   z   }||k\  r||z
  ||z
  z  }|j                  |      c S |}> t        dj                  ||             )Nr   zThis path contains no segments!r   r   r   zGSomething has gone wrong.  Could not compute Path.point({}) for path {})	r-   r  r   r   r=  rn   r
  RuntimeErrorr   )r   possegment_startr   r  segment_endsegment_poss          r7   r   z
Path.point
  s     t~~!#>??#:>>!$**3//#:>>"%++C00'7 	(NE7'$--*>>Kc!"]2-/1}}[11'M	( dkkloquvwwr9   r   r   c                     j                  ||       |dk(  r|dk(  r j                  S t               dk(  r d   j                  ||      S  j	                  |      \  }} j	                  |      \  }}||k(  r |   j                  ||      S  |   j                  |      t         fdt        |dz   |      D              z    |   j                  |      z   S )Nr&  r   r   )r:  r*  )r:  c              3  D   K   | ]  }|   j                           y wr;   )r!  )r  r  r   s     r7   r  zPath.length.<locals>.<genexpr>8
  s     LsS	((*Ls    )r*  )r=  r	  r-   r!  T2tr:  rZ   )	r   T0T1r  r  idx0r:  idx1r*  s	   `        r7   r!  zPath.length,
  s    )<7rQw<<4yA~Aw~~~33xx|HD"xx|HD"t|Dz((B2(66J%%%,LeD1Hd6KLLMJ%%%,- .r9   c                $    t        | |||||      S rq  rr  rs  s         r7   rt  zPath.ilength;
  ru  r9   c                V     t         fdt        t               dz
        D              S )zLChecks if a path is continuous with respect to its
        parameterization.c              3  b   K   | ]&  }|   j                   |d z      j                  k(   ( yw)r   Nrg  )r  r]   r   s     r7   r  z$Path.iscontinuous.<locals>.<genexpr>E
  s*     Pa47;;$qs)//1Ps   ,/r   )rE   rZ   r-   rE  s   `r7   iscontinuouszPath.iscontinuousB
  s#     P5TQ;OPPPr9   c           	     .   g }d}t        t        |       dz
        D ]S  }| |   j                  | |dz   t        |       z     j                  k7  s2|j	                  t        | ||dz            |dz   }U |j	                  t        | |t        |                |S )a	  Breaks self into its continuous components, returning a list of
        continuous subpaths.
        I.e.
        (all(subpath.iscontinuous() for subpath in self.continuous_subpaths())
         and self == concatpaths(self.continuous_subpaths()))
        )
        r   r   )rZ   r-   r3   r2   r  rD   )r   subpathssubpath_startr]   s       r7   continuous_subpathszPath.continuous_subpathsG
  s     s4y1}% 	$AAw{{dAaC3t9#45;;;d=!A#&> ?@ !!	$ 	d=#d)<=>r9   c                x    t        |       dk7  sJ | j                         sJ | j                  | j                  k(  S )z7This function determines if a connected path is closed.r   )r-   rN  r2   r3   rE  s    r7   r  zPath.isclosedX
  s7    4yA~~  """zzTXX%%r9   c                T    t        |       dk7  sJ | j                  | j                  k(  S Nr   )r-   r2   r3   rE  s    r7   
isclosedaczPath.isclosedac^
  s%    4yA~~zzTXX%%r9   c                r    	 | d   j                   }| D ]  }|j                  |k(  s y y# t        $ r Y yw xY w)Nr   TF)r3   
IndexErrorr2   )r   r3   r  s      r7   _is_closablezPath._is_closableb
  sM    	r(,,C  	G}}#	   		s   * 	66c                \    d}|rt        |       | j                  xr | j                         S )zThe closed attribute is deprecated, please use the isclosed()
        method instead.  See _closed_warning for more information.zThis attribute is deprecated, consider using isclosed() method instead.

This attribute is kept for compatibility with scripts created using svg.path (v2.0). You can prevent this warning in the future by setting CLOSED_WARNING_ON=False.)r   r  rY  )r   r  r   s      r7   r  zPath.closedl
  s-    *
 I||3 1 1 33r9   c                b    t        |      }|r| j                         st        d      || _        y )Nz+End does not coincide with a segment start.)rM  rY  r   r  )r   r$  s     r7   r  zPath.closedy
  s,    U**,JKKr9   c                    | j                   s6t        | j                        dkD  r| j                  d   j                  | _         | j                   S rU  r  r-   r  r2   rE  s    r7   r2   z
Path.start
  s9    {{s4>>214..+11DK{{r9   c                l    || _         t        | j                        dkD  r|| j                  d   _        y y rU  r]  r   r  s     r7   r2   z
Path.start
  s0    t~~q &(DNN1# !r9   c                    | j                   s6t        | j                        dkD  r| j                  d   j                  | _         | j                   S r"  r  r-   r  r3   rE  s    r7   r3   zPath.end
  s9    yyS02r*..DIyyr9   c                l    || _         t        | j                        dkD  r|| j                  d   _        y y r"  ra  r_  s     r7   r3   zPath.end
  s0    	t~~q %'DNN2" !r9   c                ,	   t        |       dk(  ry|r0| j                         xr | j                         }|r| dd }n| dd }nd}| dd }d}g }d}| d   j                  }	|D ]  }
|
j                  }||k7  s	|rJ||	k(  rE|rC|r
|||z
  n|}n|}|j                  dj                  |j                  |j                               t        |
t              rU|r|
j                  |z
  }n|
j                  }|j                  dj                  |j                  |j                               n't        |
t              rT|r|
j                  |d      r|r|
j                  |z
  }|
j                  |z
  }n|
j                  }|
j                  }|j                  |j                  |j                  |j                  f}|j                   d	j                  |        nz|r.|
j                  |z
  }|
j                  |z
  }|
j                  |z
  }n$|
j                  }|
j                  }|
j                  }|j                  |j                  |j                  |j                  |j                  |j                  f}|j                   d
j                  |        nt        |
t              r|ri|
j                  |d      rV|r|
j                  |z
  }n|
j                  }|j                  |j                  f}|j                   dj                  |        nG|r|
j                   |z
  }|
j                  |z
  }n|
j                   }|
j                  }|j                  |j                  |j                  |j                  f}|j                   dj                  |        nt        |
t"              r|r|
j                  |z
  }n|
j                  }|
j$                  j                  |
j$                  j                  |
j&                  t)        |
j*                        t)        |
j,                        |j                  |j                  f}|j                   dj                  |        |
j                  }|
} |r|j                  d       dj/                  |      }|s|S |j1                         S )zReturns a path d-string for the path object.
        For an explanation of useSandT and use_closed_attrib, see the
        compatibility notes in the README.r    Nr   FzM {},{}zL {},{})r  zS {},{} {},{}zC {},{} {},{} {},{}zT {},{}zQ {},{} {},{}zA {},{} {} {:d},{:d} {},{}Z )r-   rN  r  r3   r2   r  r   r$   r#   r<   r.   r/   r  r5   r4   r0   r6   rA   r   r   r  r   r   r5  lower)r   useSandTuse_closed_attribrelself_closedr  r  partsprevious_segmentr3   r  	seg_start
_seg_start_seg_end_seg_control2args_seg_control1_seg_controlr-  s                      r7   r  zPath.d
  s    t9>++-A$--/K97KAwH2hll J	'GI i' Y#%5:K<G<S[!8YbJ!*JY--joozOP'4(&{{Y6H&{{HY--hmmX]]KLG[1 6 67GBG !7 !I(/(8(89(D#*;;#:(/(8(8#*;;)..0B0B$MM8==:DLL!7!7!7!>?(/(8(89(D(/(8(89(D#*;;#:(/(8(8(/(8(8#*;;)..0B0B)..0B0B$MM8==:D LL!=!6!=!=t!DEG_5 6 67GBG !7 !I#*;;#:#*;;#==(--7DLL!1!1!14!89'.'B#*;;#:'.#*;;(--|/@/@$MM8==:DLL!7!7!7!>?GS)&{{Y6H&{{H++W^^-@-@((W->->)?GMM*8==(--I @9@@$GH!++K&UJ	'X LLHHUOq**r9   c                
   |rA| d   j                   |j                  k(  xr# | j                  d      |j                  d      k(  S | d   j                   |j                  k(  xr# | j                  d      |j                  d      k(  S )aP  Checks if this Path object joins smoothly with previous
        path/segment.  By default, this only checks that this Path starts
        moving (at t=0) in the same direction (and from the same positive) as
        previous stopped moving (at t=1).  To check if the tangent magnitudes
        also match, set wrt_parameterization=True.r   r   )r2   r3   r   r   r`  s      r7   rc  zPath.joins_smoothly_with
  s      7==HLL0 -T__6))!,6- - 7==HLL0 /T5F5F6++A.6/ /r9   c                    |dk(  rt        |       dz
  dfS |dk(  ry| j                          d}t        | j                        D ]  \  }}||z   }||k\  r||z
  |z  }||fc S |}! d|cxk  rdk  sJ  J t        )zreturns the segment index, `seg_idx`, and segment parameter, `t`,
        corresponding to the path parameter `T`.  In other words, this is the
        inverse of the `Path.t2T()` method.r   r   )r   r   )r-   r=  rn   r
  r   )r   r   rG  seg_idx
seg_lengthrH  rT   s          r7   rF  zPath.T2t  s     6t9Q;>!6#,T]]#; 	GZjBQwVZ'z!B	 A{{{{r9   c                0   | j                          t        |t              r|}n	 | j                  |      }t        | j                  d|       }|| j                  |   z   }||z
  |z  |z   }|S # t        $ r t        |      st        |t              sJ  w xY w)a  returns the path parameter T which corresponds to the segment
        parameter t.  In other words, for any Path object, path, and any
        segment in path, seg,  T(t) = path.t2T(seg, t) is the unique
        reparameterization such that path.point(T(t)) == seg.point(t) for all
        0 <= t <= 1.
        Input Note: seg can be a segment in the Path object or its
        corresponding index.N)r=  r<   r  r   r   rB   r:  r
  )r   r>   rT   rw  rA  rB  r   s          r7   r,  zPath.t2T"  s     	c3G**S/
 DMM(734#dmmG&<<=(!+m;  &s+z#s/CCCs   A- -(Bc                    | j                  |      \  }}| j                  |   }|j                  ||      |j                         |z  z  S )a  returns the tangent vector of the Path at T (centered at the origin
        and expressed as a complex number).
        Note: Bezier curves can have points where their derivative vanishes.
        If you are interested in the tangent direction, use unit_tangent()
        method instead.r   )rF  r  r   r!  )r   r   r   rw  rT   r>   s         r7   r   zPath.derivative:  sE     XXa[
nnW%~~a1~%cjjlAo55r9   c                f    | j                  |      \  }}| j                  |   j                  |      S )a  returns the unit tangent vector of the Path at T (centered at the
        origin and expressed as a complex number).  If the tangent vector's
        magnitude is zero, this method will find the limit of
        self.derivative(tau)/abs(self.derivative(tau)) as tau approaches T.)rF  r  r   )r   r   rw  rT   s       r7   r   zPath.unit_tangentD  s/    
 XXa[
~~g&33A66r9   c                *    d| j                  |      z  S r  r  r  s     r7   r  zPath.normalL  r  r9   c                   | j                  |      \  }}| |   }t        j                  |d      rb|dk7  s| j                  | j                  k(  rD| j
                  |dz
  t        | j
                        z     }|j                  |      st        d      S t        j                  |d      rn|t        |       dz
  k7  s| j                  | j                  k(  rD| j
                  |dz   t        | j
                        z     }|j                  |      st        d      S | j                  |      }| j                  |d      }|j                  |j                  }
}	|j                  |j                  }}t        |	|z  |
|z  z
        |	|	z  |
|
z  z   dz  z  S )zkreturns the curvature of this Path object at T and outputs
        float('inf') if not differentiable at T.r   r   infr*   r   g      ?)rF  r   r_  r3   r2   r  r-   rc  r  r   r$   r#   r   )r   r   rw  rT   r>   previous_seg_in_pathnext_seg_in_pathr   r   r   r   r   r   s                r7   r  zPath.curvatureP  sV    XXa[
7m::aA4::1E#'>>1DNN 33$5 **+?@U|#ZZ17c$i!m#;#'88tzz#9#~~1DNN 33 5#77<U|#__Qooa1o%"''B88SXXS2c6BsF?#RURU]S$888r9   c                    d }fd}| j                         sJ g }| D ]/  }t        |t              r| ||      z  }|j                  |       1  |t	        |       S )at  Find area enclosed by path.
        
        Approximates any Arc segments in the Path with lines
        approximately `chord_length` long, and returns the area enclosed
        by the approximated Path.  Default chord length is 0.01.  If Arc
        segments are included in path, to ensure accurate results, make
        sure this `chord_length` is set to a reasonable value (e.g. by
        checking curvature).
                
        Notes
        -----
        * Negative area results from clockwise (as opposed to
        counter-clockwise) parameterization of the input Path.
        
        To Contributors
        ---------------
        This is one of many parts of `svgpathtools` that could be 
        improved by a noble soul implementing a piecewise-linear 
        approximation scheme for paths (one with controls to guarantee a
        desired accuracy).
        c                    d}| D ]k  }t        |j                               }t        |j                               j                         }||z  }|j	                         }| |d       |d      z
  z  }m |S )Nr   r   )r$   re   r#   r   integ)rG   area_enclosedr>   r  r   	integrandintegrals          r7   area_without_arcsz$Path.area.<locals>.area_without_arcs  ss    M ;$#((*%++-bD	$??,!x{!::; ! r9   c           	     &   t        t        | j                         z              }t        j                  dd|dz         D cg c]  }| j                  |       }}t        |      D cg c]  }t        ||   ||dz             c}S c c}w c c}w )z-Find piecewise-linear approximation of `seg`.r   r   )r  r   r!  r   linspacer   rZ   r.   )seg_	num_linesrT   r  r]   chord_lengths        r7   	seg2lineszPath.area.<locals>.seg2lines  s{    D!=>?I*,++aIaK*HIQ4::a=ICI49)4DEqDQQqS*EE JEs   B	*B)r  r<   rA   r  rD   )r   r  r  r  bezier_path_approximationr>   s    `    r7   areaz	Path.areap  sm    .	!	F }}$&! 	6C#s#)Ys^;))005		6
 !'@!ABBr9   c           	        | }t        |t              r|n
t        |      }||k7  sJ g }|D ]n  }|D ]g  }|r|r	|d   c c S |j                  ||      D ]B  \  }	}
|j                  ||	      }|j                  ||
      }|j	                  |||	f|||
ff       D i p |r|r|d   S |rt        t        |       d   D cg c]  \  }}}|j                  |       }}}}g }t        t        |            D ]H  }t        |dz   t        |            D ]+  }t        ||   ||   z
        |k  s|j	                  |       - J t        |      D cg c]  \  }}||vr| }}}|S c c}}}w c c}}w )aT  Finds intersections of `self` with `other_curve`

        Args:
            other_curve: the path or path segment to check for intersections
                with `self`
            justonemode (bool): if true, returns only the first
                intersection found.
            tol (float): A tolerance used to check for redundant intersections
                (see comment above the code block where tol is used).

        Returns:
            (list[tuple[float, Curve, float]]): list of intersections, each
                in the format ((T1, seg1, t1), (T2, seg2, t2)), where
                self.point(T1) == seg1.point(t1) == seg2.point(t2) == other_curve.point(T2)

        Scope:
            If the two path objects coincide for more than a finite set of
            points, this code will iterate to max depth and/or raise an error.
        r   )r  r   )r<   rD   r  r,  r  r  r  r   rZ   r-   r   rn   )r   other_curvejustonemoder  path1path2intersection_listseg1seg2r*  r  rH  T2_T1_seg1_t1r  indices2removeind1ind2indinters                         r7   r  zPath.intersect  s   ( )+t<${BS~~ 	OD O#4,Q//"nnTsn; OFB4,B4,B%,,r4nr4n-MNOO	O ,$Q'' ;?EV@W;XYZ;[\\UC5;;s#\C\Nc#h 4!$(CH5 4D3t9s4y01C7&--d344 "++<!=!<:3!$N!: "' !< !< !  ]!<s   ?E#E*c                    | j                   D cg c]  }|j                          }}t        t        |       \  }}}}t	        |      }t        |      }t	        |      }	t        |      }
|||	|
fS c c}w )z:returns bounding box in the form (xmin, xmax, ymin, ymax).)r  r  r  r  r   r  )r   r>   bbsxminsxmaxsyminsymaxsrO   rP   rQ   rR   s              r7   r  z	Path.bbox  sm    %)^^4csxxz44%)#s)_"ueU5z5z5z5zT4%% 5s   A0c                   d|cxk  rdk  rn J d|cxk  rdk  sJ  J ||k7  sJ |dk(  r|dk(  rJ |dk(  r0d|cxk  rdk  r%n n"| j                         r| j                  d|      S |dk(  r| d   }d}t        |       dz
  }nh| j                  |      \  }}| |   }t	        j
                  |d      r(| j                  |      dz
  t        |       z  }| |   }d}n| j                  |      }|dk(  r
| d   }d}d}	nh| j                  |      \  }
}| |
   }t	        j
                  |d      r(| j                  |      dz   t        |       z  }	| |	   }d}n| j                  |      }	||k  r"|	|k(  rt        |j                  ||            }|S t        |j                  |d            }||k  rr| j                         st        d      t        |	dz   t        |             D ]  }|j                  | |           t        d|      D ]  }|j                  | |           n(t        |	dz   |      D ]  }|j                  | |           |dk7  r!|j                  |j                  d|             |S )z#returns a cropped copy of the path.r   r   r   z6This path is not closed, thus T0 must be less than T1.)r  r  r-   rF  r   r_  r   rD   r   rZ   r  )r   rG  rH  r  t_seg1i1seg1_idxseg0t_seg0i0seg0_idxnew_pathr]   s                r7   r  zPath.cropped  s{   B|!|++R!++++Rxx!Ga((7q2zzdmmo<<2&&78DFTQB#xx|Hf>Dzz&!$jj&*c$i7BxZZ%77DFB#xx|Hf>Dzz&!$jj&*c$i7BxZZ%7rRxDLL89H, ) DLL34H Bw}}$ &8 9 9 #263t95 1 Q01"1b\ 1 Q01
 rAvr* -AOODG,- {Q 78r9   c                    |rt         t        j                  ddf}d}t        |       D ]<  \  }}|j	                  |      \  }}|d   |d   k  r||fz   }|d   |d   kD  s7||fz   }> ||fS )zreturns the tuples (d_min, t_min, idx_min), (d_max, t_max, idx_max)
        which minimize and maximize, respectively, the distance
        d = |self[idx].point(t)-origin|.N)r   NNr   )r   r   r~  rn   r  )	r   ry   r  
global_min
global_maxrw  r>   r  r  s	            r7   r  zPath.radialrange  s     %%%&&$-J(J )$ =141H.!!$z!}4!/7*!<J!!$z!}4!/7*!<J= z))r9   c                    t        | ||      S r  r}   r  s      r7   r  zPath.rotated/  r  r9   c                    t        | |      S r  r   r  s     r7   r  zPath.translated6  r  r9   c                     t        | |||      S r  r   r  s       r7   r  zPath.scaled;  r  r9   c                |   t        |t              sJ |j                         sJ | |k7  sJ | j                  |d      ry| j	                  d      }|j                         \  }}}}||j                  cxk  xr |k  nc xr ||j                  cxk  xr |k  nc }|syt        |dz
  |dz
        }t        |||      S )z@Returns true if the path is fully contained in other closed pathT)r  Fr   r   )
r<   rD   r  r  r   r  r$   r#   r   r  )	r   rN  r  rO   rP   rQ   rR   
pt_in_bboxr  s	            r7   is_contained_byzPath.is_contained_by?  s    %&&&~~u}}>>%T>2ZZ]!&dD$bgg--LDBGG4Kt4K
d1fd1f%C//r9   c                .   t         dz  }t        ||z        }t        t        |       dz
  dd      D ]b  }| |   }t	        |t
              st        t        t        |j                        |z              }t        |j                  |            | ||dz    d y)z\
        Iterates through this path and replaces any Arcs with cubic bezier curves.
        r*   r   r   N)r   r   rZ   r-   r<   rA   r  r   r   r_  r  r  r   r  r   sweep_limitr-  r  arc_requireds          r7   approximate_arcs_with_cubicsz!Path.approximate_arcs_with_cubicsR  s     1fcEk*s4y{B+ 	FA1gGgs+tC$6$DEFLw66|DED1Q3K	Fr9   c                .   t         dz  }t        ||z        }t        t        |       dz
  dd      D ]b  }| |   }t	        |t
              st        t        t        |j                        |z              }t        |j                  |            | ||dz    d y)z`
        Iterates through this path and replaces any Arcs with quadratic bezier curves.
        r*   r   r   N)r   r   rZ   r-   r<   rA   r  r   r   r_  r  r  r  s          r7   approximate_arcs_with_quadsz Path.approximate_arcs_with_quads_  s     1fcEk*s4y{B+ 	EA1gGgs+tC$6$DEFLw55lCDD1Q3K	Er9   c                N    t        |       \  }}t        |d       t        ||      S )zreturns generator of segment joints 
        
        I.e. Path(s0, s1, s2, ..., sn).joints() returns generator 
            (s0, s1), (s1, s2), ..., (sn, s0)

        credit: https://docs.python.org/3/library/itertools.html#recipes
        N)r   nextr  )r   r  rS   s      r7   ro   zPath.jointsl  s&     4y1Q1ayr9   c              #     K   t         j                  |      D ],  }|t        v r| t        j	                  |      D ]  }|  . y wr;   )
COMMAND_REr8  COMMANDSFLOAT_REfindall)r   pathdefr  tokens       r7   _tokenize_pathzPath._tokenize_pathx  sK     !!'* 	AH}!))!, 	s   AAc           
        t        | j                  |            }|j                          | j                  }d }d }|r|d   t        v r+|}|j                         }|t        v }	|j                         }n8|4t        d|dt        |j                               t        |      z
        |}|dk(  rJ|j                         }
|j                         }t        |
      t        |      dz  z   }	r|}n||z  }|}d}nY|dk(  r-||k(  s|j                  t        ||             d| _        |}d }n'|dk(  r`|j                         }
|j                         }t        |
      t        |      dz  z   }	s||z  }|j                  t        ||             |}n|d	k(  r[|j                         }
t        |
      |j                  dz  z   }	s||j                   z  }|j                  t        ||             |}nb|d
k(  r^|j                         }|j                   t        |      dz  z   }	s||j                  dz  z  }|j                  t        ||             |}n|dk(  rt        |j                               t        |j                               dz  z   }t        |j                               t        |j                               dz  z   }t        |j                               t        |j                               dz  z   }	s||z  }||z  }||z  }|j                  t#        ||||             |}n&|dk(  r|dvr|}n||z   |d   j$                  z
  }t        |j                               t        |j                               dz  z   }t        |j                               t        |j                               dz  z   }	s
||z  }||z  }|j                  t#        ||||             |}nl|dk(  rt        |j                               t        |j                               dz  z   }t        |j                               t        |j                               dz  z   }	s
||z  }||z  }|j                  t'        |||             |}n|dk(  ry|dvr|}n||z   |d   j(                  z
  }t        |j                               t        |j                               dz  z   }	s||z  }|j                  t'        |||             |}nQ|dk(  rKt        |j                               t        |j                               dz  z   }t        |j                               }t        |j                               }t        |j                               }t        |j                               t        |j                               dz  z   }	s||z  }|j                   dk(  s|j                  dk(  rNt+        dj-                  ||||||      dj-                  ||      z          |j                  t        ||             n|j                  t/        ||||||             |}|r|S )Nr   zUnallowed implicit command in z, position MrM   Lre  THVCSCSr   r   QTAr   zyReplacing degenerate (zero radius) Arc with a Line: Arc(start={}, radius={}, rotation={}, large_arc={}, sweep={}, end={})z --> Line(start={}, end={}))r  r  r/  r  r  pop	UPPERCASEupperr   r-   r8  r  r  r.   r  r#   r$   r/   r5   r0   r6   r   r   rA   )r   r  r  r  elementsr  	start_poscommandlast_commandabsoluter  r  r@  r4   r5   r3   r6   r   r   arcr   s                        r7   r  zPath._parse_path  s   
 ++G45>>	|x'&",,."i/!--/ ?$W]]_!5H!E&G H H&#~LLNLLNAhqB."%K3&K
 (	
 C#y0OODi$@A#'CLLNLLNAhqB.;&C[# 67!CLLNAh!1!1B!66;+++C[# 67!CLLN!&&qB6;++b00C[# 67!C 053H23MM 053H23MMHLLN+eHLLN.Cb.HH+H+H;&CK8S QR!C  t+  +H
  +[88B<;P;PPH 053H23MMHLLN+eHLLN.Cb.HH+H;&CK8S QR!C/%2G"2LLHLLN+eHLLN.Cb.HH{*G;&CWc JK!C  t+ *G
 *K7(2,:N:NNGHLLN+eHLLN.Cb.HH;&CWc JK!Cx||~.x||~1F1KK 0HLLN+hlln-HLLN+eHLLN.Cb.HH;&C;;!#v{{a'7  --3V#VXsE3.H"F;45 6 OODc$:;OOK3sKM!M P r9   r  )FFFr  r  )r   )Fr(   r;   r  )g?)r  N)Br  r  r  __doc__r  r  r  elementr   metarB  rF  rW  r%  r'  r)  r+  r-  rN   rZ  rJ  rO  rR  rI  rJ  r=  r   r!  r  r  r  r  rt  rN  rR  r  rV  rY  propertyCLOSED_WARNING_ONr  setterr2   r3   r  rc  rF  r,  r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  ro   r  r  r   r9   r7   rD   rD   	  s   / GFDGID4:+%+).+#>!
 #/:J 
Fx. a|?O .  -^#/@2Q
"&&  1 
4 
4 ]]   
 \\) )
  
 	ZZ( (
e+N/,067(9@/Cb4!l&;z*"1#
80&FE
vr9   rD   r  )TFr;   r  )ir  
__future__r   recollections.abcr   ImportErrorcollectionswarningsr   operatorr   numpyr   	itertoolsr   	functoolsr   r	   r
   r   r   r   r]  r   rx  r   r   r   r   r   r   r   r   r  r   scipy.integrater   r7  bezierr   r   r   r   r   r   	misctoolsr   	polytoolsr    r!   r"   r#   r$   
basestringr  	NameErrorsetr  r  compiler  r  rJ  rI  USE_SCIPY_QUADr  r  r  r  r  r   r  r  r8   r?   rB   rH   rK   rW   r^   r`   rc   rg   rl   rt   r~   r   r   r   r   r   r	  r  r  r  r  r+  r9  objectr.   r0   r/   rA   rD   r   r9   r7   <module>r     s  
 # 	,/     $ $ $ $ ; ;$O
( ( $ I I	
C
 %&	RZZ34
2::AB
      IJ  )*:HB240)':"#H<H$-H`9Hx#L!H.0#	#	 &1A* #0%1BA=L.F86 F8RI8f I8XF8& F8Rd& dN!W? WiL  ,++,"O  		s/   E& E8 F &E54E58E?F
F