
    0-Ph              	           d dl Zd dlmZ d Zddgddgfddgddgfg dg dfg dg d	fg d
g dfg dg dfg dg dfdZddZdS )    N)signalc                    |dk    r| S t          j        | j        d         d          }t          j        | j        d                   }d|d<   d|d<   d|j        d         dz
  fg}d}|s`|                                \  }}| |ddf         \  }}	| |ddf         \  }
}|
|z
  }||	z
  }t          j        ||           }|	t          j        |          z  |t          j        |          z  z   }| |dz   |ddf         }||dz   |         }|dddf         |z
  }|dddf         |	z
  }|dddf         |
z
  }|dddf         |z
  }||z  ||z  z   }| |z  ||z  z
  }t          j        |dk    |dk              }t          j        |          }t          j	        ||df         t          j        |          z  ||df         t          j        |          z  z   |z
            ||<   t          j
        t          j        ||         dz  ||         dz  z             t          j        ||         dz  ||         dz  z                       ||<   t          j        ||k              rM|t          j        |          z   dz   }|                    ||f           |                    ||f           d||<   t          |          dk    rd}|`| |ddf         S )	a  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/test/jupyter/venv/lib/python3.11/site-packages/skimage/measure/_polygon.pyapproximate_polygonr5      s8   4 A~~HV\!_f--EHV\!_%%EE!HE"IU[^a'()IL / ]]__
sqqq!BQQQB"W"WB+++BF=111B9N9N4NN  	C 23eai#o. QQQT"R'QQQT"R'QQQT"R'QQQT"R' 2Xb0!TBYr1~0146H16LMM~d## f47#bf]&;&;;T1W%}(=(==>
 
d
 !jGCINSY!^344GCINSY!^344	
 
d 6-)+,, 	"bi666:Ggs^,,,eW-...!E'Ny>>QL_  / b %(    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>   r   Fc                 F   |t           vrt          d          t          j        | dddf         | dddf         k              }d}|r| ddddf         } d}t           |         \  }}t          j        |t
                    d|z  z  }t          j        |t
                    d|z  z  }t          j        | j        t          j	        |          |d	          }t          j        | j        t          j	        |          |d	          }t          j
        |j        d
         |j        d
         z   df          }	|j        |	d
dd<   |j        |	ddd<   |r t          j        |	|	dddf         g          }	|r-|s+t          j        | dddf         |	| dddf         g          }	|	S )a  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WvfQTlfRUm344HF QQQ,V4IxE**ai8Ix%((AvI6H"-	**&  D 
"-))  C (DJqMCIaL0!4
5
5CC1IuC!H *ic!QQQ$i()) <X <i111sF2qqq5M:;;Jr6   )r   F)numpyr	   scipyr   r5   rK   r]    r6   r4   <module>ra      s             V V Vz 
AA	
AA		999

JJJ&'---.
 
 < < < < < <r6   