Ë
    £èhÎ<  ã                  óì   — 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
 d dlmZmZmZmZ ddlmZ ddlmZmZmZmZmZ ddd„Z	 	 	 	 dd	„Z	 d	 	 	 	 	 dd„Zddd„Zdd„Z G d„ d«      Zdd„Zdd„Zddd„Zy
)é    )Úannotations)ÚIteratorÚSequenceÚOptionalÚIterable)ÚMeshVertexMergerÚMeshTransformerÚMeshBuilder)ÚMatrix44ÚVec3ÚNULLVECÚBoundingBoxé   )Úentities)ÚBodyÚLumpÚNONE_REFÚFaceÚShellc                ój  — t        | t        «      st        dt        | «      › �«      ‚g }t	        «       }t        | «      D ]K  }|D ]  }|j                  |«       Œ |rŒ|j                  t        j                  |«      «       t	        «       }ŒM |r$|j                  t        j                  |«      «       |S )aÒ  Returns a list of :class:`~ezdxf.render.MeshTransformer` instances from
    the given ACIS :class:`Body` entity.
    The list contains multiple meshes if `merge_lumps` is ``False`` or just a
    single mesh if `merge_lumps` is ``True``.

    The ACIS format stores the faces in counter-clockwise orientation where the
    face-normal points outwards (away) from the solid body (material).

    .. note::

        This function returns meshes build up only from flat polygonal
        :class:`Face` entities, for a tessellation of more complex ACIS
        entities (spline surfaces, tori, cones, ...) is an ACIS kernel
        required which `ezdxf` does not provide.

    Args:
        body: ACIS entity of type :class:`Body`
        merge_lumps: returns all :class:`Lump` entities
            from a body as a single mesh if ``True`` otherwise each :class:`Lump`
            entity is a separated mesh

    Raises:
        TypeError: given `body` entity has invalid type

    úexpected a body entity, got: )
Ú
isinstancer   Ú	TypeErrorÚtyper   Úflat_polygon_faces_from_bodyÚadd_faceÚappendr	   Úfrom_builder)ÚbodyÚmerge_lumpsÚmeshesÚbuilderÚfacesÚfaces         ú/lib/python3.12/site-packages/ezdxf/acis/mesh.pyÚmesh_from_bodyr&      sœ   € ô4 �dœDÔ!ÜÐ7¼¸T»
°|ÐDÓEÐEà$&€FÜÓ €GÜ-¨dÖ3ˆÛˆDØ×Ñ˜TÕ"ð âØ�M‰Mœ/×6Ñ6°wÓ?Ô@Ü&Ó(‰Gð 4ñ Ø�‰”o×2Ñ2°7Ó;Ô<Ø€Mó    c              #  ó8  K  — t        | t        «      st        dt        | «      › �«      ‚| j                  }| j
                  }d}|j                  s|j                  }|j                  s1t        t        ||«      «      –— |j                  }|j                  sŒ0yy­w)a$  Yields all flat polygon faces from all lumps in the given
    :class:`Body` entity.
    Yields a separated list of faces for each linked :class:`Lump` entity.

    Args:
        body: ACIS entity of type :class:`Body`

    Raises:
        TypeError: given `body` entity has invalid type

    r   N)r   r   r   r   ÚlumpÚ	transformÚis_noneÚmatrixÚlistÚflat_polygon_faces_from_lumpÚ	next_lump)r   r)   r*   Úms       r%   r   r   5   s€   è ø€ ô �dœDÔ!ÜÐ7¼¸T»
°|ÐDÓEÐEØ�9‰9€DØ—‘€Ià €AØ×ÒØ×ÑˆØ�lŠlÜÔ/°°aÓ8Ó9Ò9Ø�~‰~ˆð �l�lùs   ‚BBÂBNc              #  ó–  K  — t        | t        «      st        dt        | «      › �«      ‚| j                  }|j
                  ryg }|j                  }|j
                  �sKt        }|j                  «        |j                  j                  dk(  r	 |j                  j                  }|}|j
                  sÜ|j                  }	 |j                  j                  dk7  rnµ|j                  r0|j!                  |j"                  j$                  j&                  «       n/|j!                  |j(                  j$                  j&                  «       |j*                  }||u r-|�t-        |j/                  |«      «      –— nt-        |«      –— n|j
                  sŒÜ|j0                  }|j
                  s�ŒJyy# t        $ r Y �Œw xY w# t        $ r Y Œ7w xY w­w)av  Yields all flat polygon faces from the given :class:`Lump` entity as
    sequence of :class:`~ezdxf.math.Vec3` instances. Applies the transformation
    :class:`~ezdxf.math.Matrix44` `m` to all vertices if not ``None``.

    Args:
        lump: :class:`Lump` entity
        m: optional transformation matrix

    Raises:
        TypeError: `lump` has invalid ACIS type

    úexpected a lump entity, got: Nzplane-surfacezstraight-curve)r   r   r   r   Úshellr+   r$   r   ÚclearÚsurfaceÚloopÚcoedgeÚAttributeErrorÚedgeÚcurveÚsenser   Ú
