
    j{               	           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y)    )	dataclassN   )util)log)res_path)tol_path)	ArrayLikeNDArrayNumberOptionalfloat64g-q=c                   v    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y)ArcInforadiuscenterNnormalanglesspanc                     t        | |      S N)getattr)selfitems     =/DATA/.local/lib/python3.12/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      sX     M G *.FHWW%&- *.FHWW%&- "D(6
!#r   r   pointsreturn_normalreturn_anglereturnc           	      j   t        j                  | t         j                        } | g d   | g d   z
  }t        j                  |dz  dg| j                  d   z        }t        j
                  |      }|j                         }||z  }|j                         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  j                  d      j                  d      |z  }| j                  j                  |      |j                         z  }t        j                  r:t        j                   t         j"                  j%                  | |z
  d      |
      sJ ||
d}|r| j                  dk(  r\t        j&                  t        j(                  t        j*                  |d    d      t        j*                  |d   d                  |d<   n3t        j&                  t        j(                  |d    |d               |d<   |rXt        j&                  | |z
        }t        j,                  | d      }t        j                  |ddg    }|t.        dz
  k  rt         j0                  }n$|dt.        z
  kD  rd}nt        j2                  |      }t5        |      t.        kD  r+t        j                  | dk  rt         j0                  dz  |z
  }t        j6                  |ddddf   j                  ddd    t         j0                  dz  z   }t        j8                  |ddg         }|d   |d   cxk  xr |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4F Y&"33G66'1*qcFLLO34D
''$-C GGIE%KE99;D2774%<((Esyy+,,rwwu~+rwwu~=>F +,/MM
V
V	cqckDC XX\\#*F
zz}}RYY^^FVO!^DfMMM &1F<<6!  $||GAJ;2BIIgaj!4LM F8
  $||BHHgaj['!*,MNF8fvo.a0fffaVn%)a- EEE1y= EIIcNE u:	!bffn&=&CUUQY%'EVArrE]__TrT23beeai?1v/"VAYAq1AA%&C!cg+.>.B*B&CD(xvVr   c                 @   t        j                  | d      \  } }	 t        |       }|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,                  |      j/                  d      z  |z  z  }||t        j0                  |      j/                  d      z  |z  z  }|st2        j4                  rt        j6                  | dd	g   |dd	g   z
        }|t2        j8                  k  j;                         }|sJt=        j>                  d
tA        |      |       t=        j>                  dtA        |              tC        d      | dd	g   |dd	g<   |dddd|z
  f   }|S # t        $ r |r| ddddf   cY S | cY S w xY w)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|      sa   * MM&D9MFE ( 		FAq% 	 cmm#G5yS\\E12G FFGW%&E GGE1bff%EE	fQi&(	)B	bhhr2&	'B
Aue$Awwvqz*HBFF1I%%g..33HBFF1I%%g..33H ::}}VQG_xB7H%HIH*//1FJM
 3S[A !;<<"Ar7O!R =a%i=()HOs   !RaR%= s   J   JJJc                 z   |dt         j                  g}t        j                  |t         j                        }|j                  dk7  rt        d      |d   |d   k  r|dxx   t         j                  dz  z  cc<   t        j                  | t         j                        } | j                  dk7  rt        d      t        j                  |d   |j                         |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
    r.   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_stackrh   ri   )r   r   r   threes       r   to_threepointr      s    * ~ruu]]64F||t/00ay6!9q	RUUQY	]]64F||t122 XXvay&++-;2::NF__bffVnbffVn=>G6QELr   )TT)Fg      ?r   )dataclassesr   numpyr/    r   	constantsr   r   r_   r   r7   typedr	   r
   r   r   r   rD   r   boolrY   r|   r   r"   r   r   <module>r      s{    !    ' ' A A 	 # # #. IM[[&*[AE[[|Sl)r   