a
    i‚jO	  ã                   @   s,   d Z ddlmZ dd„ ZG dd„ deƒZdS )z’Selection-buffer handling code

This code is resonsible for turning gluint *
arrays into structured representations for use
by Python-level code.
é    )Úinteger_typesc                 C   s   | dk r| d@ d } | S )Nr   iÿÿÿl        © )Úvaluer   r   úQ/home/ghrups/robot-bench/.venv/lib/python3.9/site-packages/OpenGL/GL/selection.pyÚ
uintToLong	   s    r   c                   @   sD   e Zd ZdZedƒZdZdd„ ZeeƒZdd„ Z	dd	„ Z
d
d„ ZdS )ÚGLSelectRecorda³  Minimalist object for storing an OpenGL selection-buffer record
    
    Provides near and far as *float* values by dividing by 
    self.DISTANCE_DIVISOR (2**32-1)
    From the spec:
        Depth values (which are in the range [0,1]) are multiplied by 
        2^32 - 1, before being placed in the hit record.
    
    Names are unmodified, so normally are slices of the array passed in 
    to GLSelectRecord.fromArray( array )
    l   ÿÿ )ÚnearÚfarÚnamesc                 C   s’   g }d}t |ƒ}t|ƒD ]t}|d |kr, qŽ|| }||d  }||d  }	dd„ ||d |d | … D ƒ}
| | ||	|
ƒ¡ |d| 7 }q|S )z,Produce list with all records from the arrayr   é   é   c                 S   s   g | ]}t |ƒ‘qS r   )r   )Ú.0Úvr   r   r   Ú
<listcomp>(   ó    z,GLSelectRecord.fromArray.<locals>.<listcomp>é   )ÚlenÚrangeÚappend)ÚclsÚarrayÚtotalÚresultÚindexZarrayLengthÚitemÚcountr   r	   r
   r   r   r   Ú	fromArray   s    "zGLSelectRecord.fromArrayc                 C   s"   |   |¡| _|   |¡| _|| _dS )zInitialise/store the valuesN)ÚconvertDistancer   r	   r
   )Úselfr   r	   r
   r   r   r   Ú__init__.   s    zGLSelectRecord.__init__c                 C   s   t |ƒ| j S )z?Convert a distance value from array uint to 0.0-1.0 range float)r   ÚDISTANCE_DIVISOR)r   r   r   r   r   r   3   s    zGLSelectRecord.convertDistancec              
   C   sp   t |tƒr| j| j| jf| S || jv rlzt| |ƒW S  tyj } ztd|| j	f ƒ‚W Y d}~n
d}~0 0 dS )z.Allow for treating the record as a three-tuplez)Don't have an index/key %r for %s instantN)
Ú
isinstancer   r   r	   r
   Ú	__slots__ÚgetattrÚAttributeErrorÚKeyErrorÚ	__class__)r   ÚkeyÚerrr   r   r   Ú__getitem__6   s    

ÿzGLSelectRecord.__getitem__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úfloatr    r"   r   Úclassmethodr   r   r)   r   r   r   r   r      s   r   N)r-   ZOpenGL._bytesr   r   Úobjectr   r   r   r   r   Ú<module>   s   