
    hW                        S SK Jr  S SKJrJrJrJrJr  S SKr\(       a  S SK	J
r
  SS/r S     SS jjr S     SS jjrSS	 jr        SS
 jrg)    )annotations)TYPE_CHECKINGIterableUnionMappingOptionalN)
DXFGraphic	ascending
descendingc                X    U(       a  [        U5      O0 n[        XS5      n[        U5      $ )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      ?/var/www/html/env/lib/python3.13/site-packages/ezdxf/reorder.pyr
   r
      '    $  'd7mBG(R(D4=    c                X    U(       a  [        U5      O0 n[        XS5      n[        U5      $ )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              #  d   #    U (       a%  [         R                  " U 5      S   v   U (       a  M$  gg7f)zYields heap content in order.r   N)heapqheappop)r   s    r   r   r   ;   s#     
mmD!"%% $s   *00c                   ^ SU4S jjn/ n[        U 5       H*  u  pV[        R                  " UU" U5      U-  XR-  U45        M,     U$ )zReturns a heap structure.

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

c                |   > U R                   R                  n[        TR                  X5      S5      nU(       a  U$ S$ )N   l    )dxfhandleintget)entityr"   sort_handle_r   s      r   sort_handle_build.<locals>.sort_handleM   s7    ""7;;v6;  ,|C1CCr   )r%   r	   returnr#   )	enumerater   heappush)r   r   orderr'   r   indexr%   s    `     r   r   r   A   sS    D /1D"8, 	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>r4      s    # D D )
%
 AE"= 2 AE"= .&#"#-4#=@#&#r   