
    OgH                    (   d dl mZ d dlmZmZmZmZmZ d dlZd dl	Z
d dlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ erd dlmZ d dlmZ g dZd ej<                  dz  ej<                  ej<                  dz  gZ G d d      Z ddZ!ddZ"y)    )annotations)TYPE_CHECKINGIterableSequenceIteratorOptionalN)Vec2UVec   )BoundingBox2d)enclosing_angles)ConstructionCircle)ConstructionRayConstructionLine)UCS)Arc)
BaseLayout)ConstructionArcarc_chord_lengtharc_segment_count      ?g      ?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
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ed%d       Zed%d       Ze	 	 	 	 	 	 d,d       Ze	 d-	 	 	 	 	 	 	 	 	 d.d       Ze	 	 d/	 	 	 	 	 	 	 	 	 	 	 d0d       Ze	 d-	 	 	 	 	 	 	 	 	 d1d       Z	 d2	 	 	 	 	 d3dZ	 d4	 	 	 	 	 d5dZ	 d4	 	 	 	 	 d6dZ	 d4	 	 	 	 	 d7dZ	 d4	 	 	 	 	 d8dZ d9dZ!y):r   aP  Construction tool for 2D arcs.

    :class:`ConstructionArc` represents a 2D arc in the xy-plane, use an
    :class:`UCS` to place a DXF :class:`~ezdxf.entities.Arc` entity in 3D space,
    see method :meth:`add_to_layout`.

    Implements the 2D transformation tools: :meth:`translate`,
    :meth:`scale_uniform` and :meth:`rotate_z`

    Args:
        center: center point as :class:`Vec2` compatible object
        radius: radius
        start_angle: start angle in degrees
        end_angle: end angle in degrees
        is_counter_clockwise: swaps start- and end angle if ``False``

    c                p    t        |      | _        || _        |r|| _        || _        y || _        || _        y N)r	   centerradiusstart_angle	end_angle)selfr   r   r   r   is_counter_clockwises         S/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/arc.py__init__zConstructionArc.__init__+   s7     6l*D&DN(D(DN    c                p    | j                   t        j                  | j                  | j                        z   S )z$start point of arc as :class:`Vec2`.)r   r	   from_deg_angler   r   r   s    r!   start_pointzConstructionArc.start_point=   s*     {{T001A1A4;;OOOr#   c                p    | j                   t        j                  | j                  | j                        z   S )z"end point of arc as :class:`Vec2`.)r   r	   r%   r   r   r&   s    r!   	end_pointzConstructionArc.end_pointB   s(     {{T00MMMr#   c                4    | j                   | j                  kD  S )z<Returns ``True`` if the arc passes the x-axis (== 0 degree).r   r   r&   s    r!   is_passing_zerozConstructionArc.is_passing_zeroG   s     $..00r#   c                B    t        | j                  | j                        S r   )r   r   r   r&   s    r!   circlezConstructionArc.circleL   s    !$++t{{;;r#   c                    t        | j                  | j                  f      }|j                  | j	                                |S )z.bounding box of arc as :class:`BoundingBox2d`.)r   r'   r)   extendmain_axis_points)r   bboxs     r!   bounding_boxzConstructionArc.bounding_boxP   s7     d..?@D))+,r#   c              #     K   |dk  rt        d      | j                  dz  }| j                  dz  }||k  r|dz  }t        j                  |||d      D ]	  }|dz    yw)zReturns `num` angles from start- to end angle in degrees in
        counter-clockwise order.

        All angles are normalized in the range from [0, 360).

           znum >= 2h  T)numendpointN)
ValueErrorr   r   nplinspace)r   r7   startstopangles        r!   angleszConstructionArc.anglesW   sp      7Z((''#-nns*5=CKD[[#E 	E#+	s   AA!c                `    | j                   }|| j                  k  r|dz  }|| j                  z
  S )z3Returns angle span of arc from start- to end param.     v@)r   r   )r   ends     r!   
angle_spanzConstructionArc.angle_spang   s5     ^^!!!5LCT%%%%r#   c              #     K   | j                   }| j                  }|D ]  }|t        j                  ||      z     yw)zYields vertices on arc for angles in iterable `a` in WCS as location
        vectors.

        Args:
            a: angles in the range from 0 to 360 in degrees, arc goes
                counter clockwise around the z-axis, WCS x-axis = 0 deg.

        N)r   r   r	   r%   )r   ar   r   r>   s        r!   verticeszConstructionArc.verticeso   sA       	>E4..uf===	>s   <>c              #  x  K   t        | j                        }|dkD  r| j                  }| j                  }t	        j
                  ||      ry|dz  }|dz  }||k  r|dz  }t	        j                  ||z
        }t        |||      }| j                  t        j                  |||dz               E d{    yy7 w)zApproximate the arc by vertices in WCS, argument `sagitta` is the
        max. distance from the center of an arc segment to the center of its
        chord.

        r   Nr6   r   )absr   r   r   mathiscloseradiansr   rF   r:   r;   )r   sagittar   r<   r=   rC   counts          r!   
