Ë
    £èhò"  ã                  ó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        ú:lib/python3.12/site-packages/ezdxf/addons/menger_sponge.pyÚ__init__zMengerSponge.__init__e   s   € ô !/Ø f°EÀô!
ˆÕó    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   st   è ø€ à $× 5Ô 5ÑˆH�fØ‰GˆAˆq�!õ #1õá"0‘J�B˜˜Bô �Q˜˜f™‘_ a¨"¨v©+¡o°q¸2À¹;±ÕGØ"0óó ñ !6ùôù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ƒ   sW   € ñ, Ø—9‘9“;ˆDØ×ÑØ :°fÀ#ð õ ð Ÿ
™
ž�Ø× Ñ  ¨¸FÈÐ ÕLñ %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¢   sF   è ø€ ð —
‘
“ˆÛˆHÜ#Ó%ˆDØ�M‰M 8°5ˆMÔ9Ü!×.Ñ.¨tÓ4Ó4ñ ùs   ‚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Ø�M‰M 8°5ˆMÕ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Ó5€H„NØ€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ÛˆÜ”F˜4“LÓ!ˆð	!Ø�3‰K×Ñ˜tÕ$ð ð —‘–ˆÜˆu‹:˜‹?Ø˜‘(‹Nñ !øô ò 	!Ø˜&ˆF�3‹Kð	!ü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?   ø€ Ø‰ˆˆ1ˆaÜØ�Q˜‘]Ñ"Ø�Q˜‘]Ñ"Ø�Q˜‘]Ñ"ó
ð 	
r?   )rd   r   )rb   Ú
cube_sizesÚbuilding_schemas)
r6   r7   r9   Úremaining_cubesrƒ   r~   r   r€   r�   r‚   s
         @@@@r=   Ú
_subdivider‡   É   s]   û€ ð( &Ñ€FˆF�FÜ�f“¤
¨4Ñ 0Ñ0€IÜ& tÑ,€O÷
ð 
ñ ?NÓN¹o°7‰\˜'Ó" IÒ.¸oÑ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–   € ô$ ˆt‹9€DØ�<ÑÜÐ7Ó8Ð8Ü�‹J€EØˆq‚yÜÐ7Ó8Ð8Ü�x ¨dÔ3€EÜ�5˜1‘9ÖˆØÐÛ %ÑˆH�fØ×#Ñ#¤J¨x¸ÀdÔ$KÕLð !&à ‰ð	 ð
 €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ñ _2óDó
ð HIð OØð OØ.3ð OØADð Oàó OðH %ØØØð	Øðàðð ðð ð	ð
 ôr?   