
    Ti{               	           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m
Z ddlmZmZmZmZmZ d	Ze G d
 d                      Z	 ddedededefdZddZddZdS )    )	dataclassN   )util)log)res_path)tol_path)	ArrayLikeNDArrayNumberOptionalfloat64g-q=c                       e Zd ZU eed<   ee         ed<   dZeee                  ed<   dZ	eee                  ed<   dZ
ee         ed<   d ZdS )ArcInforadiuscenterNnormalanglesspanc                 "    t          | |          S N)getattr)selfitems     J/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/path/arc.py__getitem__zArcInfo.__getitem__!   s    tT"""    )__name__
__module____qualname__float__annotations__r
   r   r   r   r   r   r   r    r   r   r   r      s          MMM G *.FHWW%&--- *.FHWW%&--- "D(6
!!!# # # # #r   r   Tpointsreturn_normalreturn_anglereturnc           	         t          j        | t           j                  } | g d         | g d         z
  }t          j        |dz  dg| j        d         z            }t          j        |          }|                                }||z  }|                                dz  }|t          j        ||z
            z  }	|	t          j
        k     rt          d          |t          j        |          dz  t          j        |	          z  z  }
|g d	         g d
z                      d                              d          |z  }| j                            |          |                                z  }t          j        r9t          j        t           j                            | |z
  d          |
          sJ ||
d}|r| j        dk    r^t          j        t          j        t          j        |d          d          t          j        |d         d                              |d<   n7t          j        t          j        |d          |d                             |d<   |r^t          j        | |z
            }t          j        | d          }t          j        |ddg          }|t.          dz
  k     rt           j        }n%|dt.          z
  k    rd}nt          j        |          }t5          |          t.          k    r$t          j        | dk     rt           j        dz  |z
  }t          j        |ddddf         j        ddd          t           j        dz  z   }t          j        |ddg                   }|d         |d         cxk     o|d         k     nc }|dddt;          |           dz  z
           }||d<   ||d<   t=          di |S )a  
    Given three points on a 2D or 3D arc find the center,
    radius, normal, and angular span.

    Parameters
    ---------
    points : (3, dimension) float
      Points in space, where dimension is either 2 or 3
    return_normal : bool
      If True calculate the 3D normal unit vector
    return_angle : bool
      If True calculate the start and stop angle and span

    Returns
    ---------
    info
      Arc center, radius, and other information.
    dtype)r   r      )r*   r   r   r   r*   g       @zarc is colinear!g      @)	r*   r   r   r   r   r*   r   r*   r   )	r*   r*   r*   r*   r+   r*   r*   r+   )   r,   )axis)r   r   )r,   r   r   r           Nr+   r   r   r"   )np
asanyarrayr   dotshapesqrtminsumprodtolmerge
ValueErrorreshapeTstrictr   allcloselinalgnormunitizecrossappenddiff	_TOL_ZEROpiarccosabsarctan2sortintr   )r#   r$   r%   vectorsabc2abcscaleedgeshalfdenomr   ba2r   resultvectoredge_directionr1   angler   angles_sortedreverses                        r   
arc_centerrY   &   s   * ]6444F YYY&"33G6'1*qcFLO344D
'$--C GGIIE%KE99;;D274%<(((Esy+,,,rwu~~+rwu~~=>F +++,/M/M/MM
V
V 	cqckkDC X\\#*F
z N}RY^^FVO!^DDfMMMMM &11F 	O<6!!  $|GAJ;22BIgaj!4L4LMM   F8
  $|BHgaj['!*,M,MNNF8 fvo..a000ffaVn%)a-  EEE1y=  EEIcNNE u::	!!bfn&=&C&CUQY%'EVAAArrE]_TTrT23beai?1v//"VAYAAAAq1AAAAA%&C&C!cg+.>.>.B*B&CD(xvVr   F      ?c                 6   t          j        | d          \  } }	 t          |           }n$# t          $ r |r| ddddf         cY S | cY S w xY w|j        |j        |j        |j        f\  }}}}|rt          j	        dz  }|t          j        z  }	||z  t          j        |z  z  }
t          j        |	|
g          }t          j        |dt          j                  }t!          t          j        |                    }t          j        | d         |z
            }t          j        t          j        | |                    }t          j        d||          }t          j        ||df          }||t          j        |                              d          z  |z  z  }||t          j        |                              d          z  |z  z  }|st2          j        rt          j        | dd	g         |dd	g         z
            }|t2          j        k                                     }|sTt=          j        d
tA          |          |           t=          j        dtA          |                      tC          d          | dd	g         |dd	g<   |dddd|z
  f         }|S )a  
    Returns a version of a three point arc consisting of
    line segments.

    Parameters
    ---------
    points : (3, d) float
      Points on the arc where d in [2,3]
    close :  boolean
      If True close the arc into a circle
    scale : float
      What is the approximate overall drawing scale
      Used to establish order of magnitude for precision

    Returns
    ---------
    discrete : (m, d) float
      Connected points in space
    T)	return_2DNr      r   r*   )r+   r*   r+   z4failed to discretize arc (endpoint_distance=%s R=%s)zFailed arc points: %szArc endpoints diverging!r,   )"r   stack_3DrY   BaseExceptionr   r   r   r   r/   rE   res	seg_angleseg_fracmaxclipinfrJ   ceilr@   rA   linspacetilecosr:   sinr7   r<   row_normr8   allr   warningstrr9   )r#   closerN   is_2Dcenter_infor   RNrV   count_acount_lcountV1V2tdiscretearc_distarc_oks                     r   discretize_arcr}      s   * M&D999MFE ((     	!!!!RaR%=    		FAq%  	 cm#G5yS\E12G FGW%&&E GE1bf%%EE	fQi&(	)	)B	bhr2&&	'	'B
Aue$$Awvqz**HBF1II%%g...33HBF1II%%g...33H  ,: 
	=}VQG_xB7H%HIIH*//11F =JMM  
 3S[[AAA !;<<<"Ar7O!R =a%i=()HOs   + AAAc                 n   |dt           j        g}t          j        |t           j                  }|j        dk    rt          d          |d         |d         k     r|dxx         t           j        dz  z  cc<   t          j        | t           j                  } | j        dk    rt          d	          t          j        |d         |                                |d         gt           j                  }t          j        t          j	        |          t          j
        |          f          |z  | z   }|S )
a  
    For 2D arcs, given a center and radius convert them to three
    points on the arc.

    Parameters
    -----------
    center : (2,) float
      Center point on the plane
    radius : float
      Radius of arc
    angles : (2,) float
      Angles in radians for start and end angle
      if not specified, will default to (0.0, pi)

    Returns
    ----------
    three : (3, 2) float
      Arc control points
    Nr.   r(   )r   zangles must be (2,)!r*   r   r   zonly valid on 2D arcs!)r/   rE   r0   r   r2   r9   arraymeancolumn_stackri   rj   )r   r   r   threes       r   to_threepointr      s	   * ~ru]6444F|t/000ay6!9q			RUQY			]6444F|t1222 Xvay&++--;2:NNNF_bfVnnbfVnn=>>G6QELr   )TT)FrZ   r   )dataclassesr   numpyr/    r   	constantsr   r   r`   r   r7   typedr	   r
   r   r   r   rD   r   boolrY   r}   r   r"   r   r   <module>r      sQ   ! ! ! ! ! !                 ' ' ' ' ' ' ' ' ' ' ' ' A A A A A A A A A A A A A A 	 # # # # # # # #. IM[ [[&*[AE[[ [ [ [|S S S Sl) ) ) ) ) )r   