Ë
    £èhé'  ã                  óø   — d dl mZ d dlmZ d dlZd dlmZmZmZ ddl	m
Z
mZ ddlmZ g d¢Z G d	„ d
e«      Zej"                  dz  Zdej"                  z  Zej"                  dz  ZdZ G d„ d«      Z G d„ d«      Zy)é    )Úannotations)ÚOptionalN)ÚVec2Úintersection_line_line_2dÚUVecé   )Úis_point_left_of_lineÚ	TOLERANCE)ÚBoundingBox2d)ÚConstructionRayÚConstructionLineÚParallelRaysErrorc                  ó   — e Zd Zy)r   N)Ú__name__Ú
__module__Ú__qualname__© ó    ú/lib/python3.12/site-packages/ezdxf/math/line.pyr   r      s   „ Ør   r   ç       @g      ø?gê-�™—q=c                  óÜ   — e Zd ZdZ	 d	 	 	 	 	 dd„Zedd„«       Zedd„«       Zedd„«       Zedd„«       Z	edd„«       Z
edd	„«       Zedd
„«       Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zy)r   zÇConstruction tool for infinite 2D rays.

    Args:
        p1: definition point 1
        p2: ray direction as 2nd point or ``None``
        angle: ray direction as angle in radians or ``None``

    Nc                ó„  — t        |«      | _        |  |  |  |  |  |  |��t        |«      }| j                  j                  |j                  k  r#|| j                  z
  j                  «       | _        n"| j                  |z
  j                  «       | _        | j                  j
                  | _        n/|�"|| _        t        j                  |«      | _        nt        d«      ‚t        | j                  j                  «      t        k  rd | _        d | _        nq| j                  j                  | j                  j                  z  | _        | j                  j                  | j                  | j                  j                  z  z
  | _        | j                  d u | _        t        | j                  j                  «      t        k  | _        y )Nzp2 or angle required.)r   Ú	_locationÚxÚ	normalizeÚ
