
    Og                        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y)    )annotations)TYPE_CHECKINGIterableOptionalN)disassemble)BoundingBox)	DXFEntityc                  R    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y	)CachezyCaching object for :class:`ezdxf.math.BoundingBox` objects.

    Args:
        uuid: use UUIDs for virtual entities

    c                ^    t               | _        t        |      | _        d| _        d| _        y )Nr   )dict_boxesbool	_use_uuidhitsmisses)selfuuids     O/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/bbox.py__init__zCache.__init__   s$    .2fd	    c                ,    t        | j                        S N)r   r   r   s    r   has_datazCache.has_data   s    DKK  r   c                h    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__"   s;    s4;;'( )II; kk]!%	
r   c                    |J | j                  |      }|| xj                  dz  c_        y | j                  j                  |      }|| xj                  dz  c_        |S | xj                  dz  c_        |S )N   )_get_keyr   r   getr   )r   entitykeyboxs       r   r#   z	Cache.get)   sr    !!!mmF#;KK1Kkkooc";KK1K 
 IINI
r   c                R    |J | j                  |      }|y || j                  |<   y r   )r"   r   )r   r$   r&   r%   s       r   storezCache.store6   s2    !!!mmF#;Cr   c                j    |D ]  }	 | j                   | j                  |      = ! y# t        $ r Y .w xY w)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   entitiesr$   s      r   
invalidatezCache.invalidate=   sA      	FKKf 56	  s   &	22c                    |j                         dk(  ry |j                  j                  }||dk(  r#| j                  rt	        |j
                        S d S |S )NHATCH0)dxftypedxfhandler   strr   )r   r$   r%   s      r   r"   zCache._get_keyM   sO    >>w&
 jj;#*'+~~3v{{#?4?Jr   N)F)returnNone)r4   r   )r$   r	   r4   zOptional[BoundingBox])r$   r	   r&   r   r4   r5   )r+   Iterable[DXFEntity]r4   r5   )r$   r	   r4   zOptional[str])__name__
__module____qualname____doc__r   propertyr   r   r#   r(   r,   r"    r   r   r   r      s9     ! !
 r   r   Ffastcachec             #  r  K   t        j                  |       }t        j                  |      }|D ]  }|j                  r|j                  }|D|j                  |      }|C|j                  |      }|j                  r%|j                  ||       n|j                  |      }|j                  s|  yw)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>   r?   flat_entities
primitives	primitiver$   r&   s           r   multi_recursiverH   \   s       33H=M**=9J 	!!))F#C{nn$n/<<KK,..d.+C<<Is   B-B70B7c               b    t               }t        | ||      D ]  }|j                  |        |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>   r?   _extendsr&   s        r   extentsrM      s4     }H(U; Or   c             #     K   dfd}| D ]G  }d}rj                  |      }| ||g      }rj                  ||       |j                  sD| I yw)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.

    c                d    t               }t        |       D ]  }|j                  |        |S )Nr=   )r   rH   rK   )	entities_rL   _boxr?   r>   s      r   extends_zmulti_flat.<locals>.extends_   s3    =#IDF 	"DOOD!	"r   N)rP   r6   r4   r   )r#   r(   r   )r+   r>   r?   rR   r$   r&   s    ``   r   rJ   rJ      sa       ))F#C;F8$CFC(<<Is   AAA)r+   r6   r?   Optional[Cache]r4   zIterable[BoundingBox])r+   r6   r?   rS   r4   r   )
__future__r   typingr   r   r   ezdxfr   
ezdxf.mathr   ezdxf.entitiesr	   	Primitivemax_flattening_distanceMAX_FLATTENING_DISTANCEr   rH   rM   rJ   r<   r   r   <module>r\      s    # 4 4   "(%//GG I I^ 
!	 !  	 
  L 
!	! 	
 * 
!	! 	
 r   