
    wgP                       d 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 ddlmZ ddlmZ dd	lmZ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mZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' g dZ( e)d      D  cg c]
  }  ed       c} \  Z*Z+ edd      Z, G d dee      Z- G d de-e      Z. ee.e      d        Z! ee.e      d        Zd Z/d"d Z0d! Z1yc c} w )#a  The definition of the base geometrical entity with attributes common to
all derived geometrical entities.

Contains
========

GeometryEntity
GeometricSet

Notes
=====

A GeometryEntity is any object that has special geometric properties.
A GeometrySet is a superclass of any GeometryEntity that can also
be viewed as a sympy.sets.Set.  In particular, points are the only
GeometryEntity not considered a Set.

Rn is a GeometrySet representing n-dimensional Euclidean space. R2 and
R3 are currently the only ambient spaces implemented.

    )annotations)Basic)Tuple)
EvalfMixinN)oo)Dummy)sympify)cossinataneye)dispatch)sstr)SetUnion	FiniteSet)intersection_sets)
union_sets)solve)	func_name)is_sequence)Point2DPoint3DPoint	Segment2DRay2DLine2D	Segment3DLine3DRay3DSegmentRayLinePlaneTriangleRegularPolygonPolygonCircleEllipseCurveParabola   entity_dummyT)realc                      e Zd ZU dZdZded<   d Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd dZd Zed        Zed        Zd Zd Zd Zd Zd Zd!dZd"dZd#dZd Z y)$GeometryEntityzThe base class for all geometrical entities.

    This class does not represent any particular geometric entity, it only
    provides the implementation of some methods common to all subclasses.

     ztuple[str, ...]	__slots__c                   | j                   j                  }|j                   j                  }||kD  ||k  z
  }|syd}| j                   j                  D ]#  }	 t        j	                  |j                        } n |dk(  r|S d}|j                   j                  D ]#  }	 t        j	                  |j                        } n |dk(  r|S ||kD  ||k  z
  S # t
        $ r d}Y w xY w# t
        $ r d}Y Vw xY w)z#Comparison of two GeometryEntities.r   )	__class____name____mro__ordering_of_classesindex
