
    |h              	           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y)    N)signalc                 P   |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.|j                         \  }}| |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kD  |dkD        }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                  ||kD        rF|t        j                  |      z   dz   }|j                  ||f       |j                  ||f       d||<   t        |      dk(  rd}|s.| |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                              W/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/measure/_polygon.pyapproximate_polygonr5      s   4 A~HHV\\!_f-EHHV\\!_%EE!HE"IU[[^a'()IL]]_
sq!BQB"W"WB++BFF=11B9N4NN  	C 23eai#. 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_ 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>   c                 N   |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vvfQTlfRUm34HFQ,V4IxE*ai8Ixx%(AvI6H"--	*&D 

"--)C ((DJJqMCIIaL0!4
5CC1IuuC!Hiic!Q$i()Xii1sF2q5M:;Jr6   )r   F)numpyr	   scipyr   r5   rK   r]    r6   r4   <module>ra      sj     Vz 
AA	
AA9J&'-.
 <r6   