
    h                       S SK Jr  S SKJrJrJrJrJr  S SKrS SK	J
r
JrJrJr  S SKJrJr  \(       a  S SKJr  S\R&                  " S5      -  r\R&                  " S	5      S
-  r\R,                  " \R.                  S	-  5      S-  rS\R2                  " \R.                  S	-  5      -  r " S S5      r    S       SS jjr S       SS jjr S     SS jjr S     SS jjrg)    )annotations)TYPE_CHECKINGIterableSequenceIteratorOptionalN)Vec3UVecMatrix44UCS)MeshVertexMergerMeshTransformer)GenericLayoutType      ?       @g      @g      @      ?c                      \ rS rSrSr    S       SS jjrSS jr\r      SS jrSS jr	    S         SS jjr
SS	 jrSS
 jrSrg)SierpinskyPyramid   z
Args:
    location: location of base center as (x, y, z) tuple
    length: side length
    level: subdivide level
    sides: sides of base geometry

c                .    X@l         [        XX4S9U l        g )N)locationlengthlevelsides)r   sierpinsky_pyramidpyramid_definitions)selfr   r   r   r   s        Q/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/sierpinski_pyramid.py__init__SierpinskyPyramid.__init__   s     
#5E$
     c              #  \   #    U R                    H  u  pU R                  X5      v   M     g7f)z@Yields the pyramid vertices as list of :class:`ezdxf.math.Vec3`.N)r   _calc_vertices)r   r   r   s      r   verticesSierpinskyPyramid.vertices*   s)      $ 8 8H%%h77 !9s   *,c                   US-  nUu  pEnU R                   S:X  aV  [        XC-
  XS-
  U5      [        XC-   XS-
  U5      [        XC-   XS-   U5      [        XC-
  XS-   U5      [        XEXb[        -  -   5      /$ U R                   S:X  aV  U[        -  nU[        -  n[        XC-
  XW-
  U5      [        XC-   XW-
  U5      [        XEU-   U5      [        XEXb[
        -  -   5      /$ [        S5      e)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#    SierpinskyPyramid._calc_vertices1   s     |a::?QXqx+QXqx+QXqx+QXqx+Q1//0  ZZ1_:%C:%CQXqw*QXqw*QC#Q1//0	  677r!   c                h    U R                   S:X  a  / SQ$ U R                   S:X  a  / SQ$ [        S5      e)zkReturns list of pyramid faces. All pyramid vertices have the same
order, so one faces list fits them all.

r'   ))r(         r   )r   r8   r'   )r8   r7   r'   )r7   r(   r'   )r(   r   r'   r(   ))r7   r8   r   )r   r8   r(   )r8   r7   r(   )r7   r   r(   r)   )r   r.   )r   s    r   facesSierpinskyPyramid.facesT   s2    
 ::?MMZZ1_??677r!   Nc                    U(       a!  U R                  5       nUR                  XXES9  gU R                  5        H  nUR                  XXES9  M     g)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)r=   r>   N)meshrender_meshpyramids)r   layoutmerger<   r=   r>   r?   pyramids           r   renderSierpinskyPyramid.render`   sO    * 99;Df    ==?##Fv#O +r!   c              #  x   #    U R                  5       nU  H   n[        5       nUR                  X!S9  Uv   M"     g7f)z^Yields all pyramids of the sierpinsky pyramid as individual
:class:`MeshTransformer` objects.
r$   r9   N)r9   r   add_mesh)r   r9   r$   r?   s       r   rA   SierpinskyPyramid.pyramids~   s7      

H"$DMM8M9J s   8:c                    U R                  5       n[        5       nU  H  nUR                  X1S9  M     [        R                  " U5      $ )z8Returns geometry as one :class:`MeshTransformer` object.rH   )r9   r   rI   r   from_builder)r   r9   r?   r$   s       r   r?   SierpinskyPyramid.mesh   s>    

!HMM8M9 ++D11r!   )r   r   )        rO   rO   r   r8   r'   )r   r
   r   floatr   intr   rQ   )returnzIterator[list[Vec3]])r   r
   r   rP   rR   z
list[Vec3])rR   zlist[Sequence[int]])FNNN)
rB   r   rC   boolr=   zOptional[Matrix44]r>   zOptional[UCS]rR   None)rR   zIterable[MeshTransformer])rR   r   )__name__
__module____qualname____firstlineno____doc__r   r$   __iter__r#   r9   rE   rA   r?   __static_attributes__ r!   r   r   r      s     )



 

 	


 

8
 H!8!8&+!8	!8F
8 %)!P!P P
 #P P 
P<2r!   r   c           	         [        U 5      n [        U5      nUS:  a  [        S5      e[        XU5      n[	        US-
  5       H-  n/ nU H   u  pUR                  [        XU5      5        M"     UnM/     U$ )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

r8   zlevel has to be 1 or bigger.)r	   rQ   r.   _sierpinsky_pyramidrangeextend)r   r   r   r   rA   _next_level_pyramidss          r   r   r      s    " H~HJEqy788"8U;H519  (H&&#He< !) '  Or!   c                \    US:X  a  [        X5      $ US:X  a  [        X5      $ [        S5      e)Nr(   r'   r)   )sierpinsky_pyramid_3sierpinsky_pyramid_4r.   )r   r   r   s      r   r^   r^      s4     z#H55	!#H55233r!   c                    US-  nUS-  nU u  pEn[        XC-
  XS-
  U5      U4[        XC-   XS-
  U5      U4[        XC-
  XS-   U5      U4[        XC-   XS-   U5      U4[        XEXb[        -  -   5      U4/$ )zBuild 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

r7   r'   )r	   r*   )r   r   r/   len4r0   r1   r2   s          r   re   re      s     A:DA:DGA!	ah!	$d+	ah!	$d+	ah!	$d+	ah!	$d+	aAw&	'. r!   c           
         U[         -  S-  nU[        -  S-  nUS-  nUS-  nU u  pgn[        Xe-
  Xr-
  U5      U4[        Xe-   Xr-
  U5      U4[        XgU-   U5      U4[        XgX[        -  -   5      U4/$ )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   r7   r'   )r+   r,   r	   r-   )	r   r   r3   r4   r/   rg   r0   r1   r2   s	            r   rd   rd      s     :

#C
:

#CA:DA:DGA!	ah	#T*	ah	#T*	aS!	d#	aAw&	'.	 r!   rN   )r   rP   r   rQ   r   rQ   rR   list[tuple[Vec3, float]])r   r'   )r   r	   r   rP   r   rQ   rR   ri   )r   )r   r	   r   rP   rR   ri   ) 
__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   r^   re   rd   r\   r!   r   <module>rt      s1   # H H  0 0 ?/
		#

))C.3
XXdggm$s*
488DGGcM**
z2 z2| 	  	
 B 7844!40344 %(!4 %(!r!   