Ë
    :vžj®  ã                   ó”   — d dl mZ d dlmZ d dlmZ ddlmZmZm	Z	m
Z
 dede
e	z  fd„Zd	ee   ez  d
z  dee   fd„Z G d„ de«      Zy
)é    )ÚOrderedDict)Úlog2)ÚAnyé   )ÚCallableÚIterableÚNDArrayÚSequenceÚ	operationÚitemsc           
      óÚ  — t        |«      dk(  ryt        |«      dk(  r|d   S t        |«      dk(  r | |d   |d   «      S t        t        dt        t        |«      «      z   «      «      D ]l  }g }t        |«      dz  }t        dt        |«      |z
  d«      D ]#  }|j	                   | ||   ||dz      «      «       Œ% |dk7  r|j	                  |d   «       |}Œn t        «      dk(  sJ ‚|d   S )af  
    Call an operation function in a cascaded pairwise way against a
    flat list of items.

    This should produce the same result as `functools.reduce`
    if `operation` is commutable like addition or multiplication.
    This may be faster for an `operation` that runs with a speed
    proportional to its largest input, which mesh booleans appear to.

    The union of a large number of small meshes appears to be
    "much faster" using this method.

    This only differs from `functools.reduce` for commutative `operation`
    in that it returns `None` on empty inputs rather than `functools.reduce`
    which raises a `TypeError`.

    For example on `a b c d e f g` this function would run and return:
        a b
        c d
        e f
        ab cd
        ef g
        abcd efg
     -> abcdefg

    Where `functools.reduce` would run and return:
        a b
        ab c
        abc d
        abcd e
        abcde f
        abcdef g
     -> abcdefg

    Parameters
    ----------
    operation
      The function to call on pairs of items.
    items
      The flat list of items to apply operation against.
    r   Nr   é   éÿÿÿÿ)ÚlenÚrangeÚintr   Úappend)r   r   Ú_ÚresultsÚ	items_modÚis         úb/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/iteration.pyÚreduce_cascader      sô   € ôT ˆ5ƒz�Q‚ØÜ	ˆU‹�qŠà�Q‰xˆÜ	ˆU‹�qŠá˜˜q™ 5¨¡8Ó,Ð,ä”3�qœ4¤ E£
Ó+Ñ+Ó,Ö-ˆØˆô ˜“J ‘Nˆ	Ü�qœ#˜e›* yÑ0°!Ö4ˆAØ�N‰N™9 U¨1¡X¨u°Q¸±U©|Ó<Õ=ð 5ð
 ˜Š>Ø�N‰N˜5 ™9Ô%à‰ð .ô  ˆw‹<˜1ÒÐÐà�1‰:Ðó    ÚargsNÚreturnc                  ó¼   — g }| D �cg c]H  }|�Dt        |d«      r't        |t        t        f«      s|j	                  |«      n|j                  |«      ‘ŒJ c} |S c c}w )aø  
    A less principled version of `list(itertools.chain(*args))` that
    accepts non-iterable values, filters `None`, and returns a list
    rather than yielding values.

    If all passed values are iterables this will return identical
    results to `list(itertools.chain(*args))`.


    Examples
    ----------

    In [1]: list(itertools.chain([1,2], [3]))
    Out[1]: [1, 2, 3]

    In [2]: trimesh.util.chain([1,2], [3])
    Out[2]: [1, 2, 3]

    In [3]: trimesh.util.chain([1,2], [3], 4)
    Out[3]: [1, 2, 3, 4]

    In [4]: list(itertools.chain([1,2], [3], 4))
      ----> 1 list(itertools.chain([1,2], [3], 4))
      TypeError: 'int' object is not iterable

    In [5]: trimesh.util.chain([1,2], None, 3, None, [4], [], [], 5, [])
    Out[5]: [1, 2, 3, 4, 5]


    Parameters
    -----------
    args
      Will be individually checked to see if they're iterable
      before either being appended or extended to a flat list.


    Returns
    ----------
    chained
      The values in a flat list.
    Ú__iter__)ÚhasattrÚ
isinstanceÚstrÚbytesÚextendr   )r   ÚchainedÚas      r   Úchainr&   P   so   € ðV €Gñ ó	ñ ˆAØˆ=ô �A�zÔ"¬:°a¼#¼u¸Ô+Fð 	�‰�qÔà�^‰^˜AÓñ	ð ò	ð €Nùòs   ‡AAc                   óZ   ‡ — e Zd ZdZˆ fd„Zˆ fd„Zd„ ZexZxZxZ	Z
dˆ fd„Zdefd„Zˆ xZS )	ÚIndexedDictaŠ  
    An append-only `OrderedDict` which knows what position a key was inserted at.

    Useful anywhere values are referenced by *position* but keyed by content so
    duplicates are only stored once: the only other spelling is
    `list(d.keys()).index(key)`, which allocates every key and scans it, i.e.
    quadratic. Looking up the position of all `n` keys once each:

        n       list(keys()).index()      this class
        2000          0.061s                0.00007s
        4000          0.262s                0.00012s
        8000          1.135s                0.00026s

    Removing or reordering a key would shift the position of every key after it,
    so `__delitem__`, `pop`, `popitem`, and `move_to_end` raise: the supported
    way to remove is `clear` followed by `update`.

    Examples
    ----------

    In [1]: IndexedDict({"a": 1, "b": 2, "c": 3}).index("c")
    Out[1]: 2
    c                 ó2   •— i | _         t        ‰| �  |i |¤Ž y ©N)Ú	_positionÚsuperÚ__init__)Úselfr   ÚkwargsÚ	__class__s      €r   r-   zIndexedDict.__init__£   s   ø€ àˆŒÜ‰Ñ˜$Ð) &Ó)r   c                 ó^   •— || vrt        | «      | j                  |<   t        ‰| �  ||«       y r*   )r   r+   r,   Ú__setitem__)r.   ÚkeyÚvaluer0   s      €r   r2   zIndexedDict.__setitem__¨   s+   ø€ Ø�d‰?Ü"% d£)ˆD�N‰N˜3ÑÜ‰Ñ˜C Õ'r   c                 ó   — t        d«      ‚)Nz6`IndexedDict` is append-only: use `clear` and `update`)Ú	TypeError)r.   r   r/   s      r   Ú
_forbiddenzIndexedDict._forbidden­   s   € ÜÐPÓQÐQr   r   c                 óV   •— t         ‰| �  «        | j                  j                  «        y r*   )r,   Úclearr+   )r.   r0   s    €r   r9   zIndexedDict.clear³   s   ø€ Ü‰‰ŒØ�‰×ÑÕr   c                 ó    — | j                   |   S )zJ
        Which position in insertion order was `key` inserted at.
        )r+   )r.   r3   s     r   ÚindexzIndexedDict.index·   s   € ð �~‰~˜cÑ"Ð"r   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r-   r2   r7   Ú__delitem__ÚpopÚpopitemÚmove_to_endr9   r   r;   Ú__classcell__)r0   s   @r   r(   r(   ‡   s?   ø„ ñô6*ô
(ò
Rð 1;Ð:€KÐ:�#Ð:˜ +õð#˜C÷ #r   r(   )Úcollectionsr   Úmathr   Útypingr   Útypedr   r   r	   r
   r   Úlistr&   r(   © r   r   Ú<module>rK      sb   ðÝ #Ý Ý ç 8Ó 8ðE˜hð E¨x¸'Ñ/Aó EðP4�˜#‘ Ñ$ tÑ+ð 4°°S±	ó 4ôn4#�+õ 4#r   