
    Og                       d dl mZ d dlmZmZmZmZmZ d dlZd dl	m
Z
mZmZmZ d dlmZmZ erd dlmZ d ej&                  d      z  Z ej&                  d	      d
z  Z ej,                  ej.                  d	z        dz  Zd ej2                  ej.                  d	z        z  Z G d d      Z	 	 	 	 d	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZy)    )annotations)TYPE_CHECKINGIterableSequenceIteratorOptionalN)Vec3UVecMatrix44UCS)MeshVertexMergerMeshTransformer)GenericLayoutType      ?       @g      @g      @      ?c                      e Zd ZdZ	 	 	 	 d
	 	 	 	 	 	 	 ddZddZeZ	 	 	 	 	 	 ddZddZ	 	 	 	 d	 	 	 	 	 	 	 	 	 ddZ	ddZ
dd	Zy)SierpinskyPyramidz
    Args:
        location: location of base center as (x, y, z) tuple
        length: side length
        level: subdivide level
        sides: sides of base geometry

    c                :    || _         t        ||||      | _        y )N)locationlengthlevelsides)r   sierpinsky_pyramidpyramid_definitions)selfr   r   r   r   s        d/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/sierpinski_pyramid.py__init__zSierpinskyPyramid.__init__   s!     
#5fE$
     c              #  \   K   | j                   D ]  \  }}| j                  ||        yw)z@Yields the pyramid vertices as list of :class:`ezdxf.math.Vec3`.N)r   _calc_vertices)r   r   r   s      r   verticeszSierpinskyPyramid.vertices*   s3      $ 8 8 	8Hf%%h77	8s   *,c                   |dz  }|\  }}}| j                   dk(  r`t        ||z
  ||z
  |      t        ||z   ||z
  |      t        ||z   ||z   |      t        ||z
  ||z   |      t        ||||t        z  z         gS | j                   dk(  r]|t        z  }|t        z  }t        ||z
  ||z
  |      t        ||z   ||z
  |      t        |||z   |      t        ||||t
        z  z         gS t        d      )z
        Calculates the pyramid vertices.

        Args:
            location: location of the pyramid as center point of the base
            length: pyramid side length

        Returns: list of :class:`ezdxf.math.Vec3`

        r         sides has to be 3 or 4.)r   r	   HEIGHT4
DY1_FACTOR
DY2_FACTORHEIGHT3
ValueError)	r   r   r   len2xyzdy1dy2s	            r   r!   z SierpinskyPyramid._calc_vertices1   s    |1a::?QXq4x+QXq4x+QXq4x+QXq4x+Q1v//0  ZZ1_:%C:%CQXq3w*QXq3w*QC#Q1v//0	  677r   c                d    | j                   dk(  rg dS | j                   dk(  rg dS t        d      )z{Returns list of pyramid faces. All pyramid vertices have the same
        order, so one faces list fits them all.

        r$   ))r%         r   )r   r4   r$   )r4   r3   r$   )r3   r%   r$   )r%   r   r$   r%   ))r3   r4   r   )r   r4   r%   )r4   r3   r%   )r3   r   r%   r&   )r   r+   )r   s    r   faceszSierpinskyPyramid.facesT   s2    
 ::?MMZZ1_??677r   Nc                    |r&| j                         }|j                  ||||       y| j                         D ]  }|j                  ||||        y)a,  Renders the sierpinsky pyramid into layout, set `merge` to ``True``
        for rendering the whole sierpinsky pyramid into one MESH entity, set
        `merge` to ``False`` for individual pyramids as MESH entities.

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

        )
