
    'j&                        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dS )    )annotations)OptionalN)Vec2intersection_line_line_2dUVec   )is_point_left_of_line	TOLERANCE)BoundingBox2d)ConstructionRayConstructionLineParallelRaysErrorc                      e Zd ZdS )r   N)__name__
__module____qualname__     I/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/math/line.pyr   r      s        Dr   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dS ).r   zConstruction 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``

    Np1r   p2Optional[UVec]angleOptional[float]c                   t          |          | _        |  |  |  |  |  |  |yt          |          }| j        j        |j        k     r"|| j        z
                                  | _        n!| j        |z
                                  | _        | j        j        | _        n2|!|| _        t          j        |          | _        nt          d          t          | j        j                  t          k    rd | _        d | _        nD| j        j        | j        j        z  | _        | j        j        | j        | j        j        z  z
  | _        | j        d u | _        t          | j        j                  t          k    | _        d S )Nzp2 or angle required.)r   	_locationx	normalize
_directionr   _angle
from_angle
ValueErrorabsABS_TOL_slope_yof0y_is_vertical_is_horizontal)selfr   r   r   p2_s        r   __init__zConstructionRay.__init__"   sT    b$$#!>r((C~#%''#&#7"B"B"D"D#'>C#7"B"B"D"D//DKKDK"oe44DOO4555t !!W,,DKDJJ/+do.??DK)DK$.:J,JJDJ K4/!$/"344?r   returnr   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!   r1   s    r   	directionzConstructionRay.directionH   s     r   c                    | j         S )z%Slope of ray or ``None`` if vertical.)r'   r1   s    r   slopezConstructionRay.slopeM   s     {r   floatc                6    | j         | j        j        S | j         S )z(Angle between x-axis and ray in radians.)r"   r!   r   r1   s    r   r   zConstructionRay.angleR   s     ;?((;r   c                4    t          j        | j                  S )z(Angle between x-axis and ray in degrees.)mathdegreesr   r1   s    r   	angle_degzConstructionRay.angle_degZ   s     |DJ'''r   boolc                    | j         S )z1``True`` if ray is vertical (parallel to y-axis).)r*   r1   s    r   is_verticalzConstructionRay.is_vertical_   s       r   c                    | j         S )z3``True`` if ray is horizontal (parallel to x-axis).)r+   r1   s    r   is_horizontalzConstructionRay.is_horizontald   s     ""r   strc                ,    d                     |           S )NzQConstructionRay(p1=({0.location.x:.3f}, {0.location.y:.3f}), angle={0.angle:.5f})formatr1   s    r   __repr__zConstructionRay.__repr__i   s    ##)6$<<	
r   otherc                    | j         r|j         S |j         rdS | j        r|j        S t          j        | j        |j        t
                    S )z&Returns ``True`` if rays are parallel.Fabs_tol)r*   r+   r:   iscloser'   r&   r,   rG   s     r   is_parallelzConstructionRay.is_parallelo   sU     	&%% 	5 	(''|DKwGGGGr   c                t   | }|}|                     |          rt          d          |j        r6|j        j        }|j        r|j        j        }n|                    |          }n|j        r6|j        j        }|j        r|j        j        }n|                    |          }n|j        r"|j        j        }|	                    |          }n]|j        r"|j        j        }|	                    |          }n4|j
        |j
        z
  |j        |j        z
  z  }|                    |          }t          ||f          S )zReturns the intersection point as ``(x, y)`` tuple of `self` and
        `other`.

        Raises:
             ParallelRaysError: if rays are parallel

        zRays are parallel)rM   r   r*   r   r   rA   r)   yofr+   xofr(   r'   r   )r,   rG   ray1ray2r   r)   s         r   	intersectzConstructionRay.intersectz   s6    D!! 	9#$7888 	 A!  N$HHQKK 	 A!  N$HHQKK  	 AAA  	 AAA
 dj(T[4;-FGAAQF||r   r2   c                >    t          || j        t          z             S )z%Returns orthogonal ray at `location`.r   )r   r   HALF_PI)r,   r2   s     r   
orthogonalzConstructionRay.orthogonal   s    xtzG/CDDDDr   r   c                \    | j         rt          | j        t          |          | j        z  z   S )zrReturns y-value of ray for `x` location.

        Raises:
            ArithmeticError: for vertical rays

        )r*   ArithmeticErrorr(   r7   r'   )r,   r   s     r   rO   zConstructionRay.yof   s/      	"!!zE!HHt{222r   r)   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+   r7   r(   r'   rY   )r,   r)   s     r   rP   zConstructionRay.xof   sE      	">##$ 	"!HHtz)T[88!!r   c                r    |                      |          }| j        |j        z   dz  }t          ||          S )z%Bisectrix between `self` and `other`.r   rU   )rS   r   r   )r,   rG   intersectionalphas       r   	bisectrixzConstructionRay.bisectrix   s9    ~~e,,ek)S0|59999r   )NN)r   r   r   r   r   r   r/   r   )r/   r   r/   r7   r/   r=   r/   rB   )rG   r   r/   r=   )rG   r   r/   r   )r2   r   r/   r   )r   r7   r/   r7   )r)   r7   r/   r7   )rG   r   r/   r   )r   r   r   __doc__r.   propertyr2   r4   r6   r   r<   r?   rA   rF   rM   rS   rW   rO   rP   r^   r   r   r   r   r      s         MQ@ @ @ @ @B    X    X    X    X ( ( ( X( ! ! ! X! # # # X#
 
 
 
	H 	H 	H 	H% % % %NE E E E
3 
3 
3 
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d0d-d#Zd$S )1r   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

    startr   endc                V    t          |          | _        t          |          | _        d S Nr   rf   rg   )r,   rf   rg   s      r   r.   zConstructionLine.__init__   s     %[[
99r   r/   rB   c                ,    d                     |           S )Nz$ConstructionLine({0.start}, {0.end})rD   r1   s    r   rF   zConstructionLine.__repr__   s    5<<TBBBr   r   c                8    t          | j        | j        f          S )z6bounding box of line as :class:`BoundingBox2d` object.)r   rf   rg   r1   s    r   bounding_boxzConstructionLine.bounding_box   s     dj$(3444r   dxr7   dyNonec                f    t          ||          }| xj        |z  c_        | xj        |z  c_        dS )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

        Nrj   )r,   rn   ro   vs       r   	translatezConstructionLine.translate   s3     RLL

a

Ar   c                Z    | j         | j        k    r| j        | j         fn| j         | j        fS ri   )rf   rg   r1   s    r   sorted_pointszConstructionLine.sorted_points   s5     zDH$$ Xtz""*dh'	
r   c                6    t          | j        | j                  S )z#collinear :class:`ConstructionRay`.)r   rf   rg   r1   s    r   rayzConstructionLine.ray   s     tz48444r   rG   objectr=   c                    t          |t                    st          t          |                    | j        |j        k    S ri   
isinstancer   	TypeErrortyperu   rL   s     r   __eq__zConstructionLine.__eq__   s:    %!122 	)DKK(((!U%888r   c                    t          |t                    st          t          |                    | j        |j        k     S ri   rz   rL   s     r   __lt__zConstructionLine.__lt__   s:    %!122 	)DKK(((!E$777r   c                *    | j         | j        z
  j        S )zReturns length of line.)rg   rf   	magnituder1   s    r   lengthzConstructionLine.length  s    4:%00r   r   c                @    | j                             | j                  S )zReturns mid point of line.)rf   lerprg   r1   s    r   midpointzConstructionLine.midpoint  s    ztx(((r   c                T    t          j        | j        j        | j        j                  S )z``True`` if line is vertical.)r:   rK   rf   r   rg   r1   s    r   r?   zConstructionLine.is_vertical       |DJL$(*555r   c                T    t          j        | j        j        | j        j                  S )z``True`` if line is horizontal.)r:   rK   rf   r)   rg   r1   s    r   rA   zConstructionLine.is_horizontal  r   r   pointc                6    | j                             |          S )z;Returns ``True`` if `point` is inside of line bounding box.)rm   inside)r,   r   s     r   inside_bounding_boxz$ConstructionLine.inside_bounding_box  s     ''...r   rJ   Optional[Vec2]c                X    t          | j        | j        f|j        |j        fd|          S )zReturns 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)virtualrJ   )r   rf   rg   r,   rG   rJ   s      r   rS   zConstructionLine.intersect  s9     )Z"[%)$	
 
 
 	
r   c                4    |                      ||          duS )z7Returns ``True`` if has intersection with `other` line.rI   N)rS   r   s      r   has_intersectionz!ConstructionLine.has_intersection+  s     ~~eW~55TAAr   Fc                <    t          || j        | j        |          S )zReturns ``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	   rf   rg   )r,   r   r   s      r   r	   z&ConstructionLine.is_point_left_of_line1  s(     %4:tx(
 
 
 	
r   N)rf   r   rg   r   rb   )r/   r   )rn   r7   ro   r7   r/   rp   )rG   rx   r/   r=   r`   r_   ra   )r   r   r/   r=   )rG   r   rJ   r7   r/   r   )rG   r   rJ   r7   r/   r=   )F)r   r   r   rc   r.   rF   rd   rm   rs   ru   rw   r~   r   r   r   r?   rA   r   r
   rS   r   r	   r   r   r   r   r      s       
 
   C C C C 5 5 5 X5    
 
 X
 5 5 X59 9 9 9
8 8 8 8
1 1 1 1) ) ) ) 6 6 6 X6 6 6 6 X6/ / / /
 9B
 
 
 
 
& 9BB B B B B	
 	
 	
 	
 	
 	
 	
r   r   )
__future__r   typingr   r:   
ezdxf.mathr   r   r   construct2dr	   r
   bboxr   __all__rY   r   pirV   THREE_PI_HALF	DOUBLE_PIr&   r   r   r   r   r   <module>r      sI   # " " " " "        < < < < < < < < < < 9 9 9 9 9 9 9 9       G
F
F	 	 	 	 	 	 	 	 'C-dgGcM	
k: k: k: k: k: k: k: k:\t
 t
 t
 t
 t
 t
 t
 t
 t
 t
r   