
    OgW                        d dl mZ d dlmZmZmZmZmZ d dlZerd dl	m
Z
 ddgZ	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZdd	Z	 	 	 	 	 	 	 	 dd
Zy)    )annotations)TYPE_CHECKINGIterableUnionMappingOptionalN)
DXFGraphic	ascending
descendingc                P    |rt        |      ni }t        | |d      }t        |      S )a%  Yields entities in ascending handle order.

    The sort-handle doesn't have to be the entity handle, every entity handle
    in `mapping` will be replaced by the given sort-handle, `mapping` is an
    iterable of 2-tuples (entity_handle, sort_handle) or a
    dict (entity_handle, sort_handle). Entities with equal sort-handles show
    up in source entities order.

    Args:
        entities: iterable of :class:`DXFGraphic` objects
        mapping: iterable of 2-tuples (entity_handle, sort_handle) or a
            handle mapping as dict.

       dict_build_sortedentitiesmappingheaps      R/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/reorder.pyr
   r
      )    $  'd7mBG(GR(D4=    c                P    |rt        |      ni }t        | |d      }t        |      S )a/  Yields entities in descending handle order.

    The sort-handle doesn't have to be the entity handle, every entity handle
    in `mapping` will be replaced by the given sort-handle, `mapping` is an
    iterable of 2-tuples (entity_handle, sort_handle) or a
    dict (entity_handle, sort_handle). Entities with equal sort-handles show
    up in reversed source entities order.

    Args:
        entities: iterable of :class:`DXFGraphic` objects
        mapping: iterable of 2-tuples (entity_handle, sort_handle) or a
            handle mapping as dict.

    r   r   s      r   r   r   $   r   r   c              #  L   K   | rt        j                  |       d    | ryyw)zYields heap content in order.r   N)heapqheappop)r   s    r   r   r   ;   s"     
mmD!"%% s   $$c                    dfd}g }t        |       D ]*  \  }}t        j                  | ||      |z  ||z  |f       , |S )zReturns a heap structure.

    Args:
        entities: DXF entities to order
        mapping: handle remapping
        order: +1 for ascending, -1 for descending

    c                t    | j                   j                  }t        j                  ||      d      }|r|S dS )N   l    )dxfhandleintget)entityr"   sort_handle_r   s      r   sort_handlez_build.<locals>.sort_handleM   s9    ""7;;vv6;  ,|C1CCr   )r%   r	   returnr#   )	enumerater   heappush)r   r   orderr'   r   indexr%   s    `     r   r   r   A   s\    D /1D"8, 
v 	F#e+	
	
 Kr   )N)r   Iterable[DXFGraphic]r   z0Optional[Union[dict, Iterable[tuple[str, str]]]]r(   r-   )r(   r-   )r   r-   r   r   r+   r#   r(   z!list[tuple[int, int, DXFGraphic]])
__future__r   typingr   r   r   r   r   r   ezdxf.entitiesr	   __all__r
   r   r   r    r   r   <module>r3      s    # D D )
%
 AE"= 2 AE"= .&#"#-4#=@#&#r   