
    9i              	           S SK rS SKJr  S rSS/SS/4SS/SS/4/ SQ/ SQ4/ SQ/ S	Q4/ S
Q/ SQ4/ SQ/ SQ4/ SQ/ SQ4S.rSS jrg)    N)signalc                 |   US::  a  U $ [         R                  " U R                  S   S5      n[         R                  " U R                  S   5      nSUS'   SUS'   SUR                  S   S-
  4/nSnU(       Gd=  UR                  5       u  pgXSS24   u  pXSS24   u  pX-
  nX-
  n[         R                  " X5      * nU	[         R
                  " U5      -  U[         R                  " U5      -  -   nXS-   U2SS24   nX6S-   U nUSS2S4   U-
  nUSS2S4   U	-
  nUSS2S4   U
-
  nUSS2S4   U-
  nUU-  UU-  -   nU* U-  UU-  -
  n[         R                  " US:  US:  5      n[         R                  " U5      n[         R                  " UUS4   [         R                  " U5      -  UUS4   [         R
                  " U5      -  -   U-
  5      UU'   [         R                  " [         R                  " UU   S-  UU   S-  -   5      [         R                  " UU   S-  UU   S-  -   5      5      UU'   [         R                  " UU:  5      (       aG  U[         R                  " U5      -   S-   nUR                  UU45        UR                  UU45        SUU'   [        U5      S:X  a  SnU(       d  GM=  XSS24   $ )	al  Approximate a polygonal chain with the specified tolerance.

It is based on the Douglas-Peucker algorithm.

Note that the approximated polygon is always within the convex hull of the
original polygon.

Parameters
----------
coords : (K, 2) array
    Coordinate array.
tolerance : float
    Maximum distance from original points of polygon to approximated
    polygonal chain. If tolerance is 0, the original coordinate array
    is returned.

Returns
-------
coords : (L, 2) array
    Approximated polygonal chain where L <= K.

References
----------
.. [1] https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm
r   boolT   FN   )npzerosshapepoparctan2sincoslogical_andlogical_notabsminimumsqrtanyargmaxappendlen)coords	tolerancechaindists	pos_stackend_of_chainstartendr0c0r1c1drdcsegment_anglesegment_distsegment_coordssegment_distsdr0dc0dr1dc1projected_lengths0projected_lengths1perpeuclnew_ends                              X/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/measure/_polygon.pyapproximate_polygonr5      s   4 A~HHV\\!_f-EHHV\\!_%EE!HE"IU[[^a'()IL]]_
q!QWWB++BFF=11B9N4NN  	C 23ai#. QT"R'QT"R'QT"R'QT"R' 2Xb0!TBYr1~~0146H16LM~~d# ff47#bff]&;;T1W%}(==>
d
 !jjGGCINSY!^34GGCINSY!^34	
d 66-)+,,bii66:Ggs^,eW-.!E'Ny>QL_ lb (    r      )r      r   )r      r9   )   
   r   )r   r;   r:   )r      r<   r   )r   r8      r8   )   #      r   )r   r@   r?   r>   )r      F   rA   r   )r      8   rD   rC   )r   r   r7   r9   r:   r8   r>   c                 |   U[         ;  a  [        S5      e[        R                  " U SSS24   U SSS24   :H  5      nSnU(       a  U SS2SS24   n Sn[         U   u  pV[        R                  " U[
        5      SU-  -  n[        R                  " U[
        5      SU-  -  n[        R                  " U R                  [        R                  " U5      USS	9n[        R                  " U R                  [        R                  " U5      USS	9n[        R                  " UR                  S
   UR                  S
   -   S45      n	UR                  U	S
SS2'   UR                  U	SSS2'   U(       a  [        R                  " XSSS24   /5      n	U(       a-  U(       d&  [        R                  " U SSS24   XSSS24   /5      n	U	$ )al  Subdivision of polygonal curves using B-Splines.

Note that the resulting curve is always within the convex hull of the
original polygon. Circular polygons stay closed after subdivision.

Parameters
----------
coords : (K, 2) array
    Coordinate array.
degree : {1, 2, 3, 4, 5, 6, 7}, optional
    Degree of B-Spline. Default is 2.
preserve_ends : bool, optional
    Preserve first and last coordinate of non-circular polygon. Default is
    False.

Returns
-------
coords : (L, 2) array
    Subdivided coordinate array.

References
----------
.. [1] http://mrl.nyu.edu/publications/subdiv-course2000/coursenotes00.pdf
z8Invalid B-Spline degree. Only degree 1 - 7 is supported.r   Nr   validsamer   wrap)modeboundaryr   )_SUBDIVISION_MASKS
ValueErrorr	   allarrayfloatr   
convolve2dT
atleast_2dr
   r   vstack)
r   degreepreserve_endscircularmethod	mask_evenmask_oddevenoddouts
             r4   subdivide_polygonr]   l   s~   2 ''VWWvvfQTlfRUm34HFQ,V4IE*ai8Ixx%(AvI6H"--	*&D 

"--)C ((DJJqMCIIaL0!4
5CC1IuuC!Hii!Q$i()Xii1s2q5M:;Jr6   )r   F)numpyr	   scipyr   r5   rK   r]    r6   r4   <module>ra      sj     Vz 
AA	
AA9J&'-.
 <r6   