ValueError)selfothern1n2ci1clsi2s           Z/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/geometry/entity.py__cmp__zGeometryEntity.__cmp__Q   s   ^^$$__%%"Wb!>>)) 	C(..s||<	 8H??** 	C(..s||<	 8HRBG$$    s$   CC!CC!C/.C/c                L    t        |       t        |      u r| |k(  S t               )zPSubclasses should implement this method for anything more complex than equality.)typeNotImplementedErrorr=   r>   s     rE   __contains__zGeometryEntity.__contains__o   s%    :e$5= !##    c                ,    t        | j                        S )z=Returns a tuple that will be passed to __new__ on unpickling.)tupleargsr=   s    rE   __getnewargs__zGeometryEntity.__getnewargs__u   s    TYYrL   c                    | |k(   S )z,Test inequality of two geometrical entities.r3   r=   os     rE   __ne__zGeometryEntity.__ne__y   s    19}rL   c                    d }|D cg c]  } ||      rt        | n
t        |       }}t        j                  | g| S c c}w )Nc                J    t        | d      r| j                  ryt        |       S )Nis_PointF)hasattrrX   r   )as    rE   is_seq_and_not_pointz4GeometryEntity.__new__.<locals>.is_seq_and_not_point   s    q*%!**q>!rL   )r   r
   r   __new__)rC   rO   kwargsr[   rZ   s        rE   r\   zGeometryEntity.__new__}   sM    	" OSS1!4q	'!*DSS}}S(4(( Ts   "Ac                $    |j                  |       S )z%Implementation of reverse add method.)__add__r=   rZ   s     rE   __radd__zGeometryEntity.__radd__       yyrL   c                $    |j                  |       S )z*Implementation of reverse division method.)__truediv__r`   s     rE   __rtruediv__zGeometryEntity.__rtruediv__   s    }}T""rL   c                X    t        |       j                  t        | j                        z   S )zQString representation of a GeometryEntity that can be evaluated
        by sympy.)rH   r8   reprrO   rP   s    rE   __repr__zGeometryEntity.__repr__   s!     Dz""T$))_44rL   c                $    |j                  |       S )z0Implementation of reverse multiplication method.)__mul__r`   s     rE   __rmul__zGeometryEntity.__rmul__   rb   rL   c                $    |j                  |       S )z-Implementation of reverse subtraction method.)__sub__r`   s     rE   __rsub__zGeometryEntity.__rsub__   rb   rL   c                X    t        |       j                  t        | j                        z   S )z*String representation of a GeometryEntity.)rH   r8   r   rO   rP   s    rE   __str__zGeometryEntity.__str__   s    Dz""T$))_44rL   c                    ddl m}m} t        |      st        |      r?t	        | |      r ||      } ||      }n ||      } ||      }| j                  ||      S y )Nr   )r   r   )sympy.geometry.pointr   r   r   
isinstance_subs)r=   oldnewr   r   s        rE   
_eval_subszGeometryEntity._eval_subs   sX    7s{3/$(clclCjCjJJsC((  0rL   c                   	 | j                   }t        d |D              syd}t	        t
        |      \  }}}}||k(  r||k(  r|dz
  |dz
  |dz   |dz   f\  }}}}n.d}t        ||z
  ||z
  g      }||z  }	||	z  }||	z  }||	z  }||	z  }||z
  }
||z
  }t        t        d|
g      dg      }t        t        d|g      dg      }t        ||      dk(  rd	nt        |
|      t        ||      z  }	 | j                  |      }d
j                  |||
|      }dj                  ||z         }|j                  |||      }|dj                  ||      z   S # t        t        f$ r Y yw xY w# t        t        f$ r Y yw xY w)z;SVG representation of a GeometryEntity suitable for IPythonNc              3  P   K   | ]  }|j                   xr |j                     y wN)	is_number	is_finite).0xs     rE   	<genexpr>z,GeometryEntity._repr_svg_.<locals>.<genexpr>   s      ?11;;.1;;.?s   $&a  <svg xmlns="http://www.w3.org/2000/svg"
            xmlns:xlink="http://www.w3.org/1999/xlink"
            width="{1}" height="{2}" viewBox="{0}"
            preserveAspectRatio="xMinYMin meet">
            <defs>
                <marker id="markerCircle" markerWidth="8" markerHeight="8"
                    refx="5" refy="5" markerUnits="strokeWidth">
                    <circle cx="5" cy="5" r="1.5" style="stroke: none; fill:#000000;"/>
                </marker>
                <marker id="markerArrow" markerWidth="13" markerHeight="13" refx="2" refy="4"
                       orient="auto" markerUnits="strokeWidth">
                    <path d="M2,2 L2,6 L6,4" style="fill: #000000;" />
                </marker>
                <marker id="markerReverseArrow" markerWidth="13" markerHeight="13" refx="6" refy="4"
                       orient="auto" markerUnits="strokeWidth">
                    <path d="M6,2 L6,6 L2,4" style="fill: #000000;" />
                </marker>
            </defs>g      ?g?g      Y@i,  r         ?z{} {} {} {}zmatrix(1,0,0,-1,0,{})z<g transform="{}">{}</g></svg>)
boundsrI   	TypeErrorallmapr   maxmin_svgformat)r=   r   svg_topxminyminxmaxymaxexpandwidest_partexpand_amountdxdywidthheightscale_factorsvgview_box	transforms                     rE   
_repr_svg_zGeometryEntity._repr_svg_   s   	[[F ???( "%QdD$4<DDL%)BYb$)TBY%N"D$d Ftd{D4K89K'&0MM!DM!DM!DM!DD[D[S$_c*+c4*os+, /14r#b"+ESYHZ:Z	))L)C !''dB;+224$;?	..5&9,fY$% 	%u $Y/ 	 	b $Y/ 	 	s#   E -E# E E #E54E5c                    t               )a)  Returns SVG path element for the GeometryEntity.

        Parameters
        ==========

        scale_factor : float
            Multiplication factor for the SVG stroke-width.  Default is 1.
        fill_color : str, optional
            Hex string for fill color. Default is "#66cc99".
        rI   )r=   r   
fill_colors      rE   r   zGeometryEntity._svg   s     "##rL   c                    | S rz   r3   rP   s    rE   _sympy_zGeometryEntity._sympy_   s    rL   c                    t               )zCWhat is the dimension of the space that the object is contained in?r   rP   s    rE   ambient_dimensionz GeometryEntity.ambient_dimension   s     "##rL   c                    t               )zwReturn a tuple (xmin, ymin, xmax, ymax) representing the bounding
        rectangle for the geometric figure.

        r   rP   s    rE   r   zGeometryEntity.bounds  s     "##rL   c                    ddl m} ddlm}m}m} ddlm} ddlm	}m
} t        ||      r j                  |      S t        ||      rt         fd|j                  D              S t        |||f      ryt        ||      r~ j                  |j                        xra  j                   ||j                  j                   |j"                  z   |j                  j$                              xr  j'                  |       S t        ||      rFt        ||      r j                  |j                        syt         fd|j(                  D              S t+               )	a  
        Return True if o is inside (not on or outside) the boundaries of self.

        The object will be decomposed into Points and individual Entities need
        only define an encloses_point method for their class.

        See Also
        ========

        sympy.geometry.ellipse.Ellipse.encloses_point
        sympy.geometry.polygon.Polygon.encloses_point

        Examples
        ========

        >>> from sympy import RegularPolygon, Point, Polygon
        >>> t  = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
        >>> t2 = Polygon(*RegularPolygon(Point(0, 0), 2, 3).vertices)
        >>> t2.encloses(t)
        True
        >>> t.encloses(t2)
        False

        r   r   )r#   r$   r%   )r+   )r)   r(   c              3  @   K   | ]  }j                  |        y wrz   encloses_point)r}   r~   r=   s     rE   r   z*GeometryEntity.encloses.<locals>.<genexpr>0  s     @!t**1-@   Fc              3  @   K   | ]  }j                  |        y wrz   r   )r}   vr=   s     rE   r   z*GeometryEntity.encloses.<locals>.<genexpr><  s     B!t**1-Br   )rr   r   sympy.geometry.liner#   r$   r%   sympy.geometry.ellipser+   sympy.geometry.polygonr)   r(   rs   r   r   pointscenterr~   hradiusyintersectionverticesrI   )	r=   rT   r   r#   r$   r%   r+   r)   r(   s	   `        rE   encloseszGeometryEntity.encloses  s   4 	/::2Ba&&q))7#@qxx@@@C;'7#&&qxx0 )##ahhjj199,ahhjj9;) %%a(() 7#!^,**1884 BqzzBBB!##rL   c                    | |k(  S rz   r3   rS   s     rE   equalszGeometryEntity.equals?  s    qyrL   c                    t               )a  
        Returns a list of all of the intersections of self with o.

        Notes
        =====

        An entity is not required to implement this method.

        If two different types of entities can intersect, the item with
        higher index in ordering_of_classes should implement
        intersections with anything having a lower index.

        See Also
        ========

        sympy.geometry.util.intersection

        r   rS   s     rE   r   zGeometryEntity.intersectionB  s    & "##rL   c                    t               )am  Is this geometrical entity similar to another geometrical entity?

        Two entities are similar if a uniform scaling (enlarging or
        shrinking) of one of the entities will allow one to obtain the other.

        Notes
        =====

        This method is not intended to be used directly but rather
        through the `are_similar` function found in util.py.
        An entity is not required to implement this method.
        If two different types of entities can be similar, it is only
        required that one of them be able to determine this.

        See Also
        ========

        scale

        r   rJ   s     rE   
