
    Og&                        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__     T/var/www/html/public_html/myphp/venv/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   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``

    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////DKDK"ooe4DO455t  !W,DKDJ//++doo.?.??DK))DKK$..:J:J,JJDJ KK4/!$//"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     ||DJJ''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    %%%'''||DKK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 )zReturns 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!!NN$$HHQK  A!!NN$$HHQK    AA    AA
 djj(T[[4;;-FGA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    xtzzG/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/     !!zzE!Ht{{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     >>###$$!Htzz)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,ekk)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     djj$((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)     RL

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     zzDHH$ XXtzz"	
 **dhh'	
r   c                B    t        | j                  | j                        S )z#collinear :class:`ConstructionRay`.)r   rh   ri   r.   s    r   rayzConstructionLine.ray   s     tzz488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    zztxx((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  %     ||DJJLL$((**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 )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)virtualrC   )r   rh   ri   r(   rF   rC   s      r   rM   zConstructionLine.intersect  s7     )ZZ"[[%))$	
 	
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     ~~eW~5TAAr   c                H    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	   rh   ri   )r(   r   r   s      r   r	   z&ConstructionLine.is_point_left_of_line1  s"     %4::txx(
 	
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-dggGGcM	
k: k:\t
 t
r   