end_vertexÚpointÚlocationÚstart_vertexÚnext_coedgeÚtupleÚtransform_verticesÚ	next_face)r)   r0   r3   Úverticesr$   Úfirst_coedger7   r9   s           r%   r.   r.   Q   sz  è ø€ ô �dœDÔ!ÜÐ7¼¸T»
°|ÐDÓEÐEà�J‰J€EØ‡}‚}ØØ€HØ�:‰:€DØ�l‹lÜˆØ�‰ÔØ�<‰<×Ñ Ò/ðØ#Ÿy™y×/Ñ/�ð ˆØ—.’.à—;‘;ˆDðà—:‘:—?‘?Ð&6Ò6Øà—<’<Ø—O‘O D§O¡O×$9Ñ$9×$BÑ$BÕCà—O‘O D×$5Ñ$5×$;Ñ$;×$DÑ$DÔEð
 ×'Ñ'ˆFØ˜Ñ%Ø�=Ü × 4Ñ 4°XÓ >Ó?Ó?ä ›/Ò)Øð- —.“.ð. �~‰~ˆðA �lŽløô "ò Úðûô "ò ñ ðüsh   ‚BG	ÂF* Â$G	Â?F: ÃG	ÃA+F: ÅA	G	ÆG	Æ(G	Æ*	F7Æ3G	Æ6F7Æ7G	Æ:	GÇG	ÇGÇG	c                ó¤  — | j                  |«      } t        «       }t        | j                  «      }|j                  j
                  sX| j                  |j                   «       t        j                  «       }t        j                  |j                  Ž |_
        ||_        | j                  «       D ]  } t        | «      }|j                  |«       Œ  |S )a#  Returns a :term:`ACIS` :class:`~ezdxf.acis.entities.Body` entity from a
    :class:`~ezdxf.render.MeshBuilder` instance.

    This entity can be assigned to a :class:`~ezdxf.entities.Solid3d` DXF entity
    as :term:`SAT` or :term:`SAB` data according to the version your DXF
    document uses (SAT for DXF R2000 to R2010 and SAB for DXF R2013 and later).

    If the `mesh` contains multiple separated meshes, each mesh will be a
    separated :class:`~ezdxf.acis.entities.Lump` node.
    If each mesh should get its own :class:`~ezdxf.acis.entities.Body` entity,
    separate the meshes beforehand by the method
    :meth:`~ezdxf.render.MeshBuilder.separate_meshes`.

    A closed mesh creates a solid body and an open mesh creates an open (hollow)
    shell. The detection if the mesh is open or closed is based on the edges
    of the mesh: if **all** edges of mesh have two adjacent faces the mesh is
    closed.

    The current implementation applies automatically a vertex optimization,
    which merges coincident vertices into a single vertex.

    )Úoptimize_verticesr   r   rD   ÚcenterÚis_nullÚ	translater   Ú	Transformr   r,   r*   Úseparate_meshesÚlump_from_meshÚappend_lump)ÚmeshÚ	precisionr   Úbboxr*   r)   s         r%   Úbody_from_meshrR   ‹   s¦   € ð. ×!Ñ! )Ó,€DÜ‹6€DÜ�t—}‘}Ó%€DØ�;‰;×ÒØ�‰˜Ÿ™�|Ô$Ü×&Ñ&Ó(ˆ	Ü#×-Ñ-¨t¯{©{Ð;ˆ	ÔØ"ˆŒà×$Ñ$Ö&ˆÜ˜dÓ#ˆØ×Ñ˜Õð 'ð €Kr'   c                ó²   — t        «       }t        «       }|j                  |«       t        | «      }|j	                  «       D ]  }|j                  |«       Œ |S )z¡Returns a :class:`~ezdxf.acis.entities.Lump` entity from a
    :class:`~ezdxf.render.MeshBuilder` instance. The `mesh` has to be a single
    body or shell!
    )r   r   Úappend_shellÚPolyhedronFaceBuilderÚ