flatteningzConstructionArc.flattening~   s      DKK(A:++E..D||E4(SLECKDu} $TE\ :J%fj'BE}}R[[eai%HIII  Js   B/B:1B82B:c              #     K   |D ]M  }t        j                  |      }t        t        j                  |       t        j                  |      f       O yw)zYields tangents on arc for angles in iterable `a` in WCS as
        direction vectors.

        Args:
            a: angles in the range from 0 to 360 in degrees, arc goes
                counter-clockwise around the z-axis, WCS x-axis = 0 deg.

        N)rI   rK   r	   sincos)r   rE   r>   rs       r!   tangentszConstructionArc.tangents   sG       	4E||E*A!dhhqk233	4s   AAc              #     K   | j                   }| j                  }t        j                  | j                        }t        j                  | j
                        }t        D ]+  }t        |||      s|t        j                  ||      z    - y wr   )
r   r   rI   rK   r   r   QUARTER_ANGLESr   r	   
from_angle)r   r   r   r<   rB   r>   s         r!   r1   z ConstructionArc.main_axis_points   so     {{||D$4$45\\$..1# 	>Euc2tuf===	>s   A-B0Bc                D    | xj                   t        ||      z  c_         | S )zMove arc about `dx` in x-axis and about `dy` in y-axis, returns
        `self` (floating interface).

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

        )r   r	   )r   dxdys      r!   	translatezConstructionArc.translate   s     	tB|#r#   c                B    | xj                   t        |      z  c_         | S )zkScale arc inplace uniform about `s` in x- and y-axis, returns
        `self` (floating interface).
        )r   float)r   ss     r!   scale_uniformzConstructionArc.scale_uniform   s     	uQxr#   c                Z    | xj                   |z  c_         | xj                  |z  c_        | S )zRotate arc inplace about z-axis, returns `self`
        (floating interface).

        Args:
            angle: rotation angle in degrees

        r+   )r   r>   s     r!   rotate_zzConstructionArc.rotate_z   s(     	E!%r#   c                @    t        j                  | j                        S )z#Returns the start angle in radians.)rI   rK   r   r&   s    r!   start_angle_radzConstructionArc.start_angle_rad   s     ||D,,--r#   c                @    t        j                  | j                        S )z!Returns the end angle in radians.)rI   rK   r   r&   s    r!   end_angle_radzConstructionArc.end_angle_rad   s     ||DNN++r#   c                V    t        |       } t        |      }| |k(  rt        d      | |fS )Nz1Start- and end point have to be different points.)r	   r9   )r'   r)   s     r!   validate_start_and_end_pointz,ConstructionArc.validate_start_and_end_point   s<     ;'O	)#C  I%%r#   c                   | j                  ||      \  }}t        j                  |      }|dk(  rt        d      |du r||}}|dz  }|j	                  |      }|dz  }	|	t        j
                  |      z  }
|	t        j                  |      z  }|j                  |d      }||z
  }|j                         j                  |      }||z   }t        ||
||z
  j                  ||z
  j                  d      S )	a  Create arc from two points and enclosing angle. Additional
        precondition: arc goes by default in counter-clockwise orientation from
        `start_point` to `end_point`, can be changed by `ccw` = ``False``.

        Args:
            start_point: start point as :class:`Vec2` compatible object
            end_point: end point as :class:`Vec2` compatible object
            angle: enclosing angle in degrees
            ccw: counter-clockwise direction if ``True``

        r   zAngle can not be 0.F       @r   factorTr   r   r   r   r    )rf   rI   rK   r9   distancerP   tanlerp
orthogonal	normalizer   	angle_deg)clsr'   r)   r>   ccw_start_point
_end_pointalpha2rl   	distance2r   height	mid_pointdistance_vectorheight_vectorr   s                   r!   from_2p_anglezConstructionArc.from_2p_angle   s
   & $'#C#C$
 j U#A:233%<'1<*L$--l;#c>	!DHHV$44!DHHV$44$//,s/C	 *\ 9-88:DDVL =0%.99!F*55!%
 	
