
    Og!                    2   d dl mZ d dlmZmZmZmZ d dlmZm	Z	m
Z
mZ d dlmZmZmZ erd dlmZ g dZg dZg dZg d	Zg d
ZeeeegZg dZg dZg dg dg dg dg dg dgZ G d d      ZddZddZ	 d	 	 	 	 	 	 	 ddZ	 	 	 	 d	 	 	 	 	 	 	 	 	 ddZy)     )annotations)TYPE_CHECKINGIteratorSequenceOptional)Vec3UVecMatrix44UCS)MeshVertexMergerMeshTransformerMeshBuilder)GenericLayoutType)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   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   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   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   r   r   r    r"   r$   r&   r(   r*   r,   )r   r   r   r   r   r   r   r!   r#   r%   r'   r)   r+   )Lr   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-   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   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.   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-   )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-   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.   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.   )r-   r-   r.   )r.   r-   r.   )r   r.   r.   )r   r.   r.   )r   r.   r.   )r-   r.   r.   )r.   r.   r.   )      @r/   r/   g      @)r   r   r   r   r   r   r   r   )r   r-   r   r   )r.            )r   r   r0   r.   )r   r   r1   r0   )r-   r2   r1   r   )r   r.   r2   r-   c                      e Zd ZdZ	 	 	 	 d		 	 	 	 	 	 	 d
dZddZeZedd       Z	 	 	 	 d	 	 	 	 	 	 	 	 	 ddZ	ddZ
ddZy)MengerSpongeaZ  

    Args:
        location: location of lower left corner as (x, y, z) tuple
        length: side length
        level: subdivide level
        kind: type of menger sponge

    === ===========================
    0   Original Menger Sponge
    1   Variant XOX
    2   Variant OXO
    3   Jerusalem Cube
    === ===========================

    c                ,    t        ||||      | _        y )N)locationlengthlevelkind)_menger_spongecube_definitions)selfr6   r7   r8   r9   s        _/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/menger_sponge.py__init__zMengerSponge.__init__e   s     !/fE!
    c              #     K   | j                   D ]F  \  }}|\  }}}t        D cg c]%  \  }}}t        |||z  z   |||z  z   |||z  z         ' c}}} H yc c}}}w w)z5Yields the cube vertices as list of (x, y, z) tuples.N)r;   _cube_verticesr   )	r<   r6   r7   xyzxfyfzfs	            r=   verticeszMengerSponge.verticesp   sy      $ 5 5 	HfGAq! #1 BB Qf_a"v+oq2;G 	s   #A *A
A c                     t         S )zuReturns list of cube faces. All cube vertices have the same order, so
        one faces list fits them all.

        )
cube_faces r?   r=   faceszMengerSponge.faces{   s
     r?   Nc                    |r&| j                         }|j                  ||||       y| j                         D ]  }|j                  ||||        y)aV  Renders the menger sponge into layout, set `merge` to ``True`` for
        rendering the whole menger sponge into one MESH entity, set `merge` to
        ``False`` for rendering the individual cubes of the menger sponge as
        MESH entities.

        Args:
            layout: DXF target layout
            merge: ``True`` for one MESH entity, ``False`` for individual MESH
                entities per cube
            dxfattribs: DXF attributes for the MESH entities
            matrix: apply transformation matrix at rendering
            ucs: apply UCS transformation at rendering

        )
dxfattribsmatrixucs)rO   rP   N)meshrender_meshcubes)r<   layoutmergerN   rO   rP   rQ   cubes           r=   renderzMengerSponge.render   s^    , 99;D:f#   

 M  F LMr?   c              #     K   | j                         }| D ]6  }t               }|j                  ||       t        j                  |       8 yw)zfYields all cubes of the menger sponge as individual
        :class:`MeshTransformer` objects.
        rH   rL   N)rL   r   add_meshr   from_builder)r<   rL   rH   rQ   s       r=   rS   zMengerSponge.cubes   sK      

 	5H#%DMM85M9!..t44	5s   AAc                    | j                         }t               }| D ]  }|j                  ||        t        |      S )z8Returns geometry as one :class:`MeshTransformer` object.rY   )rL   r   rZ   remove_duplicate_inner_faces)r<   rL   rQ   rH   s       r=   rQ   zMengerSponge.mesh   s?    