acis_facesÚappend_face)rO   r)   r3   Úface_builderr$   s        r%   rM   rM   ±   sP   € ô
 ‹6€DÜ‹G€EØ×Ñ�eÔÜ(¨Ó.€LØ×'Ñ'Ö)ˆØ×Ñ˜$Õð *à€Kr'   c                  óZ   — e Zd Zd
d„Zd„ Zdd„Zdd„Zdd„Zdd„Z	 	 	 	 	 	 	 	 dd„Z	dd„Z
y	)rU   c                óL  — |j                  «       }|j                  «        |j                  | _        |j                  | _        t	        |j                  «       «      | _        g | _        |j                  «       j                  | _
        t        «       | _        t        «       | _        y ©N)ÚcopyÚnormalize_facesrD   r#   r-   Úface_normalsÚnormalsÚacis_verticesÚdiagnoseÚis_edge_balance_brokenÚdouble_sidedÚdictÚpartner_coedgesÚedges)ÚselfrO   Ú	mesh_copys      r%   Ú__init__zPolyhedronFaceBuilder.__init__À   s~   € Ø—I‘I“Kˆ	Ø×!Ñ!Ô#Ø$-×$6Ñ$6ˆŒØ*3¯/©/ˆŒ
Ü˜I×2Ñ2Ó4Ó5ˆŒØ46ˆÔð &×.Ñ.Ó0×GÑGˆÔô HLÃvˆÔÜ;?»6ˆ�
r'   c                ó²   — t        t        | j                  «      «      | _        | j                  j                  «        | j                  j                  «        y r[   )r-   Úmake_verticesrD   r`   re   r4   rf   )rg   s    r%   ÚresetzPolyhedronFaceBuilder.reset×   s:   € Ü!¤-°·±Ó">Ó?ˆÔØ×Ñ×"Ñ"Ô$Ø�
‰
×ÑÕr'   c                óˆ  — | j                  «        g }t        | j                  | j                  «      D ]Œ  \  }}|j                  rŒt        «       }| j                  |«      }|€Œ1||_        | j                  |«      }|€ŒL|j                  |«       ||_
        d|_        | j                  |_        |j                  |«       ŒŽ |S )NF)rl   Úzipr#   r_   rI   r   Ú
make_planeÚnormalÚ	make_loopÚappend_loopr5   r;   rc   r   )rg   r#   r$   Úface_normalÚ	acis_faceÚplaner6   s          r%   rV   z PolyhedronFaceBuilder.acis_facesÜ   s²   € Ø�
‰
ŒØˆÜ!$ T§Z¡Z°·±Ö!>ÑˆD�+Ø×"Ò"ØÜ›ˆIØ—O‘O DÓ)ˆEØˆ}ØØ&ˆEŒLØ—>‘> $Ó'ˆDØˆ|ØØ×!Ñ! $Ô'Ø %ˆIÔØ#ˆIŒOØ%)×%6Ñ%6ˆIÔ"Ø�L‰L˜Õ#ð "?ð$ ˆr'   c                ó  — t        |«      dkD  sJ d«       ‚t        j                  «       }d|_        | j                  |d      |_        	 | j                  |d      |j
                  z
  j                  «       |_        |S # t        $ r Y y w xY w)Nr   zface requires least 2 verticesFr   )	Úlenr   ÚPlaneÚ	reverse_vrD   ÚoriginÚ	normalizeÚu_dirÚZeroDivisionError)rg   r$   ru   s      r%   ro   z PolyhedronFaceBuilder.make_planeó   s…   € Ü�4‹y˜1Š}Ð>Ð>Ó>ˆ}Ü—‘Ó ˆàˆŒØ—}‘} T¨!¡WÑ-ˆŒð	ØŸ=™=¨¨a©Ñ1°E·L±LÑ@×KÑKÓMˆEŒKð ˆøô !ò 	Ùð	ús   Á	2A= Á=	B	ÂB	c                ó`  — g }t        |dd  «      }|d   |d   k7  r|j                  |d   «       t        ||«      D ]H  \  }}| j                  ||«      }| j	                  |||«      \  |_        |_        |j                  |«       ŒJ t        j                  «       }|j                  |d¬«       |S )Nr   r   éÿÿÿÿT)Úclose)
