
    Ti                         d dl mZ ddlmZmZmZmZmZmZm	Z	 dede	eef         fdZ
de	ee         edf         d	ee         fd
ZdS )    )log2   )AnyCallableIterableListNDArraySequenceUnion	operationitemsc           
      |   t          |          dk    rdS t          |          dk    r|d         S t          |          dk    r | |d         |d                   S t          t          dt          t          |                    z                       D ]}g }t          |          dz  }t          dt          |          |z
  d          D ]0}|                     | ||         ||dz                                 1|dk    r|                    |d                    |}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         K/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/iteration.pyreduce_cascader      s@   T 5zzQt	UqQx	Uqyq58,,,3q4E

+++,,--   JJN	q#e**y0!44 	> 	>ANN99U1XuQU|<<==== >>NN59%%% w<<11:    argsNreturnc                  (    g fd| D              S )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.
    c                     g | ]Z}|t          |d          r1t          |t          t          f          s                    |          n                    |          [S )N__iter__)hasattr
isinstancestrbytesextendr   ).0achaineds     r   
<listcomp>zchain.<locals>.<listcomp>{   sm        = Az""	+5a#u+F+F	q^^A==r    )r   r(   s    @r   chainr+   N   s?    V G    	    Nr   )mathr   typedr   r   r   r   r	   r
   r   r   r+   r*   r   r   <module>r.      s          J J J J J J J J J J J J J J J J J JEh EuXw5F/G E E E EP4x}c4/0 4T#Y 4 4 4 4 4 4r   