o
    8Va                     @   s  d dl mZ d dlmZ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mZmZmZmZ d dlmZ G d	d
 d
eZedd Zeedd Zeedd ZeedddZeedddZeedddZeedddZdS )    )singledispatch)pitan)trigsimp)BasicTuple)_symbol)solve)PointSegmentCurveEllipsePolygon)ImplicitRegionc                       sP   e Zd ZdZ fddZedd Zedd Zedd	 Zed
d Z	  Z
S )ParametricRegiona  
    Represents a parametric region in space.

    Examples
    ========

    >>> from sympy import cos, sin, pi
    >>> from sympy.abc import r, theta, t, a, b, x, y
    >>> from sympy.vector import ParametricRegion

    >>> ParametricRegion((t, t**2), (t, -1, 2))
    ParametricRegion((t, t**2), (t, -1, 2))
    >>> ParametricRegion((x, y), (x, 3, 4), (y, 5, 6))
    ParametricRegion((x, y), (x, 3, 4), (y, 5, 6))
    >>> ParametricRegion((r*cos(theta), r*sin(theta)), (r, -2, 2), (theta, 0, pi))
    ParametricRegion((r*cos(theta), r*sin(theta)), (r, -2, 2), (theta, 0, pi))
    >>> ParametricRegion((a*cos(t), b*sin(t)), t)
    ParametricRegion((a*cos(t), b*sin(t)), t)

    >>> circle = ParametricRegion((r*cos(theta), r*sin(theta)), r, (theta, 0, pi))
    >>> circle.parameters
    (r, theta)
    >>> circle.definition
    (r*cos(theta), r*sin(theta))
    >>> circle.limits
    {theta: (0, pi)}

    Dimension of a parametric region determines whether a region is a curve, surface
    or volume region. It does not represent its dimensions in space.

    >>> circle.dimensions
    1

    Parameters
    ==========

    definition : tuple to define base scalars in terms of parameters.

    bounds : Parameter or a tuple of length 3 to define parameter and corresponding lower and upper bound.

    c                    s   d}i }t |tst| }|D ]/}t |tst |tr9t|dkr%td||d f7 }|d |d f||d < q||f7 }qt |tsLt |tsL|f}t j| t| g|R  }||_||_|S )N    z?Tuple should be in the form (parameter, lowerbound, upperbound)r         )	
isinstancer   tuplelen
ValueErrorsuper__new___parameters_limits)cls
definitionbounds
parameterslimitsZboundobj	__class__r   ?/usr/lib/python3/dist-packages/sympy/vector/parametricregion.pyr   5   s"   
zParametricRegion.__new__c                 C   s
   | j d S )Nr   )argsselfr   r   r%   r   N      
zParametricRegion.definitionc                 C      | j S N)r   r'   r   r   r%   r!   R      zParametricRegion.limitsc                 C   r*   r+   )r   r'   r   r   r%   r    V   r,   zParametricRegion.parametersc                 C   s
   t | jS r+   )r   r!   r'   r   r   r%   
dimensionsZ   r)   zParametricRegion.dimensions)__name__
__module____qualname____doc__r   propertyr   r!   r    r-   __classcell__r   r   r#   r%   r      s    )


r   c                 C   s   t d)aN  
    Returns a list of ParametricRegion objects representing the geometric region.

    Examples
    ========

    >>> from sympy.abc import t
    >>> from sympy.vector import parametric_region_list
    >>> from sympy.geometry import Point, Curve, Ellipse, Segment, Polygon

    >>> p = Point(2, 5)
    >>> parametric_region_list(p)
    [ParametricRegion((2, 5))]

    >>> c = Curve((t**3, 4*t), (t, -3, 4))
    >>> parametric_region_list(c)
    [ParametricRegion((t**3, 4*t), (t, -3, 4))]

    >>> e = Ellipse(Point(1, 3), 2, 3)
    >>> parametric_region_list(e)
    [ParametricRegion((2*cos(t) + 1, 3*sin(t) + 3), (t, 0, 2*pi))]

    >>> s = Segment(Point(1, 3), Point(2, 6))
    >>> parametric_region_list(s)
    [ParametricRegion((t + 1, 3*t + 3), (t, 0, 1))]

    >>> p1, p2, p3, p4 = [(0, 1), (2, -3), (5, 3), (-2, 3)]
    >>> poly = Polygon(p1, p2, p3, p4)
    >>> parametric_region_list(poly)
    [ParametricRegion((2*t, 1 - 4*t), (t, 0, 1)), ParametricRegion((3*t + 2, 6*t - 3), (t, 0, 1)),     ParametricRegion((5 - 7*t, 3), (t, 0, 1)), ParametricRegion((2*t - 2, 3 - 2*t),  (t, 0, 1))]

    z?SymPy cannot determine parametric representation of the region.)r   )Zregr   r   r%   parametric_region_list_   s   #r4   c                 C   s   t | jgS r+   )r   r&   )r"   r   r   r%   _   s   r5   c                 C   s    |  | jj}| j}t||gS r+   )arbitrary_point	parameterr&   r!   r   )r"   r   r   r   r   r%   r5      s   tc                 C   s2   |  |j}t|dd}|ddt f}t||gS )NTrealr   r   )r6   r&   r   r   r   )r"   r7   r   r8   r   r   r   r%   r5      s   c           	      C   s   t |dd}| |j}tddD ]7}t|| | jd j|  |}t|| | jd j|  |}t|dkrHt|dkrH||d |d f} nq| |j}t||gS )NTr9   r   r   r   )r   r6   r&   ranger	   Zpointsr   r   )	r"   r7   r8   r   iZlower_boundZupper_boundr   Zdefinition_tupler   r   r%   r5      s   c                    s    fdd| j D }|S )Nc                    s   g | ]	}t | d  qS )r   )r4   ).0Zsider7   r   r%   
<listcomp>   s    _.<locals>.<listcomp>)Zsides)r"   r7   lr   r>   r%   r5      s   r8   sc                    sv   |  |}g }tt| jd D ]}t|| dd  fdd|D }| ddt f qt| }t|g|R  gS )Nr   Tr9   c              	      s$   g | ]}t | t d  qS )r   )r   Zsubsr   )r=   elemr>   r   r%   r?      s   $ r@   r   r   )	Zrational_parametrizationr;   r   Z	variablesr   appendr   r   r   )r"   r    r   r   r<   r   r>   r%   r5      s   
N)r8   )rB   )	functoolsr   Zsympyr   r   Zsympy.simplifyr   Z
sympy.corer   r   Zsympy.core.symbolr   Zsympy.solversr	   Zsympy.geometryr
   r   r   r   r   Zsympy.vectorr   r   r4   registerr5   r   r   r   r%   <module>   s.    T
%

