
    OgS/                        d dl mZ d dlmZmZmZmZ d dlZddlm	Z	m
Z
 erd dlmZ dZdZd	Zdd
Zdef	 	 	 	 	 ddZddZef	 	 	 	 	 ddZddZddZef	 	 	 	 	 ddZdZdZdZdZdZdZd dZd!d"dZy)#    )annotations)IterableSequenceOptionalTYPE_CHECKINGN   )Vec2Vec3)UVecg|=gV瞯<gvIh%<=c           	         t        j                  |       } t        |       dk  rt        d      | d   j	                  | d         s| j                  | d          t        d t        | | dd       D              dkD  S )	zReturns ``True`` if the given 2D `vertices` have clockwise orientation.
    Ignores the z-axis of all vertices.

    Args:
        vertices: iterable of :class:`Vec2` compatible objects

    Raises:
        ValueError: less than 3 vertices

       zAt least 3 vertices required.r   c              3     K   | ]:  \  }}|j                   |j                   z
  |j                  |j                  z   z   < y w)N)xy).0p1p2s      Z/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/math/_construct.py	<genexpr>z,has_clockwise_orientation.<locals>.<genexpr>(   s9      
B TTBDD[RTTBDD[)
s   A Ar   N        )r	   listlen
ValueErroriscloseappendsumzip)verticess    r   has_clockwise_orientationr       s     yy"H
8}q899 A;x|,$ 	 
h5
 	
 		    Tc                &   | \  }}|\  }}|j                   }|j                  }	|j                   }
|j                  }|j                   }|j                  }|j                   }|j                  }||z
  |
|z
  z  ||z
  ||	z
  z  z
  }t        j                  |      |k  ry||z
  |	|z
  z  ||z
  ||z
  z  z
  |z  }t	        |||
|z
  z  z   |	|||	z
  z  z         }|r|S d}d}||cxk  r|k  r,n y|
|z
  |	|z
  z  ||	z
  ||z
  z  z
  |z  }||cxk  r|k  r|S  yy)a9  
    Compute the intersection of two lines in the xy-plane.

    Args:
        line1: start- and end point of first line to test
            e.g. ((x1, y1), (x2, y2)).
        line2: start- and end point of second line to test
            e.g. ((x3, y3), (x4, y4)).
        virtual: ``True`` returns any intersection point, ``False`` returns
            only real intersection points.
        abs_tol: tolerance for intersection test.

    Returns:
        ``None`` if there is no intersection point (parallel lines) or
        intersection point as :class:`Vec2`

    Nr         ?)r   r   mathfabsr	   )line1line2virtualabs_tols1s2c1c2s1xs1ys2xs2yc1xc1yc2xc2ydenusintersection_pointlwruprucs                         r   intersection_line_line_2dr<   0   sT   2 FBFB
$$C
$$C
$$C
$$C
$$C
$$C
$$C
$$C9s
#sSyS3Y&?
?Cyy~ 9s
#sSyS3Y&?
?3	FBcB#)$44cB#)<L6LM!!
 C
C
bC  SyS3Y'39s*CCsJ"%% r!   c                    | \  }}}|\  }}}|\  }	}
}||z  |z  ||z  |	z  z   ||z  |
z  z   ||z  |	z  z
  ||z  |
z  z
  ||z  |z  z
  S )zReturns determinant. )v1v2v3e11e12e13e21e22e23e31e32e33s               r   _determinantrK   i   s    MCcMCcMCc 	c	C
)c/	
)c/	 )c/	 )c/		
 )c/	r!   c                X   | \  }}||z
  j                         }|\  }}||z
  j                         }|j                  |      }	|	j                  }
|
|k  r
t               S ||z
  }t	        |||	      }t	        |||	      }||||
z  z  z   }||||
z  z  z   }|j                  ||      r|fS ||fS )a  
    Calculate intersection of two 3D rays, returns a 0-tuple for parallel rays,
    a 1-tuple for intersecting rays and a 2-tuple for not intersecting and not
    parallel rays with points of the closest approach on each ray.

    Args:
        ray1: first ray as tuple of two points as :class:`Vec3` objects
        ray2: second ray as tuple of two points as :class:`Vec3` objects
        abs_tol: absolute tolerance for comparisons

    r)   )	normalizecrossmagnitude_squaretuplerK   r   )ray1ray2r)   o1r   d1o2r   d2d1xd2denominatoro2_o1det1det2s                 r   intersection_ray_ray_3dr]   y   s     FB
r'			BFB
r'			BHHRLE((KgwRE2u-E2u-"{*++"{*++::b':*5L r6Mr!   c                    t        j                  | |t              ry| dz  } t        j                  | |dz  t              ryt        j                  |dt              s|dz  }|| k  r|dz  }|| z
  S )u  Returns the counter-clockwise angle span from `start` to `end` in degrees.

    Returns the angle span in the range of [0, 360], 360 is a full circle.
    Full circle handling is a special case, because normalization of angles
    which describe a full circle would return 0 if treated as regular angles.
    e.g. (0, 360) → 360, (0, -360) → 360, (180, -180) → 360.
    Input angles with the same value always return 0 by definition: (0, 0) → 0,
    (-180, -180) → 0, (360, 360) → 0.

    rM   r   g     v@)r$   r   DEG_ABS_TOL)startends     r   arc_angle_span_degrb      sn     ||E34 
