�
��gk@ � �� � d dl mZmZmZmZmZ d dlmZ d dlm Z m
Z
d dlmZm
Z
mZ d dlmZ d dlmZ d dlmZmZmZ dd lmZ dd
lmZmZ ddlmZ ddlmZm Z m!Z! dd
l"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ d dl,m-Z-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3m4Z4 d dl5m6Z6 d dl7Z7d� e8d� � D � � \ Z9Z:Z; G d� de� � Z< G d� de<� � Z= G d� de<� � Z>d� Z?d� Z@d � ZAd!� ZBd"� ZCd#� ZDdS )$� )�Expr�S�oo�pi�sympify)�N)�default_sort_key�ordered)�_symbol�Dummy�Symbol)�sign)� Piecewise)�cos�sin�tan� )�Circle)�GeometryEntity�GeometrySet)�
GeometryError)�Line�Segment�Ray��Point)�And)�Matrix��simplify)�solve)�has_dups�has_variety�uniq�rotate_left�least_rotation)�as_int� func_name)�prec_to_dpsNc �0 � g | ]}t d d�� � ��S )�
polygon_dummyT��real)r )�.0�is �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/geometry/polygon.py�
<listcomp>r1 s% � �
?�
?�
?��5��t�,�,�,�
?�
?�
?� � c �\ � e Zd ZdZdZdd�d�Zed� � � Zed� � � Z ed� � � Z
ed � � � Zed
� � � Zed� � � Z
ed� � � Zd$d�Zd$d�Zd� Zd$d�Zed� � � Zed� � � Zd� Zd� Zd%d�Zd� Zd%d�Zd� Zd� Zd� Zd� Zd&d �Zd!� Zd"� Z d$d#�Z!d
S )'�Polygona� A two-dimensional polygon.
A simple polygon in space. Can be constructed from a sequence of points
or from a center, radius, number of sides and rotation angle.
Parameters
==========
vertices
A sequence of points.
n : int, optional
If $> 0$, an n-sided RegularPolygon is created.
Default value is $0$.
Attributes
==========
area
angles
perimeter
vertices
centroid
sides
Raises
======
GeometryError
If all parameters are not Points.
See Also
========
sympy.geometry.point.Point, sympy.geometry.line.Segment, Triangle
Notes
=====
Polygons are treated as closed paths rather than 2D areas so
some calculations can be be negative or positive (e.g., area)
based on the orientation of the points.
Any consecutive identical points are reduced to a single point
and any points collinear and between two points will be removed
unless they are needed to define an explicit intersection (see examples).
A Triangle, Segment or Point will be returned when there are 3 or
fewer points provided.
Examples
========
>>> from sympy import Polygon, pi
>>> p1, p2, p3, p4, p5 = [(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
>>> Polygon(p1, p2, p3, p4)
Polygon(Point2D(0, 0), Point2D(1, 0), Point2D(5, 1), Point2D(0, 1))
>>> Polygon(p1, p2)
Segment2D(Point2D(0, 0), Point2D(1, 0))
>>> Polygon(p1, p2, p5)
Segment2D(Point2D(0, 0), Point2D(3, 0))
The area of a polygon is calculated as positive when vertices are
traversed in a ccw direction. When the sides of a polygon cross the
area will have positive and negative contributions. The following
defines a Z shape where the bottom right connects back to the top
left.
>>> Polygon((0, 2), (2, 2), (0, 0), (2, 0)).area
0
When the keyword `n` is used to define the number of sides of the
Polygon then a RegularPolygon is created and the other arguments are
interpreted as center, radius and rotation. The unrotated RegularPolygon
will always have a vertex at Point(r, 0) where `r` is the radius of the
circle that circumscribes the RegularPolygon. Its method `spin` can be
used to increment that angle.
>>> p = Polygon((0,0), 1, n=3)
>>> p
RegularPolygon(Point2D(0, 0), 1, 3, 0)
>>> p.vertices[0]
Point2D(1, 0)
>>> p.args[0]
Point2D(0, 0)
>>> p.spin(pi/2)
>>> p.vertices[0]
Point2D(0, 1)
� r )�nc �J �� |rmt |� � }t |� � dk r|� |� � n)t |� � dk r|� d|� � t |i ���S �fd�|D � � }g }|D ]&}|r
||d k r�|� |� � �'t |� � dk r&|d |d k r|� � � d}|t |� � dz
k r�t |� � dk r�|| ||dz ||dz }
} }t
j || |
� � r4|� |dz � � ||
k r|� |� � n|dz
}|t |� � dz
k rt |� � dk ��t |� � }t |� � dk rt j | g|�R i ���S t |� � dk rt |i ���S t |� � dk rt |i ���S t
|i ���S )N� r3 c �. �� g | ]}t |fd di�����S ��dimr9 r �r. �a�kwargss �r0 r1 z#Polygon.__new__.<locals>.<listcomp>� �. �� �<�<�<�!�E�!�-�-��-�f�-�-�<�<�<r2 �����r r �����)�list�len�append�insert�RegularPolygon�popr �is_collinearr �__new__�Triangler )�clsr7 �argsr? �vertices�nodup�pr/ r>