r-   r   rn   Úmake_coedgeÚ	make_edger9   r;   r   ÚLoopÚset_coedges)rg   r$   ÚcoedgesÚface2Úi1Úi2r7   r6   s           r%   rq   zPolyhedronFaceBuilder.make_loopÿ   s©   € Ø)+ˆÜ�T˜!˜"�X“ˆØ�‰7�d˜2‘hÒØ�L‰L˜˜a™Ô!ä˜$ Ö&‰FˆB�Ø×%Ñ% b¨"Ó-ˆFØ(,¯©°r¸2¸vÓ(FÑ%ˆFŒK˜œØ�N‰N˜6Õ"ð 'ô �}‰}‹ˆØ×Ñ˜¨ÐÔ-Øˆr'   c                óÊ   — ||kD  r||f}n||f}t        j                  «       }	 | j                  |   }|j                  |«       |S # t        $ r || j                  |<   Y |S w xY wr[   )r   ÚCoedgere   Úadd_partner_coedgeÚKeyError)rg   Úindex1Úindex2Úkeyr7   Úpartner_coedges         r%   r�   z!PolyhedronFaceBuilder.make_coedge  sy   € Ø�FŠ?Ø˜&�.‰Cà˜&�.ˆCÜ—‘Ó"ˆð	6Ø!×1Ñ1°#Ñ6ˆNð ×-Ñ-¨fÔ5Øˆøô	 ò 	/Ø(.ˆD× Ñ  Ò%ð ˆð		/ús   ¤A ÁA"Á!A"c                óº  ‡ ‡— dˆˆ fd„}d}|}|}||kD  rd}||}}	 ‰ j                   ||f   |fS # t        $ r Y nw xY wt        j                  «       Š|‰_        d‰_         ||«      ‰_        d‰_         ||«      ‰_        ‰ j                  |   j                  ‰ j                  |   «      ‰_        ‰ j                  ||«      ‰_        ‰‰ j                   ||f<   ‰|fS )Nc                óŠ   •— ‰j                   |    }|xj                  dz  c_        |j                  j                  r‰|_        |S )Nr   )r`   Ú	ref_countr9   r+   )ÚindexÚvertexr9   rg   s     €€r%   Úmake_vertexz4PolyhedronFaceBuilder.make_edge.<locals>.make_vertex  s=   ø€ Ø×'Ñ'¨Ñ.ˆFØ×Ò Ñ!Õà�{‰{×"Ò"Ø"�”ØˆMr'   FTg        )r”   Úint)rf   rŒ   r   ÚEdger7   r;   r?   Ústart_paramr<   rD   ÚdistanceÚ	end_paramÚmake_rayr:   )	rg   r�   rŽ   Úparentr–   r;   Úex1Úex2r9   s	   `       @r%   r‚   zPolyhedronFaceBuilder.make_edge  së   ù€ ö	ð ˆØˆØˆØ�Š9ØˆEØ˜C�ˆCð	Ø—:‘:˜c 3˜hÑ'¨Ð.Ð.øÜò 	Ùð	úô �}‰}‹ˆØˆŒØˆŒ
Ù'¨Ó,ˆÔØˆÔÙ% cÓ*ˆŒØŸ™ sÑ+×4Ñ4°T·]±]À3Ñ5GÓHˆŒØ—]‘] 3¨Ó,ˆŒ
Ø#ˆ�
‰
�3˜�8ÑØ�Uˆ{Ðs   œ/ ¯	;º;c                óà   — | j                   |   }| j                   |   }t        j                  «       }||_        	 ||z
  j	                  «       |_        |S # t        $ r t        |_        Y |S w xY wr[   )rD   r   ÚStraightCurverz   r{   Ú	directionr}   r   )rg   r�   rŽ   Úv1Úv2Úrays         r%   rœ   zPolyhedronFaceBuilder.make_ray=  sp   € Ø�]‰]˜6Ñ"ˆØ�]‰]˜6Ñ"ˆÜ×$Ñ$Ó&ˆØˆŒ
ð	$Ø "™W×/Ñ/Ó1ˆCŒMð ˆ
øô !ò 	$Ü#ˆC�MØˆ
ð	$ús   »A ÁA-Á,A-N)rO   r
   )Úreturnz