_directionÚangleÚ_angleÚ
from_angleÚ
ValueErrorÚabsÚABS_TOLÚ_slopeÚ_yof0ÚyÚ_is_verticalÚ_is_horizontal)ÚselfÚp1Úp2r   Úp2_s        r   Ú__init__zConstructionRay.__init__"   sL  € ô ˜b›ˆŒÙÙÙÙÙÙàˆ>Ü�r“(ˆCØ�~‰~×Ñ #§%¡%Ò'Ø#&¨¯©Ñ#7×"BÑ"BÓ"D�•à#'§>¡>°CÑ#7×"BÑ"BÓ"D�”ØŸ/™/×/Ñ/ˆD�KØÐØˆDŒKÜ"Ÿo™o¨eÓ4ˆD�OäÐ4Ó5Ð5äˆt�‰× Ñ Ó!¤WÒ,ØˆDŒKØˆD�JàŸ/™/×+Ñ+¨d¯o©o×.?Ñ.?Ñ?ˆDŒKØŸ™×)Ñ)¨D¯K©K¸$¿.¹.×:JÑ:JÑ,JÑJˆDŒJØ ŸK™K¨4Ð/ˆÔÜ! $§/¡/×"3Ñ"3Ó4¼Ñ?ˆÕr   c                ó   — | j                   S )z!Location vector as :class:`Vec2`.)r   ©r(   s    r   ÚlocationzConstructionRay.locationC   s   € ð �~‰~Ðr   c                ó   — | j                   S )z"Direction vector as :class:`Vec2`.)r   r.   s    r   Ú	directionzConstructionRay.directionH   s   € ð �‰Ðr   c                ó   — | j                   S )z%Slope of ray or ``None`` if vertical.)r#   r.   s    r   ÚslopezConstructionRay.slopeM   s   € ð �{‰{Ðr   c                ó^   — | j                   €| j                  j                  S | j                   S )z(Angle between x-axis and ray in radians.)r   r   r   r.   s    r   r   zConstructionRay.angleR   s(   € ð �;‰;ÐØ—?‘?×(Ñ(Ð(à—;‘;Ðr   c                ó@   — t        j                  | j                  «      S )z(Angle between x-axis and ray in degrees.)ÚmathÚdegreesr   r.   s    r   Ú	angle_degzConstructionRay.angle_degZ   s   € ô �|‰|˜DŸJ™JÓ'Ð'r   c                ó   — | j                   S )z1``True`` if ray is vertical (parallel to y-axis).)r&   r.   s    r   Úis_verticalzConstructionRay.is_vertical_   s   € ð × Ñ Ð r   c                ó   — | j                   S )z3``True`` if ray is horizontal (parallel to x-axis).)r'   r.   s    r   Úis_horizontalzConstructionRay.is_horizontald   s   € ð ×"Ñ"Ð"r   c                ó$   — dj                  | «      S )NzQConstructionRay(p1=({0.location.x:.3f}, {0.location.y:.3f}), angle={0.angle:.5f})©Úformatr.   s    r   Ú__repr__zConstructionRay.__repr__i   s   € ð#ß#)¡6¨$£<ð	
r   c                óÜ   — | j                   r|j                   S |j                   ry| j                  r|j                  S t        j                  | j                  |j                  t
        ¬«      S )z&Returns ``True`` if rays are parallel.F©Úabs_tol)r&   r'   r6   Úiscloser#   r"   ©r(   Úothers     r   Úis_parallelzConstructionRay.is_parallelo   sS   € à×ÒØ×%Ñ%Ð%Ø×ÒØØ×ÒØ×'Ñ'Ð'ä�|‰|˜DŸK™K¨¯©¼wÔGÐGr   c                ó  — | }|}|j                  |«      rt        d«      ‚|j                  rM|j                  j                  }|j
                  r|j                  j                  }�n|j                  |«      }�n|j                  rK|j                  j                  }|j
                  r|j                  j                  }n¾|j                  |«      }n¬|j                  r(|j                  j                  }|j                  |«      }nx|j                  r(|j                  j                  }|j                  |«      }nD|j                  |j                  z
  |j                  |j                  z
  z  }|j                  |«      }t        ||f«      S )z¡Returns the intersection point as ``(x, y)`` tuple of `self` and
        `other`.

        Raises:
             ParallelRaysError: if rays are parallel

        zRays are parallel)rG   r   r&   r   r   r<   r%   Úyofr'   Úxofr$   r#   r   )r(   rF   Úray1Úray2r   r%   s         r   Ú	intersectzConstructionRay.intersectz   s-  € ð ˆØˆØ×Ñ˜DÔ!Ü#Ð$7Ó8Ð8à×ÒØ—‘× Ñ ˆAØ×!Ò!Ø—N‘N×$Ñ$’à—H‘H˜Q“K’Ø×ÒØ—‘× Ñ ˆAØ×!Ò!Ø—N‘N×$Ñ$‘à—H‘H˜Q“K‘Ø× Ò Ø—‘× Ñ ˆAØ—‘˜“‰AØ× Ò Ø—‘× Ñ ˆAØ—‘˜“‰Að
 —‘˜dŸj™jÑ(¨T¯[©[¸4¿;¹;Ñ-FÑGˆAØ—‘˜“ˆAÜ�Q˜�F‹|Ðr   c                ó>   — t        || j                  t        z   ¬«      S )z%Returns orthogonal ray at `location`.©r   )r   r   ÚHALF_PI)r(   r/   s     r   Ú
orthogonalzConstructionRay.orthogonal¡   s   € ä˜x¨t¯z©z¼GÑ/CÔDÐDr   c                óp   — | j                   rt        ‚| j                  t        |«      | j                  z  z   S )zrReturns y-value of ray for `x` location.

        Raises:
            ArithmeticError: for vertical rays

        )r&   ÚArithmeticErrorr$   Úfloatr#   )r(   r   s     r   rI   zConstructionRay.yof¥   s/   € ð ×ÒÜ!Ð!à�z‰zœE !›H t§{¡{Ñ2Ñ2Ð2r   c                ó´   — | j                   r| j                  j                  S | j                  s%t	        |«      | j
                  z
  | j                  z  S t        ‚)ztReturns x-value of ray for `y` location.

        Raises:
            ArithmeticError: for horizontal rays

        )r&   r   r   r'   rT   r$   r#   rS   )r(   r%   s     r   rJ   zConstructionRay.xof±   sH   € ð ×ÒØ—>‘>×#Ñ#Ð#Ø×$Ò$Ü˜!“H˜tŸz™zÑ)¨T¯[©[Ñ8Ð8ä!Ð!r   c                óv   — | j                  |«      }| j                  |j                  z   dz  }t        ||¬«      S )z%Bisectrix between `self` and `other`.r   rO   )rM   r   r   )r(   rF   ÚintersectionÚalphas       r   Ú	bisectrixzConstructionRay.bisectrix¿   s4   € à—~‘~ eÓ,ˆØ—‘˜eŸk™kÑ)¨SÑ0ˆÜ˜|°5Ô9Ð9r   )NN)r)   r   r*   zOptional[UVec]r   úOptional[float]©Úreturnr   )r\   rZ   ©r\   rT   ©r\   Úbool©r\   Ústr)rF   r   r\   r_   )rF   r   r\   r   )r/   r   r\   r   )r   rT   r\   rT   )r%   rT   r\   rT   )rF   r   r\   r   )r   r   r   Ú__doc__r,   Úpropertyr/   r1   r3   r   r8   r:   r<   r@   rG   rM   rQ   rI   rJ   rY   r   r   r   r   r      sâ   „ ñð MQð@Øð@Ø*ð@Ø:Ió@ðB òó ðð òó ðð òó ðð òó ðð ò(ó ð(ð ò!ó ð!ð ò#ó ð#ó
