
    h&                        S SK Jr  S SKJr  S SKrS SKJrJrJr  SSK	J
r
Jr  SSKJr  / SQr " S	 S
\5      r\R"                  S-  rS\R"                  -  r\R"                  S-  rSr " S S5      r " S S5      rg)    )annotations)OptionalN)Vec2intersection_line_line_2dUVec   )is_point_left_of_line	TOLERANCE)BoundingBox2d)ConstructionRayConstructionLineParallelRaysErrorc                      \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r       A/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/line.pyr   r      s    r   r          @g      ?g-q=c                     \ rS rSrSr S     SS jjr\SS j5       r\SS j5       r\SS j5       r	\SS j5       r
\SS	 j5       r\SS
 j5       r\SS j5       rSS jrSS jrSS jrSS jrSS jrSS jrS S jrSrg)!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                   [        U5      U l        U   U   U   U   U   U   Ub  [        U5      nU R                  R                  UR                  :  a"  X@R                  -
  R                  5       U l        O"U R                  U-
  R                  5       U l        U R                  R
                  U l        O0Ub"  X0l        [         R                  " U5      U l        O[        S5      e[        U R                  R                  5      [        ::  a  S U l        S U l        OqU R                  R                  U R                  R                  -  U l        U R                  R                  U R                  U R                  R                  -  -
  U l        U R                  S L U l        [        U R                  R                  5      [        :*  U l        g )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__ConstructionRay.__init__"   sH    b>r(C~~#%%'#&#7"B"B"D#'>>C#7"B"B"D////DKK"ooe4DO455t  !W,DKDJ//++doo.?.??DK))DKK$..:J:J,JJDJ KK4/!$//"3"34?r   c                    U R                   $ )z!Location vector as :class:`Vec2`.)r   r,   s    r   locationConstructionRay.locationC   s     ~~r   c                    U R                   $ )z"Direction vector as :class:`Vec2`.)r    r3   s    r   	directionConstructionRay.directionH   s     r   c                    U R                   $ )z%Slope of ray or ``None`` if vertical.)r'   r3   s    r   slopeConstructionRay.slopeM   s     {{r   c                `    U R                   c  U R                  R                  $ U R                   $ )z(Angle between x-axis and ray in radians.)r"   r    r!   r3   s    r   r!   ConstructionRay.angleR   s(     ;;??(((;;r   c                B    [         R                  " U R                  5      $ )z(Angle between x-axis and ray in degrees.)mathdegreesr!   r3   s    r   	angle_degConstructionRay.angle_degZ   s     ||DJJ''r   c                    U R                   $ )z1``True`` if ray is vertical (parallel to y-axis).)r*   r3   s    r   is_verticalConstructionRay.is_vertical_   s        r   c                    U R                   $ )z3``True`` if ray is horizontal (parallel to x-axis).)r+   r3   s    r   is_horizontalConstructionRay.is_horizontald   s     """r   c                $    SR                  U 5      $ )NzQConstructionRay(p1=({0.location.x:.3f}, {0.location.y:.3f}), angle={0.angle:.5f})formatr3   s    r   __repr__ConstructionRay.__repr__i   s    ##)6$<	
r   c                    U R                   (       a  UR                   $ UR                   (       a  gU R                  (       a  UR                  $ [        R                  " U R                  UR                  [
        S9$ )z&Returns ``True`` if rays are parallel.Fabs_tol)r*   r+   r?   iscloser'   r&   r,   others     r   is_parallelConstructionRay.is_parallelo   sS    %%%'''||DKKwGGr   c                X   U nUnUR                  U5      (       a  [        S5      eUR                  (       aR  UR                  R                  nUR
                  (       a  UR                  R                  nGO*UR                  U5      nGOUR                  (       aP  UR                  R                  nUR
                  (       a  UR                  R                  nOUR                  U5      nOUR                  (       a(  UR                  R                  nUR                  U5      nO}UR                  (       a(  UR                  R                  nUR                  U5      nODUR                  UR                  -
  UR                  UR                  -
  -  nUR                  U5      n[        XE45      $ )zReturns the intersection point as ``(x, y)`` tuple of `self` and
`other`.

Raises:
     ParallelRaysError: if rays are parallel

zRays are parallel)rT   r   r*   r   r   rG   r)   yofr+   xofr(   r'   r   )r,   rS   ray1ray2r   r)   s         r   	intersectConstructionRay.intersectz   s.    D!!#$788  A!!NN$$HHQK  A!!NN$$HHQK    AA    AA
 djj(T[[4;;-FGAAQF|r   c                6    [        XR                  [        -   S9$ )z%Returns orthogonal ray at `location`.r!   )r   r!   HALF_PI)r,   r4   s     r   
orthogonalConstructionRay.orthogonal   s    xzzG/CDDr   c                z    U R                   (       a  [        eU R                  [        U5      U R                  -  -   $ )zZReturns y-value of ray for `x` location.

Raises:
    ArithmeticError: for vertical rays

)r*   ArithmeticErrorr(   floatr'   )r,   r   s     r   rW   ConstructionRay.yof   s/     !!zzE!Ht{{222r   c                    U R                   (       a  U R                  R                  $ U R                  (       d%  [	        U5      U R
                  -
  U R                  -  $ [        e)z\Returns x-value of ray for `y` location.

Raises:
    ArithmeticError: for horizontal rays

)r*   r   r   r+   rd   r(   r'   rc   )r,   r)   s     r   rX   ConstructionRay.xof   sH     >>###$$!Htzz)T[[88!!r   c                n    U R                  U5      nU R                  UR                  -   S-  n[        X#S9$ )z%Bisectrix between `self` and `other`.r   r^   )r[   r!   r   )r,   rS   intersectionalphas       r   	bisectrixConstructionRay.bisectrix   s2    ~~e,ekk)S0|99r   )r"   r    r+   r*   r   r'   r(   )NN)r-   r   r.   zOptional[UVec]r!   Optional[float]returnr   )ro   rm   ro   rd   ro   boolro   str)rS   r   ro   rr   )rS   r   ro   r   )r4   r   ro   r   )r   rd   ro   rd   )r)   rd   ro   rd   )rS   r   ro   r   )r   r   r   r   __doc__r0   propertyr4   r7   r:   r!   rA   rD   rG   rL   rT   r[   r`   rW   rX   rk   r   r   r   r   r   r      s     MQ@@*@:I@B         ( ( ! ! # #
	H%NE
3":r   r   c                     \ rS rSrSrSS jrSS jr\SS j5       rSS jr	\S 5       r
\S 5       rSS	 jrSS
 jrSS jrSS jr\SS j5       r\SS j5       rSS jr\4     SS jjr\4     SS jjrS SS jjrSrg)!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    [        U5      U l        [        U5      U l        g Nr   startend)r,   r|   r}   s      r   r0   ConstructionLine.__init__   s    %[
9r   c                $    SR                  U 5      $ )Nz$ConstructionLine({0.start}, {0.end})rJ   r3   s    r   rL   ConstructionLine.__repr__   s    5<<TBBr   c                D    [        U R                  U R                  45      $ )z6bounding box of line as :class:`BoundingBox2d` object.)r   r|   r}   r3   s    r   bounding_boxConstructionLine.bounding_box   s     djj$((344r   c                n    [        X5      nU =R                  U-  sl        U =R                  U-  sl        g)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

Nr{   )r,   dxdyvs       r   	translateConstructionLine.translate   s'     L

a
Ar   c                    U R                   U R                  :  a  U R                  U R                   4$ U R                   U R                  4$ rz   )r|   r}   r3   s    r   sorted_pointsConstructionLine.sorted_points   sB     zzDHH$ XXtzz"	
 **dhh'	
r   c                B    [        U R                  U R                  5      $ )z#collinear :class:`ConstructionRay`.)r   r|   r}   r3   s    r   rayConstructionLine.ray   s     tzz48844r   c                    [        U[        5      (       d  [        [        U5      5      eU R                  UR                  :H  $ rz   
isinstancer   	TypeErrortyper   rR   s     r   __eq__ConstructionLine.__eq__   s6    %!122DK((!!U%8%888r   c                    [        U[        5      (       d  [        [        U5      5      eU R                  UR                  :  $ rz   r   rR   s     r   __lt__ConstructionLine.__lt__   s6    %!122DK((!!E$7$777r   c                H    U R                   U R                  -
  R                  $ )zReturns length of line.)r}   r|   	magnituder3   s    r   lengthConstructionLine.length  s    4::%000r   c                L    U R                   R                  U R                  5      $ )zReturns mid point of line.)r|   lerpr}   r3   s    r   midpointConstructionLine.midpoint  s    zztxx((r   c                    [         R                  " U R                  R                  U R                  R                  5      $ )z``True`` if line is vertical.)r?   rQ   r|   r   r}   r3   s    r   rD   ConstructionLine.is_vertical  %     ||DJJLL$((**55r   c                    [         R                  " U R                  R                  U R                  R                  5      $ )z``True`` if line is horizontal.)r?   rQ   r|   r)   r}   r3   s    r   rG   ConstructionLine.is_horizontal  r   r   c                8    U R                   R                  U5      $ )z;Returns ``True`` if `point` is inside of line bounding box.)r   inside)r,   points     r   inside_bounding_box$ConstructionLine.inside_bounding_box  s      ''..r   c                r    [        U R                  U R                  4UR                  UR                  4SUS9$ )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)virtualrP   )r   r|   r}   r,   rS   rP   s      r   r[   ConstructionLine.intersect  s7     )ZZ"[[%))$	
 	
r   c                $    U R                  XS9SL$ )z7Returns ``True`` if has intersection with `other` line.rO   N)r[   r   s      r   has_intersection!ConstructionLine.has_intersection+  s     ~~e~5TAAr   c                @    [        XR                  U R                  US9$ )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	   r|   r}   )r,   r   r   s      r   r	   &ConstructionLine.is_point_left_of_line1  s      %::txx(
 	
r   )r}   r|   N)r|   r   r}   r   rs   )ro   r   )r   rd   r   rd   ro   None)rS   objectro   rr   rp   rn   rq   )r   r   ro   rr   )rS   r   rP   rd   ro   zOptional[Vec2])rS   r   rP   rd   ro   rr   )F)r   r   r   r   ru   r0   rL   rv   r   r   r   r   r   r   r   r   rD   rG   r   r
   r[   r   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   r?   
ezdxf.mathr   r   r   construct2dr	   r
   bboxr   __all__rc   r   pir_   THREE_PI_HALF	DOUBLE_PIr&   r   r   r   r   r   <module>r      sw    #   < < 9  G	 	 ''C-dggGGcM	
k: k:\t
 t
r   