r#   c                   | j                  ||      \  }}t        |      }|dk  rt        d      |du r||}}|j                  |d      }|j	                  |      }	|	dz  }
t        j                  |dz  |
dz  z
        }|||z
  j                  |      j                  |      z   }t        ||||z
  j                  ||z
  j                  d	
      S )aX  Create arc from two points and arc radius.
        Additional precondition: arc goes by default in counter-clockwise
        orientation from `start_point` to `end_point` can be changed
        by `ccw` = ``False``.

        The parameter `center_is_left` defines if the center of the arc is
        left or right of the line from `start_point` to `end_point`.
        Parameter `ccw` = ``False`` swaps start- and end point, which also
        inverts the meaning of ``center_is_left``.

        Args:
            start_point: start point as :class:`Vec2` compatible object
            end_point: end point as :class:`Vec2` compatible object
            radius: arc radius
            ccw: counter-clockwise direction if ``True``
            center_is_left: center point of arc is left of line from start- to
                end point if ``True``

        r   zRadius has to be > 0.Fr   ri   rh   r5   )rs   Trk   )rf   r\   r9   rn   rl   rI   sqrtro   rp   r   rq   )rr   r'   r)   r   rs   center_is_leftrt   ru   ry   rl   rw   rx   r   s                r!   from_2p_radiuszConstructionArc.from_2p_radius  s    8 $'#C#C$
 j vQ;455%<'1<*L$//,s/C	$--l;#c>			&A+	Q">? J$=#I#I $J $

)F
 %.99!F*55!%
 	
r#   c                ,   | j                  ||      \  }}t        |      }||k(  s||k(  rt        d      t        j                  |||      }t        |j
                        }t        ||j                  ||z
  j                  ||z
  j                  |      S )a  Create arc from three points.
        Additional precondition: arc goes in counter-clockwise
        orientation from `start_point` to `end_point`.

        Args:
            start_point: start point as :class:`Vec2` compatible object
            end_point: end point as :class:`Vec2` compatible object
            def_point: additional definition point as :class:`Vec2` compatible
                object
            ccw: counter-clockwise direction if ``True``

        z5def_point has to be different to start- and end pointrk   )	rf   r	   r9   r   from_3pr   r   r   rq   )rr   r'   r)   	def_pointrs   r.   r   s          r!   r   zConstructionArc.from_3p@  s    ( "%!A!A"
Y O	#yI'=G  $++KINfmm$==$v-88 6)44!$
 	
r#   Nc                    |j                  | j                  | j                  | j                  | j                  |      }||S |j                  |j                        S )a9  Add arc as DXF :class:`~ezdxf.entities.Arc` entity to a layout.

        Supports 3D arcs by using an :ref:`UCS`. An :class:`ConstructionArc` is
        always defined in the xy-plane, but by using an arbitrary UCS, the arc
        can be placed in 3D space, automatically OCS transformation included.

        Args:
            layout: destination layout as :class:`~ezdxf.layouts.BaseLayout`
                object
            ucs: place arc in 3D space by :class:`~ezdxf.math.UCS` object
            dxfattribs: additional DXF attributes for the ARC entity

        )r   r   r   r   
dxfattribs)add_arcr   r   r   r   	transformmatrix)r   layoutucsr   arcs        r!   add_to_layoutzConstructionArc.add_to_layoutg  sV      nn;;;;((nn!  
 ks@s}}SZZ'@@r#   c                    t        |t              sJ | j                  j                  ||      D cg c]  }| j	                  |      r| c}S c c}w )a  Returns intersection points of arc and `ray` as sequence of
        :class:`Vec2` objects.

        Args:
            ray: intersection ray
            abs_tol: absolute tolerance for tests (e.g. test for tangents)

        Returns:
            tuple of :class:`Vec2` objects

            =========== ==================================
            tuple size  Description
            =========== ==================================
            0           no intersection
            1           line intersects or touches the arc at one point
            2           line intersects the arc at two points
            =========== ==================================

        )
isinstancer   r.   intersect_ray_is_point_in_arc_range)r   rayabs_tolpoints       r!   r   zConstructionArc.intersect_ray  sU    , #/// 223@
**51 
 	
 
   Ac                    t        |t              sJ | j                  j                  ||      D cg c]  }| j	                  |      r| c}S c c}w )a  Returns intersection points of arc and `line` as sequence of
        :class:`Vec2` objects.

        Args:
            line: intersection line
            abs_tol: absolute tolerance for tests (e.g. test for tangents)

        Returns:
            tuple of :class:`Vec2` objects

            =========== ==================================
            tuple size  Description
            =========== ==================================
            0           no intersection
            1           line intersects or touches the arc at one point
            2           line intersects the arc at two points
            =========== ==================================

        )r   r   r.   intersect_liner   )r   liner   r   s       r!   r   zConstructionArc.intersect_line  sV    , $ 0111 33D'B