ó	Hó%óNEó
3ó"ô:r   r   c                  óÜ   — e Zd ZdZdd„Zdd„Zedd„«       Zdd„Zed„ «       Z	ed„ «       Z
dd„Zdd	„Zdd
„Zdd„Zedd„«       Zedd„«       Zdd„Zef	 	 	 	 	 dd„Zef	 	 	 	 	 dd„Zddd„Zy)r   a¡  Construction tool for 2D lines.

    The :class:`ConstructionLine` class is similar to :class:`ConstructionRay`,
    but has a start- and endpoint. The direction of line goes from start- to
    endpoint, "left of line" is always in relation to this line direction.

    Args:
        start: start point of line as :class:`Vec2` compatible object
        end: end point of line as :class:`Vec2` compatible object

    c                óD   — t        |«      | _        t        |«      | _        y ©N©r   ÚstartÚend)r(   rh   ri   s      r   r,   zConstructionLine.__init__Ó   s   € Ü˜%“[ˆŒ
Ü˜“9ˆ�r   c                ó$   — dj                  | «      S )Nz$ConstructionLine({0.start}, {0.end})r>   r.   s    r   r@   zConstructionLine.__repr__×   s   € Ø5×<Ñ<¸TÓBÐBr   c                óD   — t        | j                  | j                  f«      S )z6bounding box of line as :class:`BoundingBox2d` object.)r   rh   ri   r.   s    r   Úbounding_boxzConstructionLine.bounding_boxÚ   s   € ô ˜dŸj™j¨$¯(©(Ð3Ó4Ð4r   c                óp   — t        ||«      }| xj                  |z  c_        | xj                  |z  c_        y)z¦
        Move line about `dx` in x-axis and about `dy` in y-axis.

        Args:
            dx: translation in x-axis
            dy: translation in y-axis

        Nrg   )r(   ÚdxÚdyÚvs       r   Ú	translatezConstructionLine.translateß   s)   € ô ��R‹LˆØ�
