
    'jW                    v    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dS )    )annotations)TYPE_CHECKINGIterableUnionMappingOptionalN)
DXFGraphic	ascending
descendingentitiesIterable[DXFGraphic]mapping0Optional[Union[dict, Iterable[tuple[str, str]]]]returnc                h    |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r   r   heaps      G/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/reorder.pyr
   r
      5    $  '.d7mmmBG(GR((D4==    c                h    |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              #  N   K   | r t          j        |           d         V  | dS dS )zYields heap content in order.r   N)heapqheappop)r   s    r   r   r   ;   sG      
 &mD!!"%%%%  & & & & &r   r   orderint!list[tuple[int, int, DXFGraphic]]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

    entityr	   r   r"   c                p    | j         j        }t                              ||          d          }|r|ndS )N   l    )dxfhandler"   get)r%   r)   sort_handle_r   s      r   sort_handlez_build.<locals>.sort_handleM   s<    "7;;vv66;;  ,C||1CCr   )r%   r	   r   r"   )	enumerater   heappush)r   r   r!   r,   r   indexr%   s    `     r   r   r   A   s    D D D D D D /1D"8,, 
 
v 	F##e+	
 	
 	
 	
 Kr   )N)r   r   r   r   r   r   )r   r   )r   r   r   r   r!   r"   r   r#   )
__future__r   typingr   r   r   r   r   r   ezdxf.entitiesr	   __all__r
   r   r   r    r   r   <module>r5      s    # " " " " " D D D D D D D D D D D D D D  *))))))
%
 AE    2 AE    .& & & &# # # # # #r   