
    j
                     `    d Z ddlZddlmZmZmZ dedee   dee   fdZdd	ed
edee   fdZ	y)zk
interval.py
--------------

Deal with 1D intervals which are defined by:
  [start position, end position]
    N   )	ArrayLikeNDArrayfloat64abreturnc                 *   t        j                  | t         j                        } t        j                  |t         j                        }| j                  dk(  }| j	                  d      } |j	                  d      }| j                  d       |j                  d       | j                  \  }}|j                  \  }}t        j                  t        j                  ||k\  ||k\              }t        j                  | j                  t         j                        }t        j                  t        j                  ||   ||   g      j                  d      t        j                  ||   ||   g      j                  d      f      ||<   |r|d   S |S )a  
    Given pairs of ranges merge them in to
    one range if they overlap.

    Parameters
    --------------
    a : (2, ) or (n, 2)
      Start and end of a 1D interval
    b : (2, ) float
      Start and end of a 1D interval

    Returns
    --------------
    inter : (2, ) or (2, 2) float
      The unioned range from the two inputs,
      if not np.ptp(`inter, axis=1)` will be zero.
    )dtype)   )r   r   axisr   )nparrayr   shapereshapesortTlogical_not
logical_orzeroscolumn_stackmaxmin)	r   r   is_1Da_lowa_highb_lowb_highcheckoverlaps	            =/DATA/.local/lib/python3.12/site-packages/trimesh/interval.pyintersectionr$      sA   $ 	"**%A
"**%A GGtOE			'A			'A FFFNFFFNCCME6CCME6 NN2==&%6/JKEhhqwwbjj1G__HHeElE%L1266A6>HHfUmVE]3488a8@	
GEN qzN    	intervalsr   c                    t        |       dk(  rt        j                  d      S |r1t        j                  | d      } | | dddf   j	                            } | d   j                         g}| dd D ]<  \  }}|d   d   |k\  rt        |d   d   |      |d   d<   *|j                  ||g       > t        j                  |      S )a&  
    For array of multiple intervals union them all into
    the subset of intervals.

    For example:
    `intervals = [[1,2], [2,3]] -> [[1, 3]]`
    `intervals = [[1,2], [2.5,3]] -> [[1, 2], [2.5, 3]]`


    Parameters
    ------------
    intervals : (n, 2)
      Pairs of `(min, max)` values.
    sort
      If the array is already ordered into (min, max) pairs
      and then pairs sorted by minimum value you can skip the
      sorting in this function.

    Returns
    ----------
    unioned : (m, 2)
      New intervals where `m <= n`
    r   r   r   Nr   )	lenr   r   r   argsorttolistr   appendr   )r&   r   unionsbeginends        r#   unionr/   >   s    0 9~xx{ GGIA.	i1o5578	 l!!#$Fm
s":a=E!r
1s3F2JqMMM5#,'	 $ 88Fr%   )T)
__doc__numpyr   typedr   r   r   r$   boolr/    r%   r#   <module>r5      sY     . .-I -''"2 -ww7G -`,Y ,d ,gg6F ,r%   