list[Face])r$   úSequence[int]r¦   zOptional[entities.Plane])r$   r§   r¦   zOptional[entities.Loop])r�   r—   rŽ   r—   r¦   úentities.Coedge)r�   r—   rŽ   r—   r�   r¨   r¦   ztuple[entities.Edge, bool])r�   r—   rŽ   r—   r¦   zentities.StraightCurve)Ú__name__Ú
__module__Ú__qualname__ri   rl   rV   ro   rq   r�   r‚   rœ   © r'   r%   rU   rU   ¿   sL   „ óBò.ó
ó.
óóð Øð Ø#&ð Ø0?ð à	#ó ôD	r'   rU   c              #  óŽ   K  — | D ]<  }t        j                  «       }||_        t        j                  «       }||_        |–— Œ> y ­wr[   )r   ÚPointr>   ÚVertexr=   )rD   Úvr=   r•   s       r%   rk   rk   I  s;   è ø€ ÛˆÜ—‘Ó ˆØˆŒÜ—‘Ó"ˆØˆŒØ‹ñ ùs   ‚AAc                ó<  — t        | t        «      st        dt        | «      › �«      ‚| j                  }| j
                  }g }d}|j                  s|j                  }|j                  s4|j                  t        ||«      «       |j                  }|j                  sŒ4|S )a  Returns all stored vertices in the given :class:`Body` entity.
    The result is not optimized, meaning the vertices are in no particular order and
    there are duplicates.

    This function can be useful to determining the approximate bounding box of an 
    :term:`ACIS` entity.  The result is exact for polyhedra with flat faces with 
    straight edges, but not for bodies with curved edges and faces.

    Args:
        body: ACIS entity of type :class:`Body`

    Raises:
        TypeError: given `body` entity has invalid type

    r   N)r   r   r   r   r)   r*   r+   r,   ÚextendÚvertices_from_lumpr/   )r   r)   r*   rD   r0   s        r%   Úvertices_from_bodyr´   R  s‰   € ô" �dœDÔ!ÜÐ7¼¸T»
°|ÐDÓEÐEØ�9‰9€DØ—‘€IØ€Hà €AØ×ÒØ×ÑˆØ�lŠlØ�‰Ô*¨4°Ó3Ô4Ø�~‰~ˆð �l‹lð €Or'   c                óÊ  — t        | t        «      st        dt        | «      › �«      ‚g }| j                  }|j
                  r|S |j                  }|j
                  sÍt        }	 |j                  j                  }|}|j
                  s‰|j                  }	 |j                  |j                  j                  j                  «       |j                  |j                   j                  j                  «       |j"                  }||u rn|j
                  sŒ‰|j$                  }|j
                  sŒÍ|�t'        |j)                  |«      «      S |S # t        $ r Y ŒÙw xY w# t        $ r Y ŒQw xY w)aA  Returns all stored vertices from a given :class:`Lump` entity. 
    Applies the transformation :class:`~ezdxf.math.Matrix44` `m` to all vertices if not 
    ``None``.

    Args:
        lump: :class:`Lump` entity
        m: optional transformation matrix

    Raises:
        TypeError: `lump` has invalid ACIS type

    r2   )r   r   r   r   r3   r+   r$   r   r6   r7   r8   r9   r   r?   r=   r>   r<   r@   rC   r-   rB   )r)   r0   rD   r3   r$   rE   r7   r9   s           r%   r³   r³   r  s>  € ô �dœDÔ!ÜÐ7¼¸T»
°|ÐDÓEÐEà€HØ�J‰J€EØ‡}‚}Øˆà�:‰:€DØ�lŠlÜˆð	ØŸ9™9×+Ñ+ˆLð ˆØ—.’.à—;‘;ˆDðØ—‘ × 1Ñ 1× 7Ñ 7× @Ñ @ÔAØ—‘ §¡× 5Ñ 5× >Ñ >Ô?ð
 ×'Ñ'ˆFØ˜Ñ%Øð —.“.ð �~‰~ˆð) �l‹lð* 	€}Ü�A×(Ñ(¨Ó2Ó3Ð3Ø€Oøô' ò 	Ùð	ûô "ò ñ ðús%   Á#E ÂAE Å	EÅEÅ	E"Å!E")T)r   r   r¦   zlist[MeshTransformer])r   r   r¦   zIterator[list[Sequence[Vec3]]]r[   )r)   r   r0   úMatrix44 | Noner¦   zIterator[Sequence[Vec3]])é   )rO   r
   rP   r—   r¦   r   )rO   r
   r¦   r   )rD   zIterable[Vec3]r¦   zIterator[entities.Vertex])r   r   r¦   ú
list[Vec3])r)   r   r0   r¶   r¦   r¸   ) Ú
__future__r   Útypingr   r   r   r   Úezdxf.renderr   r	   r
   Ú
ezdxf.mathr   r   r   r   Ú r   r   r   r   r   r   r&   r   r.   rR   rM   rU   rk   r´   r³   r¬   r'   r%   Ú<module>r¾      s‹   ðõ #ß 9Ó 9ß GÑ Gß ;Ó ;Ý ß 7Õ 7ô'ðTØ
ðà#óð: &*ð7Ø
ð7Ø"ð7àó7ôt#óL÷Gñ GóTóõ@-r'   