! 	:HMM85M9	:+D11r?           r`   r`         ?r   r   )r6   r	   r7   floatr8   intr9   rc   )returnzIterator[list[Vec3]])rd   zlist[list[int]])FNNN)
rT   r   rU   boolrO   zOptional[Matrix44]rP   zOptional[UCS]rd   None)rd   zIterator[MeshTransformer])rd   r   )__name__
__module____qualname____doc__r>   rH   __iter__staticmethodrL   rW   rS   rQ   rK   r?   r=   r4   r4   S   s    & )	
	
 	
 		

 	
 H  %)!M!M M
 #M M 
M>52r?   r4   c                    t               }| j                  |_        t        t        | j                              |_        |S N)r   rH   listmanifold_facesrL   )rQ   new_meshs     r=   r]   r]      s0     HH.45HNOr?   c              #     K   i }| D ]+  }t        t        |            }	 ||   j                  |       - |j	                         D ]  } t        |       dk(  s| d     y # t        $ r	 |g||<   Y kw xY ww)Nr   r   )tuplesortedappendKeyErrorvalueslen)rL   ledgerfacekeys       r=   rp   rp      s     9;F !F4L!	!3Kt$!  u:?(N  	!&F3K	!s-   A6A!#A6
A6!A30A62A33A6c                   	 | \  t        |      t        |   z  	t        |   }d	fd}|D cg c]  } ||      	f c}S c c}w )ag  Divides a cube in sub-cubes and keeps only cubes determined by the
    building schema.

    All sides are parallel to x-, y- and z-axis, location is a (x, y, z) tuple
    and represents the coordinates of the lower left corner (nearest to the axis
    origin) of the cube, length is the side-length of the cube

    Args:
        location: (x, y, z) tuple, coordinates of the lower left corner of the cube
        length: side length of the cube
        kind: int for 0: original menger sponge; 1: Variant XOX; 2: Variant OXO;
            3: Jerusalem Cube;

    Returns: list of sub-cubes (location, length)

    c                N    | \  }}}t        |z  z   |z  z   |z  z         S rn   )r   )indicesrB   rC   rD   init_xinit_yinit_z	step_sizes       r=   sub_locationz _subdivide.<locals>.sub_location   s?    1aQ]"Q]"Q]"
 	
r?   )rd   r   )rb   
cube_sizesbuilding_schemas)
r6   r7   r9   remaining_cubesr   r~   r   r   r   r   s
         @@@@r=   
_subdivider      sY    ( &FFFf
4 00I&t,O
 
 ?NN7\'"I.NNNs   A
c           	        t        |      }|dvrt        d      t        |      }|dk  rt        d      t        | ||      }t        |dz
        D ]-  }g }|D ]"  \  } }|j	                  t        | ||             $ |}/ |S )a  Builds a menger sponge for given level.

    Args:
        location: (x, y, z) tuple, coordinates of the lower left corner of the cube
        length: side length of the cube
        level: level of menger sponge, has to be 1 or bigger
        kind: int for 0: original menger sponge; 1: Variant XOX; 2: Variant OXO;
            3: Jerusalem Cube;

    Returns: list of sub-cubes (location, length)

    )r   r   r   r-   zkind has to be 0, 1, 2 or 3.r   zlevel has to be 1 or bigger.)r9   )rc   
ValueErrorr   rangeextend)r6   r7   r8   r9   rS   _next_level_cubess          r=   r:   r:      s    $ t9D<788JEqy788xd3E519 ! % 	MHf##Jxd$KL	M 	!
 Lr?   N)rQ   r   rd   r   )rL   zlist[Sequence[int]]rd   zIterator[Sequence[int]])r_   ra   r   )r6   r	   r7   rb   r9   rc   rd   list[tuple[Vec3, float]]r^   )
r6   r	   r7   rb   r8   rc   r9   rc   rd   r   ) 
__future__r   typingr   r   r   r   
ezdxf.mathr   r	   r
   r   ezdxf.render.meshr   r   r   ezdxf.eztypesr   all_cubes_size_3_templateoriginal_menger_cubes	menger_v1	menger_v2jerusalem_cuber   r   rA   rJ   r4   r]   rp   r   r:   rK   r?   r=   <module>r      s   # > > 0 0 L L/  			 	  
	 
_2 _2D
 HI O O.3 OAD O OH %	  	
 r?   