UNE||E3;< <<UK8u
U{u;r!   c                   t         j                  }t        j                  | |t              ry| |z  } t        j                  | ||z  t              r|S t        j                  ||t              s||z  }|| k  r||z  }|| z
  S )u  Returns the counter-clockwise angle span from `start` to `end` in radians.

    Returns the angle span in the range of [0, 2π], 2π is a full circle.
    Full circle handling is a special case, because normalization of angles
    which describe a full circle would return 0 if treated as regular angles.
    e.g. (0, 2π) → 2π, (0, -2π) → 2π, (π, -π) → 2π.
    Input angles with the same value always return 0 by definition: (0, 0) → 0,
    (-π, -π) → 0, (2π, 2π) → 0.

    rM   r   )r$   taur   RAD_ABS_TOL)r`   ra   rd   s      r   arc_angle_span_radrf      sy     ((C||E34 
SLE||E39k:
 <<S+6s

U{s
;r!   c                :   t        |t              sJ t        |      dk  ry|d   j                  |d         r|dd }t        |      dk  ry| j                  }| j
                  }d}|d   \  }}|D ]  \  }}	||k  r||fn||f\  }
}|
|cxk  r|k  rLn nI|	|k  r|	|fn||	f\  }}||cxk  r|k  r.n n+t        |	|z
  |z  ||z
  |z  z
  ||z  |	|z  z
  z         |k  r y||cxk  r|	k  sn |	|cxk  r|k  rn n|||z
  ||z
  z  |	|z
  z  |z   k  r| }|}|	} |ryy)a  
    Test if `point` is inside `polygon`.  Returns +1 for inside, 0 for on the 
    boundary and  -1 for outside.

    Supports convex and concave polygons with clockwise or counter-clockwise oriented
    polygon vertices.  Does not raise an exception for degenerated polygons.


    Args:
        point: 2D point to test as :class:`Vec2`
        polygon: list of 2D points as :class:`Vec2`
        abs_tol: tolerance for distance check

    Returns:
        +1 for inside, 0 for on the boundary, -1 for outside

    r   r   r   NFr   )
isinstancer   r   r   r   r   abs)pointpolygonr)   r   r   insidex1y1x2y2abcds                 r   is_point_in_polygon_2dru      sf   . gt$$$
7|aqz'"+&#2,
7|aAAFR[FB B 7BxR1;Q;!BwB8RHDAqQ!bAbA-b271BC"" 1\r\rQ||bQV$R0255ZF!" r!   iRa gQ?XAg9=?giW
?g-DT!?g-DT!?c                d   t        j                  |       } t        j                  |      }t        }t        }t        j                  |      |z  }t        j
                  d|z
  d|z   z  |dz        }|t        j                  t        j                  t        |dz  z         |z        z  }|| z  }||fS )a  Transform GPS (long/lat) to World Mercator.
    
    Transform WGS84 `EPSG:4326 <https://epsg.io/4326>`_ location given as
    latitude and longitude in decimal degrees as used by GPS into World Mercator
    cartesian 2D coordinates in meters `EPSG:3395 <https://epsg.io/3395>`_.

    Args:
        longitude: represents the longitude value (East-West) in decimal degrees 
        latitude: represents the latitude value (North-South) in decimal degrees.
    
    .. versionadded:: 1.3.0

    r#          @)	r$   radiansWGS84_SEMI_MAJOR_AXISWGS84_ELLIPSOID_ECCENTRICsinpowlogtan
CONST_PI_4)	longitudelatituderq   e	e_sin_latrs   r   r   s           r   gps_to_world_mercatorr   &  s    & Y'I||H%HA!A"Q&I#	/cIo6C@A	DHHTXXj8c>9:Q>??A	IAa4Kr!   c                   t         }t        }|dz  }t        }t        j                  | |z  z  }|dt        j
                  |      z  z
  }	 t        j                  |      |z  }	|dt        j
                  |d|	z
  d|	z   z  |z  z        z  z
  }
t        |
|z
        |k  rn|
}W| |z  }t        j                  |      t        j                  |
      fS )a  Transform World Mercator to GPS.

    Transform WGS84 World Mercator `EPSG:3395 <https://epsg.io/3395>`_
    location given as cartesian 2D coordinates x, y in meters into WGS84 decimal
    degrees as longitude and latitude `EPSG:4326 <https://epsg.io/4326>`_ as
    used by GPS.

    Args:
        x: coordinate WGS84 World Mercator
        y: coordinate WGS84 World Mercator
        tol: accuracy for latitude calculation

    .. versionadded:: 1.3.0

    rw   r#   )	ry   rz   
CONST_PI_2r$   r   atanr{   ri   degrees)r   r   tolrq   r   e2pi2t	latitude_r   r   r   s               r   world_mercator_to_gpsr   D  s    , 	A!A	
SB
CA26AcDIIaL((I
HHY'!+	tyy#	/cIo62== 
 
 
 x)#$s*	  AI<<	"DLL$:::r!   )r   zIterable[UVec]returnbool)r&   Sequence[Vec2]r'   r   r   zOptional[Vec2])r   float)rR   Sequence[Vec3]rS   r   r   r   )r`   r   ra   r   r   r   )rj   r	   rk   z
list[Vec2]r   int)r   r   r   r   r   tuple[float, float])gư>)r   r   r   r   r   r   r   r   )
__future__r   typingr   r   r   r   r$   _vectorr	   r
   
ezdxf.mathr   	TOLERANCEre   r_   r    r<   rK   r]   rb   rf   ru   ry   WGS84_SEMI_MINOR_AXISrz   CONST_E2r   r   r   r   r>   r!   r   <module>r      s   
 # > >   	> 	666
 6r" 9B$
$ .$$N<@ /877$77|   $ /  

<&;r!   