Š
�a‰�
Ø�Š�A‰Žr   c                ó”   — | j                   | j                  kD  r| j                  | j                   fS | j                   | j                  fS rf   )rh   ri   r.   s    r   Úsorted_pointszConstructionLine.sorted_pointsì   sB   € ð �z‰z˜DŸH™HÒ$ð �X‰X�t—z‘zÐ"ð	
ð —*‘*˜dŸh™hÐ'ð	
r   c                óB   — t        | j                  | j                  «      S )z#collinear :class:`ConstructionRay`.)r   rh   ri   r.   s    r   ÚrayzConstructionLine.rayô   s   € ô ˜tŸz™z¨4¯8©8Ó4Ð4r   c                ó|   — t        |t        «      st        t        |«      «      ‚| j                  |j                  k(  S rf   ©Ú
isinstancer   Ú	TypeErrorÚtypers   rE   s     r   Ú__eq__zConstructionLine.__eq__ù   s3   € Ü˜%Ô!1Ô2ÜœD ›KÓ(Ð(Ø×!Ñ! U×%8Ñ%8Ñ8Ð8r   c                ó|   — t        |t        «      st        t        |«      «      ‚| j                  |j                  k  S rf   rw   rE   s     r   Ú__lt__zConstructionLine.__lt__þ   s3   € Ü˜%Ô!1Ô2ÜœD ›KÓ(Ð(Ø×!Ñ! E×$7Ñ$7Ñ7Ð7r   c                óH   — | j                   | j                  z
  j                  S )zReturns length of line.)ri   rh   Ú	magnituder.   s    r   ÚlengthzConstructionLine.length  s   € à—‘˜4Ÿ:™:Ñ%×0Ñ0Ð0r   c                óL   — | j                   j                  | j                  «      S )zReturns mid point of line.)rh   Úlerpri   r.   s    r   ÚmidpointzConstructionLine.midpoint  s   € à�z‰z�‰˜tŸx™xÓ(Ð(r   c                ó~   — t        j                  | j                  j                  | j                  j                  «      S )z``True`` if line is vertical.)r6   rD   rh   r   ri   r.   s    r   r:   zConstructionLine.is_vertical  ó%   € ô �|‰|˜DŸJ™JŸL™L¨$¯(©(¯*©*Ó5Ð5r   c                ó~   — t        j                  | j                  j                  | j                  j                  «      S )z``True`` if line is horizontal.)r6   rD   rh   r%   ri   r.   s    r   r<   zConstructionLine.is_horizontal  r…   r   c                ó8   — | j                   j                  |«      S )z;Returns ``True`` if `point` is inside of line bounding box.)rl   Úinside)r(   Úpoints     r   Úinside_bounding_boxz$ConstructionLine.inside_bounding_box  s   € à× Ñ ×'Ñ'¨Ó.Ð.r   c                óx   — t        | j                  | j                  f|j                  |j                  fd|¬«      S )zàReturns the intersection point of to lines or ``None`` if they have
        no intersection point.

        Args:
            other: other :class:`ConstructionLine`
            abs_tol: tolerance for distance check

        F)ÚvirtualrC   )r   rh   ri   ©r(   rF   rC   s      r   rM   zConstructionLine.intersect  s7   € ô )Ø�Z‰Z˜Ÿ™Ð"Ø�[‰[˜%Ÿ)™)Ð$ØØô	
ð 	
r   c                ó,   — | j                  ||¬«      duS )z7Returns ``True`` if has intersection with `other` line.rB   N)rM   r�   s      r   Úhas_intersectionz!ConstructionLine.has_intersection+  s   € ð �~‰~˜e¨Wˆ~Ó5¸TÐAÐAr   c                óH   — t        || j                  | j                  |¬«      S )zÎReturns ``True`` if `point` is left of construction line in relation
        to the line direction from start to end.

        If `colinear` is ``True``, a colinear point is also left of the line.

        )Úcolinear)r	   rh   ri   )r(   r‰   r‘   s      r   r	   z&ConstructionLine.is_point_left_of_line1  s"   € ô %Ø�4—:‘:˜tŸx™x°(ô
ð 	
r   N)rh   r   ri   r   r`   )r\   r   )rn   rT   ro   rT   r\   ÚNone)rF   Úobjectr\   r_   r]   r[   r^   )r‰   r   r\   r_   )rF   r   rC   rT   r\   zOptional[Vec2])rF   r   rC   rT   r\   r_   )F)r   r   r   rb   r,   r@   rc   rl   rq   rs   ru   r{   r}   r€   rƒ   r:   r<   rŠ   r
   rM   r�   r	   r   r   r   r   r   Æ   sã   „ ñ
óóCð ò5ó ð5óð ñ
ó ð
ð ñ5ó ð5ó9ó
8ó
1ó)ð ò6ó ð6ð ò6ó ð6ó/ð
 9Bð
Ø%ð
Ø05ð
à	ó
ð& 9BðBØ%ðBØ05ðBà	óBõ	
r   r   )Ú
__future__r   Útypingr   r6   Ú
ezdxf.mathr   r   r   Úconstruct2dr	   r
   Úbboxr   Ú__all__rS   r   ÚpirP   ÚTHREE_PI_HALFÚ	DOUBLE_PIr"   r   r   r   r   r   Ú<module>r�      sw   ðõ #Ý Û ß <Ñ <ß 9Ý ò G€ô	˜ô 	ð �'‰'�C‰-€Ø�d—g‘g‘€Ø�G‰G�c‰M€	Ø
€÷k:ñ k:÷\t
ò t
r   