is_similarzGeometryEntity.is_similarW  s    * "##rL   c           
        ddl m | }|} dd      }|j                  j                  ro|j                  d   j
                  }|s|j                  d      S |j                        D cg c]&  }||j                  d||j
                  z
  z        f( }}n|j                  t        u ro|j                  d   j                  }|s|j                  d      S |j                        D cg c]&  }||j                  d||j                  z
  z        f( }}nt        |d      s,t        fd|j                  D              st        d	|z        t        |j                        }|j                  }	|	d    |	d
   z  }
 t        t
              }|j                  |
       j!                  | |      j                  d      j!                  ||      j                  |
      }|j                        D cg c]5  }||j#                  t        |j                  t
        |j
                  i      f7 }}|j#                  t%        |            S c c}w c c}w c c}w )a  
        Reflects an object across a line.

        Parameters
        ==========

        line: Line

        Examples
        ========

        >>> from sympy import pi, sqrt, Line, RegularPolygon
        >>> l = Line((0, pi), slope=sqrt(2))
        >>> pent = RegularPolygon((1, 2), 1, 5)
        >>> rpent = pent.reflect(l)
        >>> rpent
        RegularPolygon(Point2D(-2*sqrt(2)*pi/3 - 1/3 + 4*sqrt(2)/3, 2/3 + 2*sqrt(2)/3 + 2*pi/3), -1, 5, -atan(2*sqrt(2)) + 3*pi/5)

        >>> from sympy import pi, Line, Circle, Point
        >>> l = Line((0, pi), slope=1)
        >>> circ = Circle(Point(0, 0), 5)
        >>> rcirc = circ.reflect(l)
        >>> rcirc
        Circle(Point2D(-pi, pi), -5)

        r   r   r6   )r   r.   )r~   reflectc              3  6   K   | ]  }t        |        y wrz   )rs   )r}   argr   s     rE   r   z)GeometryEntity.reflect.<locals>.<genexpr>  s      5>/2JsE*5>s   z)reflect undefined or non-Point args in %s   )rr   r   slopeis_zerorO   r   scaleatoms	translater   r~   rY   r   rI   r   coefficientsrotatexreplacedict)r=   lineglrT   r   prepsrZ   rA   dxfr   s               @rE   r   zGeometryEntity.reflectn  s   6 	/!QK77??q	Awww}$=>WWU^LQaQSSk23LDLWW]q	Awww}$=>WWU^LQaQSSk23LDL1i( 5>67ff5> 2>)?!CE EQWWAA2qtAq!B#**A2q177"7 &A,yy1y~  ABO1QQQ$456ODOzz$t*%%) M
 M Ps   ++I,+I8:INc                    g }| j                   D ]E  }t        |t              r"|j                  |j	                  ||             5|j                  |       G  t        |       | S )a^  Rotate ``angle`` radians counterclockwise about Point ``pt``.

        The default pt is the origin, Point(0, 0)

        See Also
        ========

        scale, translate

        Examples
        ========

        >>> from sympy import Point, RegularPolygon, Polygon, pi
        >>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
        >>> t # vertex on x axis
        Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2))
        >>> t.rotate(pi/2) # vertex on y axis now
        Triangle(Point2D(0, 1), Point2D(-sqrt(3)/2, -1/2), Point2D(sqrt(3)/2, -1/2))

        )rO   rs   r2   appendr   rH   )r=   angleptnewargsrZ   s        rE   r   zGeometryEntity.rotate  s\    *  	"A!^,qxxr23q!		"
 tDz7##rL   c           	        ddl m} |rK ||d      }  | j                  | j                   j	                  ||      j                  |j                   S  t        |       | j                  D cg c]  }|j	                  ||       c} S c c}w )a  Scale the object by multiplying the x,y-coordinates by x and y.

        If pt is given, the scaling is done relative to that point; the
        object is shifted by -pt, scaled, and shifted by pt.

        See Also
        ========

        rotate, translate

        Examples
        ========

        >>> from sympy import RegularPolygon, Point, Polygon
        >>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
        >>> t
        Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2))
        >>> t.scale(2)
        Triangle(Point2D(2, 0), Point2D(-1, sqrt(3)/2), Point2D(-1, -sqrt(3)/2))
        >>> t.scale(2, 2)
        Triangle(Point2D(2, 0), Point2D(-1, sqrt(3)), Point2D(-1, -sqrt(3)))

        r   r   r.   dim)rr   r   r   rO   r   rH   )r=   r~   r   r   r   rZ   s         rE   r   zGeometryEntity.scale  sx    0 	/rq!BD>4>>RC::.44Q:DDbggNNtDz499=aAGGAqM=>>=s   -B