dxfattribsmatrixucs)r8   r9   N)meshrender_meshpyramids)r   layoutmerger7   r8   r9   r:   pyramids           r   renderzSierpinskyPyramid.render`   s^    * 99;D:f#    ==? P##FJv3#OPr   c              #  |   K   | j                         }| D ]#  }t               }|j                  ||       | % yw)znYields all pyramids of the sierpinsky pyramid as individual
        :class:`MeshTransformer` objects.
        r"   r5   N)r5   r   add_mesh)r   r5   r"   r:   s       r   r<   zSierpinskyPyramid.pyramids~   s?      

 	H"$DMM85M9J	s   :<c                    | j                         }t               }| D ]  }|j                  ||        t        j                  |      S )z8Returns geometry as one :class:`MeshTransformer` object.rB   )r5   r   rC   r   from_builder)r   r5   r:   r"   s       r   r:   zSierpinskyPyramid.mesh   sE    

! 	:HMM85M9	:++D11r   )        rG   rG   r   r4   r$   )r   r
   r   floatr   intr   rI   )returnzIterator[list[Vec3]])r   r
   r   rH   rJ   z
list[Vec3])rJ   zlist[Sequence[int]])FNNN)
r=   r   r>   boolr8   zOptional[Matrix44]r9   zOptional[UCS]rJ   None)rJ   zIterable[MeshTransformer])rJ   r   )__name__
__module____qualname____doc__r   r"   __iter__r!   r5   r@   r<   r:    r   r   r   r      s     )



 

 	


 

8
 H!8!8&+!8	!8F
8 %)!P!P P
 #P P 
P<2r   r   c           	         t        |       } t        |      }|dk  rt        d      t        | ||      }t	        |dz
        D ],  }g }|D ]!  \  } }|j                  t        | ||             # |}. |S )a  Build a Sierpinski pyramid.

    Args:
        location: base center point of the pyramid
        length: base length of the pyramid
        level: recursive building levels, has to 1 or bigger
        sides: 3 or 4 sided pyramids supported

    Returns: list of pyramid vertices

    r4   zlevel has to be 1 or bigger.)r	   rI   r+   _sierpinsky_pyramidrangeextend)r   r   r   r   r<   _next_level_pyramidss          r   r   r      s    " H~HJEqy788"8VU;H519 '  ( 	Hf&&#Hfe<	 '' Or   c                \    |dk(  rt        | |      S |dk(  rt        | |      S t        d      )Nr%   r$   r&   )sierpinsky_pyramid_3sierpinsky_pyramid_4r+   )r   r   r   s      r   rT   rT      s8     z#Hf55	!#Hf55233r   c                    |dz  }|dz  }| \  }}}t        ||z
  ||z
  |      |ft        ||z   ||z
  |      |ft        ||z
  ||z   |      |ft        ||z   ||z   |      |ft        ||||t        z  z         |fgS )a  Build a 4-sided Sierpinski pyramid. Pyramid height = length of the base
    square!

    Args:
        location: base center point of the pyramid
        length: base length of the pyramid

    Returns: list of (location, length) tuples, representing the sierpinski pyramid

    r3   r$   )r	   r'   )r   r   r,   len4r-   r.   r/   s          r   r[   r[      s     A:DA:DGAq!	a$hD!	$d+	a$hD!	$d+	a$hD!	$d+	a$hD!	$d+	aAw&	'. r   c           
         |t         z  dz  }|t        z  dz  }|dz  }|dz  }| \  }}}t        ||z
  ||z
  |      |ft        ||z   ||z
  |      |ft        |||z   |      |ft        ||||t        z  z         |fgS )zBuild a 3-sided Sierpinski pyramid (tetraeder).

    Args:
        location: base center point of the pyramid
        length: base length of the pyramid

    Returns: list of (location, length) tuples, representing the sierpinski pyramid

    r   r3   r$   )r(   r)   r	   r*   )	r   r   r0   r1   r,   r]   r-   r.   r/   s	            r   rZ   rZ      s     :

#C
:

#CA:DA:DGAq!	a$hC	#T*	a$hC	#T*	aS!	d#	aAw&	'.	 r   rF   )r   rH   r   rI   r   rI   rJ   list[tuple[Vec3, float]])r   r$   )r   r	   r   rH   r   rI   rJ   r_   )r   )r   r	   r   rH   rJ   r_   ) 
__future__r   typingr   r   r   r   r   math
ezdxf.mathr	   r
   r   r   ezdxf.render.meshr   r   ezdxf.eztypesr   sqrtr'   r*   tanpir(   cosr)   r   r   rT   r[   rZ   rR   r   r   <module>rj      s9   # H H  0 0 ?/
			#

$))C.3
TXXdggm$s*
8488DGGcM**
z2 z2| 	  	
 B 7844!40344 %(!4 %(!r   