
    kj              	          U d dl mZ d dlmZ d dlZddlmZmZm	Z	 ddl
mZmZmZmZ 	 	 	 d(d)dZg g dg dg dg dg dg dg ddZded<   d*d"Zd+d%Z G d& d'          ZdS ),    )annotations)IteratorN   )CellMinimalCell
build_tree)FuncPointValuedPointbinary_search_zero   '  fnr	   pminr
   pmax	min_depthint	max_cellstolnp.ndarray | Nonec           	     ~   t          j        |          }t          j        |          }|	||z
  dz  }nt          j        |          }t          d| |||||          }t          t	          ||                                                     }g }|D ]*}	t          |	| |          }
|
|                    |
           +||fS )u   Returns the surface representing fn([x,y,z])=0 on
    pmin[0] ≤ x ≤ pmax[0] ∩ pmin[1] ≤ y ≤ pmax[1] ∩ pmin[2] ≤ z ≤ pmax[2]Ni     )npasarrayr   listSimplexGeneratorget_simplicesmarch_simplexextend)r   r   r   r   r   r   octtree	simplicesfacessimplex	face_lists              Q/home/agentuser/manim-venv/lib/python3.11/site-packages/isosurfaces/isosurface.pyplot_isosurfacer&      s     :dD:dD
{d{d"jooBdIy#FFG%gr22@@BBCCIE $ $!'2s33	 LL###e    ))r   r   r   r      r   )r   r*   r   r*   r   r*   )r   r   r*   r   )r   r   ))r   r   r*   r   r   r   )r+   r/   r(   r1   )r.   r(   r-   r0   )r.   r,   r)   r1   )r   r   r*         r      r   z dict[int, list[tuple[int, int]]]TETRAHEDRON_TABLEr#   list[ValuedPoint]returnlist[tuple[int, int]]c                ~    d}| D ]}d|z  |j         dk    z   }|t          v rt          |         S t          d|z           S )zFAssumes the simplex is a tetrahedron, so this is marching tetrahedronsr   r*      )valr5   )r#   idps      r%   march_indicesr>   1   sR    	
B " "Vquqy!	 $$ "--r'   
np.ndarray3list[list[Point]] | tuple[list[Point], list[Point]]c                B   t          |           }|rg }|D ]D\  }}t          | |         | |         ||          \  }}|sJ |                    |j                   Et	          |          dk    r|gS |d         |d         |d         g|d         |d         |d         gfS d S )Nr   r   r   r*   )r>   r   appendposlen)	r#   r   r   indicespointsijintersectionis_zeros	            r%   r   r   =   s     G$$G X  	, 	,DAq$6wqz71:rSV$W$W!L'NN7MM,*++++v;;!8O 1Ivay&)4vay&)VTUY6WWWX Xr'   c                  6    e Zd ZddZdd	ZddZddZddZdS )r   rootr   r   r	   r7   Nonec                "    || _         || _        d S N)rL   r   )selfrL   r   s      r%   __init__zSimplexGenerator.__init__P   s    	r'   Iterator[list[ValuedPoint]]c                6    |                      | j                  S rO   )get_simplices_withinrL   )rP   s    r%   r   zSimplexGenerator.get_simplicesT   s    ((333r'   octc           
   #  R  K   |j         r'|j         D ]}|                     |          E d {V  d S dD ]s}dD ]n}|                    ||          }|D ]S}|1|                     ||                    ||                    E d {V  5|                     ||||          E d {V  Totd S )N)r   r   r*   r.   )childrenrT   walk_leaves_in_directionget_simplices_between_faceget_subcellget_simplices_between)rP   rU   childaxisdiradjleafs          r%   rT   z%SimplexGenerator.get_simplices_withinW   s'     < 	X < <44U;;;;;;;;;;< < " X X! X XC66tSAAC # X X<'+'F'FsCOO\`beLfLf'g'ggggggggg'+'A'A#tTSV'W'WWWWWWWWWXXX Xr'   abr]   r   r^   c              #     K   |j         |j         k    r||g\  }}d|z
  }|                    |d|z
            }||fD ]}|                     ||          E d{V  dS )u{   
        Parameters axis and dir are same as Cell.get_leaves_in_direction.
        They denote the direction a→b
        r   N)depthrZ   rY   )rP   ra   rb   r]   r^   facevolumes          r%   r[   z&SimplexGenerator.get_simplices_betweenf   s      
 7QWVFQc'C}}T1s7++!f 	E 	EF66vtDDDDDDDDDD	E 	Er'   rf   re   r   c              #    K   t          d          D ]x}|                    |dz  |dz            }|j        D ]R}|                    | j                  |                    | j                  |                    | j                  |gV  Syd S )Nr2   r*   )rangerZ   verticesget_dualr   )rP   rf   re   rG   edgevs         r%   rY   z+SimplexGenerator.get_simplices_between_faces   s       q 	 	A##AE1622D]  OODG,,MM$'**MM$'**	    	 	r'   N)rL   r   r   r	   r7   rM   )r7   rR   )rU   r   r7   rR   )
ra   r   rb   r   r]   r   r^   r   r7   rR   )rf   r   re   r   r7   rR   )__name__
__module____qualname__rQ   r   rT   r[   rY    r'   r%   r   r   O   s           4 4 4 4X X X XE E E E     r'   r   )r   r   N)r   r	   r   r
   r   r
   r   r   r   r   r   r   )r#   r6   r7   r8   )r#   r6   r   r	   r   r?   r7   r@   )
__future__r   typingr   numpyr   cellr   r   r   pointr	   r
   r   r   r&   r5   __annotations__r>   r   r   rp   r'   r%   <module>rw      sa   " " " " " " "           / / / / / / / / / / ? ? ? ? ? ? ? ? ? ? ? ? !    6 $$$$$$$$$$$$,,,,,,,,,	7 	7  	 	 	 		. 	. 	. 	.X X X X$2 2 2 2 2 2 2 2 2 2r'   