c                    g }| j                   D ]E  }t        |t              r"|j                  |j	                  ||             5|j                  |       G  | j
                  | S )ax  Shift the object by adding to the x,y-coordinates the values x and y.

        See Also
        ========

        rotate, scale

        Examples
        ========

        >>> from sympy import RegularPolygon, Point, Polygon
        >>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
        >>> t
        Triangle(Point2D(1, 0), Point2D(-1/2, sqrt(3)/2), Point2D(-1/2, -sqrt(3)/2))
        >>> t.translate(2)
        Triangle(Point2D(3, 0), Point2D(3/2, sqrt(3)/2), Point2D(3/2, -sqrt(3)/2))
        >>> t.translate(2, 2)
        Triangle(Point2D(3, 2), Point2D(3/2, sqrt(3)/2 + 2), Point2D(3/2, 2 - sqrt(3)/2))

        )rO   rs   r2   r   r   func)r=   r~   r   r   rZ   s        rE   r   zGeometryEntity.translate  s\    *  	"A!^,q{{1a01q!		"
 tyy'""rL   c                "   ddl m} t        |t              s ||| j                        }t        ||      st        d      t        | j                  t              |z
  t        d      }|st        dt        |       z        ||d   t           iS )a  Return the parameter corresponding to the given point.
        Evaluating an arbitrary point of the entity at this parameter
        value will return the given point.

        Examples
        ========

        >>> from sympy import Line, Point
        >>> from sympy.abc import t
        >>> a = Point(0, 0)
        >>> b = Point(2, 2)
        >>> Line(a, b).parameter_value((1, 1), t)
        {t: 1/2}
        >>> Line(a, b).arbitrary_point(t).subs(_)
        Point2D(1, 1)
        r   r   r   zother must be a pointT)r   zGiven point is not on %s)
