
    'j                        d dl mZ d dlmZmZmZ d dlZd dlmZ d dlm	Z	 erd dl
mZ ej        j        Z G d d          Zd	dd
ddZd	dd
ddZd	dd
ddZdS )    )annotations)TYPE_CHECKINGIterableOptionalN)disassemble)BoundingBox)	DXFEntityc                  Z    e Zd ZdZdddZedd            Zd ZddZddZ	ddZ
ddZdS )CachezyCaching object for :class:`ezdxf.math.BoundingBox` objects.

    Args:
        uuid: use UUIDs for virtual entities

    FreturnNonec                p    t                      | _        t          |          | _        d| _        d| _        d S )Nr   )dict_boxesbool	_use_uuidhitsmisses)selfuuids     D/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/bbox.py__init__zCache.__init__   s,    .2ffd	    r   c                *    t          | j                  S N)r   r   r   s    r   has_datazCache.has_data   s    DK   r   c                R    dt          | j                   d| j         d| j         dS )NzCache(n=z, hits=z	, misses=))lenr   r   r   r   s    r   __str__zCache.__str__"   sE    %s4;'' % %I% %k% % %	
r   entityr	   Optional[BoundingBox]c                    |J |                      |          }|| xj        dz  c_        d S | j                            |          }|| xj        dz  c_        n| xj        dz  c_        |S )N   )_get_keyr   r   getr   )r   r"   keyboxs       r   r'   z	Cache.get)   sw    !!!mmF##;KK1KK4kooc"";KK1KKKIINII
r   r)   r   c                T    |J |                      |          }|d S || j        |<   d S r   )r&   r   )r   r"   r)   r(   s       r   storezCache.store6   s;    !!!mmF##;FCr   entitiesIterable[DXFEntity]c                h    |D ].}	 | j         |                     |          = # t          $ r Y +w xY wdS )a+  Invalidate cache entries for the given DXF `entities`.

        If entities are changed by the user, it is possible to invalidate
        individual entities. Use with care - discarding the whole cache is
        the safer workflow.

        Ignores entities which are not stored in cache.

        N)r   r&   KeyError)r   r,   r"   s      r   
invalidatezCache.invalidate=   s[      	 	FKf 5 566   	 	s   "
//Optional[str]c                    |                                 dk    rd S |j        j        }||dk    r| j        rt	          |j                  nd S |S )NHATCH0)dxftypedxfhandler   strr   )r   r"   r(   s      r   r&   zCache._get_keyM   sV    >>w&&
 4j;#**'+~?3v{###4?Jr   N)F)r   r   )r   r   )r"   r	   r   r#   )r"   r	   r)   r   r   r   )r,   r-   r   r   )r"   r	   r   r1   )__name__
__module____qualname____doc__r   propertyr   r!   r'   r+   r0   r&    r   r   r   r      s              ! ! ! X!
 
 
               r   r   Ffastcacher,   r-   rA   Optional[Cache]r   Iterable[BoundingBox]c             #  ^  K   t          j        |           }t          j        |          }|D ]}|j        r
|j        }|K|                    |          }|3|                    |          }|j        r|                    ||           n|                    |          }|j        r|V  dS )u  Yields all bounding boxes for the given `entities` **or** all bounding
    boxes for their sub entities. If an entity (INSERT) has sub entities, only
    the bounding boxes of these sub entities will be yielded, **not** the
    bounding box of the entity (INSERT) itself.

    If argument `fast` is ``True`` the calculation of Bézier curves is based on
    their control points, this may return a slightly larger bounding box.

    N)r@   )	r   recursive_decomposeto_primitivesis_emptyr"   r'   bboxr   r+   )r,   r@   rA   flat_entities
primitives	primitiver"   r)   s           r   multi_recursiverL   \   s        3H==M*=99J  	 	!))F##C{nn$n//< -KK,,,..d.++C< 	III r   r   c               v    t                      }t          | ||          D ]}|                    |           |S )u   Returns a single bounding box for all given `entities`.

    If argument `fast` is ``True`` the calculation of Bézier curves is based on
    their control points, this may return a slightly larger bounding box.

    r?   )r   
multi_flatextend)r,   r@   rA   _extendsr)   s        r   extentsrQ      sE     }}H(U;;;  Or   c             #     K   dfd}| D ]L}d}r                     |          }|$ ||g          }r                    ||           |j        r|V  MdS )u   Yields a bounding box for each of the given `entities`.

    If argument `fast` is ``True`` the calculation of Bézier curves is based on
    their control points, this may return a slightly larger bounding box.

    	entities_r-   r   r   c                x    t                      }t          |           D ]}|                    |           |S )Nr?   )r   rL   rO   )rS   rP   _boxrA   r@   s      r   extends_zmulti_flat.<locals>.extends_   sD    ==#IDFFF 	" 	"DOOD!!!!r   N)rS   r-   r   r   )r'   r+   r   )r,   r@   rA   rV   r"   r)   s    ``   r   rN   rN      s                	$))F##C;(F8$$C )FC(((< 	III r   )r,   r-   rA   rB   r   rC   )r,   r-   rA   rB   r   r   )
__future__r   typingr   r   r   ezdxfr   
ezdxf.mathr   ezdxf.entitiesr	   	Primitivemax_flattening_distanceMAX_FLATTENING_DISTANCEr   rL   rQ   rN   r>   r   r   <module>r_      s8   # " " " " " 4 4 4 4 4 4 4 4 4 4        " " " " " " )((((((%/G I I I I I I I I^ 
!	           L 
!	     * 
!	       r   