**51 
 	
 
r   c                    t        |t              sJ | j                  j                  ||      D cg c]  }| j	                  |      r| c}S c c}w )a  Returns intersection points of arc and `circle` as sequence of
        :class:`Vec2` objects.

        Args:
            circle: intersection circle
            abs_tol: absolute tolerance for tests

        Returns:
            tuple of :class:`Vec2` objects

            =========== ==================================
            tuple size  Description
            =========== ==================================
            0           no intersection
            1           circle intersects or touches the arc at one point
            2           circle intersects the arc at two points
            =========== ==================================

        )r   r   r.   intersect_circler   )r   r.   r   r   s       r!   r   z ConstructionArc.intersect_circle  sV    , &"4555 55fgF
**51 
 	
 
r   c                    t        |t              sJ | j                  j                  |j                  |      D cg c]&  }| j	                  |      r|j	                  |      r|( c}S c c}w )a  Returns intersection points of two arcs as sequence of
        :class:`Vec2` objects.

        Args:
            other: other intersection arc
            abs_tol: absolute tolerance for tests

        Returns:
            tuple of :class:`Vec2` objects

            =========== ==================================
            tuple size  Description
            =========== ==================================
            0           no intersection
            1           other arc intersects or touches the arc at one point
            2           other arc intersects the arc at two points
            =========== ==================================

        )r   r   r.   r   r   )r   otherr   r   s       r!   intersect_arczConstructionArc.intersect_arc  sg    , %111 55ellGL
**51,,U3 
 	
 
s   +A)c                    | j                   dz  }| j                  dz  }|| j                  z
  j                  dz  }||kD  r||k\  xs ||k  S ||cxk  xr |k  S c S )NrA   )r   r   r   rq   )r   r   r<   rB   r>   s        r!   r   z&ConstructionArc._is_point_in_arc_range  sk     ''%/^^e++66>3;E>1Uc\1$$$$$r#   ))r   r   g      ?g        rA   T)
r   r
   r   r\   r   r\   r   r\   r    zOptional[bool])returnr	   )r   bool)r   r   )r   r   )r7   intr   Iterable[float])r   r\   )rE   r   r   Iterable[Vec2])rL   r\   r   r   )r   zIterator[Vec2])rX   r\   rY   r\   r   r   )r]   r\   r   r   )r>   r\   r   r   )r'   r
   r)   r
   r   ztuple[Vec2, Vec2])T)
r'   r
   r)   r
   r>   r\   rs   r   r   r   )TT)r'   r
   r)   r
   r   r\   rs   r   r   r   r   r   )
r'   r
   r)   r
   r   r
   rs   r   r   r   )NN)r   r   r   zOptional[UCS]r   r   )g|=)r   r   r   r\   r   Sequence[Vec2])r   r   r   r\   r   r   )r.   r   r   r\   r   r   )r   r   r   r\   r   r   )r   r	   r   r   )"__name__
__module____qualname____doc__r"   propertyr'   r)   r,   r.   r3   r?   rC   rF   rN   rS   r1   rZ   r^   r`   rb   rd   staticmethodrf   classmethodr|   r   r   r   r   r   r   r   r    r#   r!   r   r      s   (   /3)) ) 	)
 ) -)$ P P N N 1 1 < <    & &>J(4>

 . . , , 	&	&&*	&		& 	&  +
+
 +
 	+

 +
 
+
 +
Z  #2
2
 2
 	2

 2
 2
 
2
 2
h  $
$
 $
 	$

 $
 
$
 $
N IMA A'4A	A4 6;
"
-2
	
< 8=
$
/4
	
< <A
(
38
	
< 8=
$
/4
	
<%r#   r   c                J    dt        j                  d| z  |z  ||z  z
        z  S )zReturns the chord length for an arc defined by `radius` and
    the `sagitta`_.

    Args:
        radius: arc radius
        sagitta: distance from the center of the arc to the center of its base

    rh   )rI   r~   )r   rL   s     r!   r   r      s+     3<'1Gg4EEFFFr#   c                    t        | |      }t        j                  |dz  | z        dz  }t        j                  ||z        S )a.  Returns the count of required segments for the approximation
    of an arc for a given maximum `sagitta`_.

    Args:
        radius: arc radius
        angle: angle span of the arc in radians
        sagitta: max. distance from the center of an arc segment to the
            center of its chord

    rh   )r   rI   asinceil)r   r>   rL   chord_lengthalphas        r!   r   r     s@     +67;L99\C/&89C?E99UU]##r#   )r   r\   rL   r\   r   r\   )r   r\   r>   r\   rL   r\   r   r   )#
__future__r   typingr   r   r   r   r   rI   numpyr:   
ezdxf.mathr	   r
   r2   r   construct2dr   r.   r   r   r   r   r   r   ezdxf.entitiesr   ezdxf.layoutsr   __all__pirU   r   r   r   r   r#   r!   <module>r      sp    # H H   !  ) & 3 "(
FTWWs]DGGTWWs];e% e%P	G$r#   