rr   r   rs   r2   r   r<   r   arbitrary_pointTr   )r=   r>   tr   sols        rE   parameter_valuezGeometryEntity.parameter_value   s    " 	/%0%T%;%;<E%'455D((+e3QTB7)D/IJJ3q6!9~rL   )r   z#66cc99rz   )r   r   Nr   r   )!r8   
__module____qualname____doc__r4   __annotations__rF   rK   rQ   rU   r\   ra   re   rh   rk   rn   rp   rw   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r3   rL   rE   r2   r2   G   s     "$I#%<$ 
)#5
5	)A%F$ $ $ $ $/$b$*$.8&t$:?<#:rL   r2   c                      e Zd ZdZdZd Zy)GeometrySetz[Parent class of all GeometryEntity that are also Sets
    (compatible with sympy.sets)
    r3   c                     t        |t              r |j                  rt         fd|D              S  j	                  |      S )zFsympy.sets uses the _contains method, so include it for compatibility.c              3  @   K   | ]  }j                  |        y wrz   )rK   )r}   ir=   s     rE   r   z(GeometrySet._contains.<locals>.<genexpr>&  s     ;t((+;r   )rs   r   is_FiniteSetr   rK   rJ   s   ` rE   	_containszGeometrySet._contains"  s9     eS!e&8&8;U;;;  ''rL   N)r8   r   r   r   r4   r   r3   rL   rE   r   r     s     I(rL   r   c                    |j                   rK|D cg c]  }| j                  |      r| }}t        |      t        |      k(  ryt        | t	        |       S | j                  |      r| S yc c}w )zO Returns the union of self and o
    for use with sympy.sets.Set, if possible. N)r   r   lenr   r   )r=   rT   r   other_pointss       rE   r   r   *  sh     	~~#$>aDNN1,=>>|A&T9l344~~a ?s
   A,A,c           	     8    ddl m} 	 |j                  rt         fd|D         }n j	                  |      }t        |D cg c]  }t        ||      s| c} }|D cg c]  }t        ||      r| }}t        ||gz    S # t
        $ r Y yw xY wc c}w c c}w )zD Returns a sympy.sets.Set of intersection objects,
    if possible. r   r   c              3  F   K   | ]  }j                  |      s|  y wrz   )contains)r}   r   r=   s     rE   r   z$intersection_sets.<locals>.<genexpr>G  s     Aaa0@As   !!N)rr   r   r   r   r   rI   rs   r   )r=   rT   r   interr   r   
non_pointss   `      rE   r   r   <  s    
 +
 >>A1ABE%%a(E EBqZ5-ABCF"?*Q*>!?J?:(**    C?s)   /B BBB1B	BBc                0    t        d      }| |d<   ||d<   |S )z6Return the matrix to translate a 2-D point by x and y.   )r.   r   )r.   r   r   )r~   r   rvs      rE   r   r   U  s"    	QBBtHBtHIrL   Nc                    t        d      }| |d<   ||d<   |r=ddlm}  ||d      }t        | j                   }t        |j                   }||z  |z  S |S )zReturn the matrix to multiply a 2-D point's coordinates by x and y.

    If pt is given, the scaling is done relative to that point.r   r   )r   r   r   r   r.   r   )r   rr   r   r   rO   )r~   r   r   r   r   tr1tr2s          rE   r   r   ]  sb     
