
    'j!                       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	 	 	 	 d0d1d*Zd+S )2    )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                  j    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dS )+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
    === ===========================

            r6   r6         ?r   r   locationr	   lengthfloatlevelintkindc                6    t          ||||          | _        d S )N)r8   r9   r;   r=   )_menger_spongecube_definitions)selfr8   r9   r;   r=   s        T/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/addons/menger_sponge.py__init__zMengerSponge.__init__e   s*     !/fE!
 !
 !
    returnIterator[list[Vec3]]c              #  h   K   | j         D ]#\  }|\  fdt          D             V  $dS )z5Yields the cube vertices as list of (x, y, z) tuples.c           	     ^    g | ])\  }}}t          |z  z   |z  z   |z  z             *S  r   ).0xfyfzfr9   xyzs       rB   
<listcomp>z)MengerSponge.vertices.<locals>.<listcomp>t   sS       BB Qf_a"v+oq2;GG  rD   N)r@   _cube_vertices)rA   r8   r9   rO   rP   rQ   s     @@@@rB   verticeszMengerSponge.verticesp   s       $ 5 	 	HfGAq!      "0      	 	rD   list[list[int]]c                     t           S )zuReturns list of cube faces. All cube vertices have the same order, so
        one faces list fits them all.

        )
cube_facesrI   rD   rB   faceszMengerSponge.faces{   s
     rD   FNlayoutr   mergeboolmatrixOptional[Matrix44]ucsOptional[UCS]Nonec                    |r/|                                  }|                    ||||           dS |                                 D ]}|                    ||||           dS )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

        )
dxfattribsr\   r^   )r\   r^   N)meshrender_meshcubes)rA   rY   rZ   rb   r\   r^   rc   cubes           rB   renderzMengerSponge.render   s    ,  	M99;;D:f#       

 M M  F LLLLM MrD   Iterator[MeshTransformer]c              #     K   |                                  }| D ]=}t                      }|                    ||           t          j        |          V  >dS )zfYields all cubes of the menger sponge as individual
        :class:`MeshTransformer` objects.
        rT   rX   N)rX   r   add_meshr   from_builder)rA   rX   rT   rc   s       rB   re   zMengerSponge.cubes   si       

 	5 	5H#%%DMM85M999!.t444444	5 	5rD   r   c                    |                                  }t                      }| D ]}|                    ||           t          |          S )z8Returns geometry as one :class:`MeshTransformer` object.rj   )rX   r   rk   remove_duplicate_inner_faces)rA   rX   rc   rT   s       rB   rc   zMengerSponge.mesh   sP    

!! 	: 	:HMM85M9999+D111rD   r5   r7   r   r   )r8   r	   r9   r:   r;   r<   r=   r<   )rE   rF   )rE   rU   )FNNN)
rY   r   rZ   r[   r\   r]   r^   r_   rE   r`   )rE   rh   )rE   r   )__name__
__module____qualname____doc__rC   rT   __iter__staticmethodrX   rg   re   rc   rI   rD   rB   r4   r4   S   s         & )	
 	
 	
 	
 	
    H   \ %)!M M M M M>5 5 5 52 2 2 2 2 2rD   r4   rc   r   rE   r   c                    t                      }| j        |_        t          t          | j                            |_        |S N)r   rT   listmanifold_facesrX   )rc   new_meshs     rB   rn   rn      s5      HH.4455HNOrD   rX   list[Sequence[int]]Iterator[Sequence[int]]c              #    K   i }| D ]P}t          t          |                    }	 ||                             |           ;# t          $ r	 |g||<   Y Mw xY w|                                D ]} t          |           dk    r
| d         V   d S )Nr   r   )tuplesortedappendKeyErrorvalueslen)rX   ledgerfacekeys       rB   ry   ry      s      9;F ! !F4LL!!	!3Kt$$$$ 	! 	! 	!&F3KKK	!  u::??(NNN s   AAAr5   r7   r8   r	   r9   r:   r=   r<   list[tuple[Vec3, float]]c                    | \  t          |          t          |         z  t          |         }dfdfd|D             S )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)

    rE   r   c                V    | \  }}}t          |z  z   |z  z   |z  z             S rw   rJ   )indicesrO   rP   rQ   init_xinit_yinit_z	step_sizes       rB   sub_locationz _subdivide.<locals>.sub_location   sD    1aQ]"Q]"Q]"
 
 	
rD   c                *    g | ]} |          fS rI   rI   )rK   r   r   r   s     rB   rR   z_subdivide.<locals>.<listcomp>   s(    NNN7\\'""I.NNNrD   )rE   r   )r:   
cube_sizesbuilding_schemas)	r8   r9   r=   remaining_cubesr   r   r   r   r   s	       @@@@@rB   
_subdivider      s    ( &FFFf
4 00I&t,O
 
 
 
 
 
 
 
 
 ONNNNoNNNNrD   r   r;   c           	     B   t          |          }|dvrt          d          t          |          }|dk     rt          d          t          | ||          }t          |dz
            D ]3}g }|D ]*\  } }|                    t          | ||                     +|}4|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.)r=   )r<   
ValueErrorr   rangeextend)r8   r9   r;   r=   re   _next_level_cubess          rB   r?   r?      s    $ t99D<7888JJEqyy7888xd333E519 ! ! % 	M 	MHf##Jxd$K$K$KLLLL LrD   N)rc   r   rE   r   )rX   r{   rE   r|   )r5   r7   r   )r8   r	   r9   r:   r=   r<   rE   r   ro   )
r8   r	   r9   r:   r;   r<   r=   r<   rE   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   rS   rW   r4   rn   ry   r   r?   rI   rD   rB   <module>r      s   # " " " " " > > > > > > > > > > > > 0 0 0 0 0 0 0 0 0 0 0 0 L L L L L L L L L L 0//////        	  		 	 	 	  
	 	 	 LLLLLLLLLLLL
_2 _2 _2 _2 _2 _2 _2 _2D   
 
 
 
 HI O  O  O  O  OH %	      rD   