
    'j                    v   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j        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dS )$    )annotations)TYPE_CHECKINGIterableSequenceIteratorOptionalN)Vec3UVecMatrix44UCS)MeshVertexMergerMeshTransformer)GenericLayoutType      ?       @g      @g      @      ?c                  b    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dS ).SierpinskyPyramidz
    Args:
        location: location of base center as (x, y, z) tuple
        length: side length
        level: subdivide level
        sides: sides of base geometry

            r   r   r         locationr
   lengthfloatlevelintsidesc                D    || _         t          ||||          | _        d S )N)r   r   r   r   )r   sierpinsky_pyramidpyramid_definitions)selfr   r   r   r   s        Y/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/addons/sierpinski_pyramid.py__init__zSierpinskyPyramid.__init__   s1     
#5fE$
 $
 $
       returnIterator[list[Vec3]]c              #  T   K   | j         D ]\  }}|                     ||          V  dS )z@Yields the pyramid vertices as list of :class:`ezdxf.math.Vec3`.N)r!   _calc_vertices)r"   r   r   s      r#   verticeszSierpinskyPyramid.vertices*   sF       $ 8 	8 	8Hf%%h777777	8 	8r%   
list[Vec3]c                ,   |dz  }|\  }}}| j         dk    rut          ||z
  ||z
  |          t          ||z   ||z
  |          t          ||z   ||z   |          t          ||z
  ||z   |          t          ||||t          z  z             gS | j         dk    rp|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   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   s8    |1a:??QXq4x++QXq4x++QXq4x++QXq4x++Q1v//00  Z1__:%C:%CQXq3w**QXq3w**QC##Q1v//00	  6777r%   list[Sequence[int]]c                \    | 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   )r   r   r   )r   r<   r   )r<   r-   r   )r-   r   r   r-   ))r<   r   r   )r   r   r-   )r   r<   r-   )r<   r   r-   r.   )r   r3   )r"   s    r#   faceszSierpinskyPyramid.facesT   sA    
 :??MMMMZ1__????6777r%   FNlayoutr   mergeboolmatrixOptional[Matrix44]ucsOptional[UCS]Nonec                    |r/|                                  }|                    ||||           dS |                                 D ]}|                    ||||           dS )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

        )
dxfattribsrA   rC   )rA   rC   N)meshrender_meshpyramids)r"   r>   r?   rG   rA   rC   rH   pyramids           r#   renderzSierpinskyPyramid.render`   s    *  	P99;;D:f#        ==?? P P##FJv3#OOOOP Pr%   Iterable[MeshTransformer]c              #     K   |                                  }| D ]+}t                      }|                    ||           |V  ,dS )znYields all pyramids of the sierpinsky pyramid as individual
        :class:`MeshTransformer` objects.
        r*   r=   N)r=   r   add_mesh)r"   r=   r*   rH   s       r#   rJ   zSierpinskyPyramid.pyramids~   sZ       

 	 	H"$$DMM85M999JJJJ	 	r%   r   c                    |                                  }t                      }| D ]}|                    ||           t          j        |          S )z8Returns geometry as one :class:`MeshTransformer` object.rO   )r=   r   rP   r   from_builder)r"   r=   rH   r*   s       r#   rH   zSierpinskyPyramid.mesh   sS    

!! 	: 	:HMM85M9999+D111r%   r   r   r   r   )r   r
   r   r   r   r   r   r   )r&   r'   )r   r
   r   r   r&   r+   )r&   r:   )FNNN)
r>   r   r?   r@   rA   rB   rC   rD   r&   rE   )r&   rM   )r&   r   )__name__
__module____qualname____doc__r$   r*   __iter__r)   r=   rL   rJ   rH    r%   r#   r   r      s          )

 

 

 

 

8 8 8 8
 H!8 !8 !8 !8F
8 
8 
8 
8 %)!P P P P P<   2 2 2 2 2 2r%   r   r   r   r   r   r   r   r   r   r&   list[tuple[Vec3, float]]c           	        t          |           } t          |          }|dk     rt          d          t          | ||          }t	          |dz
            D ]2}g }|D ])\  } }|                    t          | ||                     *|}3|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

    r   zlevel has to be 1 or bigger.)r	   r   r3   _sierpinsky_pyramidrangeextend)r   r   r   r   rJ   _next_level_pyramidss          r#   r    r       s    " H~~HJJEqyy7888"8VU;;H519 ' '  ( 	 	Hf&&#Hfe<<    'Or%   r   r	   c                x    |dk    rt          | |          S |dk    rt          | |          S t          d          )Nr-   r   r.   )sierpinsky_pyramid_3sierpinsky_pyramid_4r3   )r   r   r   s      r#   r\   r\      sE     zz#Hf555	!#Hf55523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

    r<   r   )r	   r/   )r   r   r4   len4r5   r6   r7   s          r#   rc   rc      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   r<   r   )r0   r1   r	   r2   )	r   r   r8   r9   r4   re   r5   r6   r7   s	            r#   rb   rb      s     :

#C
:

#CA:DA:DGAq!	a$hC	#	#T*	a$hC	#	#T*	aS!		d#	aAw&	'	'.	 r%   rS   )r   r   r   r   r   r   r&   rZ   )r   r   )r   r	   r   r   r   r   r&   rZ   )r   )r   r	   r   r   r&   rZ   ) 
__future__r   typingr   r   r   r   r   math
ezdxf.mathr	   r
   r   r   ezdxf.render.meshr   r   ezdxf.eztypesr   sqrtr/   r2   tanpir0   cosr1   r   r    r\   rc   rb   rY   r%   r#   <module>rq      s   # " " " " " H H H H H H H H H H H H H H  0 0 0 0 0 0 0 0 0 0 0 0 ? ? ? ? ? ? ? ? 0//////
		#

$)C..3
TXdgm$$s*
848DGcM***
z2 z2 z2 z2 z2 z2 z2 z2| 	    B 784 4 4 4 4 %(    4 %(      r%   