QBBtHBtH	.212#$!2vczIrL   c                j    t        |       }t        d      t        |       z  }||d<   | |d<   d|d<   |S )a  Return the matrix to rotate a 2-D point about the origin by ``angle``.

    The angle is measured in radians. To Point a point about a point other
    then the origin, translate the Point, do the rotation, and
    translate it back:

    >>> from sympy.geometry.entity import rotate, translate
    >>> from sympy import Point, pi
    >>> rot_about_11 = translate(-1, -1)*rotate(pi/2)*translate(1, 1)
    >>> Point(1, 1).transform(rot_about_11)
    Point2D(1, 1)
    >>> Point(0, 0).transform(rot_about_11)
    Point2D(2, 0)
    r   )r   r   )r   r   r   )r.   r.   )r   r   r   )thsr   s      rE   r   r   m  s@     	BA	QBBBtHrBtHBtHIrL   rz   )2r   
__future__r   sympy.core.basicr   sympy.core.containersr   sympy.core.evalfr   r   sympy.core.numbersr   sympy.core.symbolr	   sympy.core.sympifyr
   (sympy.functions.elementary.trigonometricr   r   r   sympy.matricesr   sympy.multipledispatchr   sympy.printingr   
sympy.setsr   r   r    sympy.sets.handlers.intersectionr   sympy.sets.handlers.unionr   sympy.solvers.solversr   sympy.utilities.miscr   sympy.utilities.iterablesr   r:   ranger~   r   r   r2   r   r   r   r   )r   s   0rE   <module>r     s   * # " ' * ! # & C C  +  , , > 0 ' * 1 0 (-Qx0!n01	.t$RUJ Rj(.# ( 
+s " 
+s+ +0 U 1s   C!