o
    GZhpa                     @   s   d Z ddlZddlmZmZmZmZmZmZ ddl	m
Z
mZmZmZmZmZmZmZmZmZmZ ddlmZ dd ZG dd	 d	ZG d
d dZG dd dZdS )z<Tests for the ``sympy.physics.mechanics.pathway.py`` module.    N)RationalSymbolcospisinsqrt)ForceLinearPathwayObstacleSetPathwayPathwayBasePointReferenceFrameWrappingCylinderWrappingGeometryBaseWrappingPathwayWrappingSpheredynamicsymbols)simplifyc                 C   s   dd | D S )Nc                 S   s    g | ]}| |j|j qS  )	__class__locationZvectorr   ).0loadr   r   Y/var/www/auris/lib/python3.10/site-packages/sympy/physics/mechanics/tests/test_pathway.py
<listcomp>   s    z#_simplify_loads.<locals>.<listcomp>r   )loadsr   r   r   _simplify_loads   s   r   c                	   @   s  e Zd Zdd Zeejdededfi fgdd Z	eejdedfededed	fgd
d Z
eejddedfeddfgdd Zejdddd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( ZdS ))TestLinearPathwayc                 C      t ttsJ d S N)
issubclassr	   r   selfr   r   r   test_is_pathway_base_subclass&      z/TestLinearPathway.test_is_pathway_base_subclasszargs, kwargspApBc                 C   s   | \}}t | i |}t|t sJ t|dsJ t|jdks"J |jd |u s+J |jd |u s4J t|jd ts>J |jd jdksHJ t|jd tsRJ |jd jdks\J d S )Nattachments   r      r%   r&   )r	   
isinstancehasattrlenr'   r   name)argskwargsZpointAZpointBinstancer   r   r   test_valid_constructor)   s   z(TestLinearPathway.test_valid_constructorr'   pZc                 C   8   t t t|  }W d    d S 1 sw   Y  d S r   )pytestraises
ValueErrorr	   r'   _r   r   r   )test_invalid_attachments_incorrect_number=      	
"z;TestLinearPathway.test_invalid_attachments_incorrect_numberNc                 C   r3   r   )r4   r5   	TypeErrorr	   r7   r   r   r   "test_invalid_attachments_not_pointI   r:   z4TestLinearPathway.test_invalid_attachments_not_pointTZautousec                 C   s~   t d| _td| _td| _t| j| j| _td| _td| _	td| _
tdd| _tdd| _tdd| _td| _d S )	NNr%   r&   q1q2q3r)   F)r   r>   r   r%   r&   r	   pathwayr   r?   r@   rA   q1dq2dq3dr   rB   r!   r   r   r   _linear_pathway_fixtureU   s   





z)TestLinearPathway._linear_pathway_fixturec                 C   s   t | j| j}tt d |_W d    n1 sw   Y  tt d |jd< W d    n1 s4w   Y  tt d |jd< W d    d S 1 sOw   Y  d S Nr   r)   )r	   r%   r&   r4   r5   AttributeErrorr'   r;   r"   r0   r   r   r   test_properties_are_immutablec   s   "z/TestLinearPathway.test_properties_are_immutablec                 C   s&   t | j| j}d}t||ksJ d S )NzLinearPathway(pA, pB))r	   r%   r&   reprr"   rC   expectedr   r   r   	test_reprl   s   zTestLinearPathway.test_reprc                 C   s,   | j | jd| jj  | jjdksJ d S Nr(   )r&   set_posr%   r>   xrC   lengthr!   r   r   r   test_static_pathway_lengthq      z,TestLinearPathway.test_static_pathway_lengthc                 C   s,   | j | jd| jj  | jjdksJ d S Nr(   r   )r&   rQ   r%   r>   rR   rC   extension_velocityr!   r   r   r   &test_static_pathway_extension_velocityu   rU   z8TestLinearPathway.test_static_pathway_extension_velocityc                 C   s\   | j | jd| jj  | j| j | jj f| j | j| jj fg}| j| j|ks,J d S rP   )r&   rQ   r%   r>   rR   rB   rC   to_loadsr"   rN   r   r   r   test_static_pathway_to_loadsy   s
   z.TestLinearPathway.test_static_pathway_to_loadsc                 C   sD   | j | jd| j | jj  dt| jd  }| jj|ks J d S rP   )	r&   rQ   r%   r?   r>   rR   r   rC   rS   rZ   r   r   r   test_2D_pathway_length   s   z(TestLinearPathway.test_2D_pathway_lengthc                 C   sP   | j | jd| j | jj  dt| jd  | j | j }| jj	|ks&J d S rP   )
r&   rQ   r%   r?   r>   rR   r   rD   rC   rW   rZ   r   r   r   "test_2D_pathway_extension_velocity   s   z4TestLinearPathway.test_2D_pathway_extension_velocityc                 C   s   | j | jd| j | jj  | j| j | jt| jd   | jj f| j | j| jt| jd   | jj fg}| j	| j|ksCJ d S rP   )
r&   rQ   r%   r?   r>   rR   rB   r   rC   rY   rZ   r   r   r   test_2D_pathway_to_loads   s
   (&z*TestLinearPathway.test_2D_pathway_to_loadsc                 C   s|   | j | j| j| jj | j| jj  d| j | jj	   t
| jd | jd  d| jd   }t| jj| dks<J d S Nr(      r   )r&   rQ   r%   r?   r>   rR   r@   yrA   zr   r   rC   rS   rZ   r   r   r   test_3D_pathway_length   s   ,&z(TestLinearPathway.test_3D_pathway_lengthc                 C   s   | j | j| j| jj | j| jj  d| j | jj	   t
| jd | jd  d| jd   }| j| j | | j| j |  d| j | j |  }t| jj| dksVJ d S r_   )r&   rQ   r%   r?   r>   rR   r@   ra   rA   rb   r   rD   rE   rF   r   rC   rW   )r"   rS   rN   r   r   r   "test_3D_pathway_extension_velocity   s   ,&z4TestLinearPathway.test_3D_pathway_extension_velocityc                 C   s(  | j | j| j| jj | j| jj  d| j | jj	   t
| jd | jd  d| jd   }| j | j | jj | | j| j | jj |  d| j | j | jj	 |  }| j| j | jj | | j| j | jj |  d| j | j | jj	 |  }| j|f| j |fg}| j| j|ksJ d S )Nr(   r`   )r&   rQ   r%   r?   r>   rR   r@   ra   rA   rb   r   rB   rC   rY   )r"   rS   pO_forceZpI_forcerN   r   r   r   test_3D_pathway_to_loads   s*   ,&z*TestLinearPathway.test_3D_pathway_to_loads)__name__
__module____qualname__r#   staticmethodr4   markparametrizer   r1   r9   r<   fixturerG   rK   rO   rT   rX   r[   r\   r]   r^   rc   rd   rf   r   r   r   r   r   $   sL    



	r   c                
   @   s~  e Zd Zdd Zeejdddd dD fdd	d d
D fddd dD fddd dD fgdd Zeejde	dge	de	dggdd Z
eejdde	de	dfe	dde	dfe	de	ddfgdd Zdd Zeejddd dD d fd!d d
D d"fd#d dD d$fgd%d& Zejd'd(d)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 ZdS )7TestObstacleSetPathwayc                 C   r   r   )r    r
   r   r!   r   r   r   r#      r$   z4TestObstacleSetPathway.test_is_pathway_base_subclassznum_attachments, attachments   c                 C      g | ]}t |qS r   r   r   r-   r   r   r   r          z!TestObstacleSetPathway.<listcomp>)pOr%   pIr`   c                 C   rp   r   rq   rr   r   r   r   r      rs   )rt   r%   r&   ru      c                 C   rp   r   rq   rr   r   r   r   r      rs   )rt   r%   r&   pCru      c                 C   rp   r   rq   rr   r   r   r   r      rs   )rt   r%   r&   rw   ZpDru   c                 C   sT   t | }t|t sJ t|dsJ t|j| ksJ |jD ]	}t|ts'J qd S )Nr'   )r
   r*   r+   r,   r'   r   )Znum_attachmentsr'   r0   
attachmentr   r   r   r1      s   
z-TestObstacleSetPathway.test_valid_constructorr'   rt   ru   c                 C   r3   r   )r4   r5   r6   r
   r7   r   r   r   5test_invalid_constructor_attachments_incorrect_number   s   
"zLTestObstacleSetPathway.test_invalid_constructor_attachments_incorrect_numberNr%   c                 C   r3   r   r4   r5   r;   r   r7   r   r   r   .test_invalid_constructor_attachments_not_point   s   

"zETestObstacleSetPathway.test_invalid_constructor_attachments_not_pointc                 C   s   t tdtdtd}tt d |_W d    n1 sw   Y  tt d |jd< W d    n1 s9w   Y  tt d |jd< W d    n1 sSw   Y  tt d |jd< W d    d S 1 snw   Y  d S )Nrt   r%   ru   r   r)   )r
   r   r4   r5   rI   r'   r;   r"   rC   r   r   r   rK      s   "z4TestObstacleSetPathway.test_properties_are_immutablezattachments, expectedc                 C   rp   r   rq   rr   r   r   r   r      rs   zObstacleSetPathway(pO, pA, pI)c                 C   rp   r   rq   rr   r   r   r   r      rs   z"ObstacleSetPathway(pO, pA, pB, pI)c                 C   rp   r   rq   rr   r   r   r   r     rs   z&ObstacleSetPathway(pO, pA, pB, pC, pI)c                 C   s   t |  }t||ksJ d S r   )r
   rL   )r'   rN   rC   r   r   r   rO      s   z TestObstacleSetPathway.test_reprTr=   c                 C   sV   t d| _td| _td| _td| _td| _td| _tdd| _	t
d| _d S )	Nr>   rt   ru   r%   r&   qr)   rB   )r   r>   r   rt   ru   r%   r&   r   r   qdr   rB   r!   r   r   r   _obstacle_set_pathway_fixture  s   





z4TestObstacleSetPathway._obstacle_set_pathway_fixturec                 C   sp   | j | j| jj | j| j| jj | j| j| jj t	| j| j | j| j}|j
ddtd  ks6J d S )Nr)   r(   )r%   rQ   rt   r>   rR   r&   ra   ru   rb   r
   rS   r   r~   r   r   r   rT     s
   z1TestObstacleSetPathway.test_static_pathway_lengthc                 C   sd   | j | j| jj | j| j| jj | j| j| jj t	| j| j | j| j}|j
dks0J d S Nr   )r%   rQ   rt   r>   rR   r&   ra   ru   rb   r
   rW   r~   r   r   r   rX     s
   z=TestObstacleSetPathway.test_static_pathway_extension_velocityc              
   C   s8  | j | j| jj | j| j| jj | j| j| jj t	| j| j | j| j}t
| j| j | jj t
| j | j| jj t
| j | jtd d | jj| jj  t
| j| jtd d | jj| jj  t
| j| jtd d | jj| jj  t
| j| jtd d | jj| jj  g}|| j|ksJ d S rP   )r%   rQ   rt   r>   rR   r&   ra   ru   rb   r
   r   rB   r   rY   rM   r   r   r   r[   &  s   ((((z3TestObstacleSetPathway.test_static_pathway_to_loadsc                 C   s   | j | j| jj| jj   | j| jt| j| jj t	| jd | jj   | j
| jt	| j| jj t| jd | jj   t| j| j | j| j
}dtd tddt| j   }|j|  dksjJ d S Nr)   r(   r   )r%   rQ   rt   r>   rR   ra   r&   r   r   r   ru   r
   r   rS   r   rM   r   r   r   r\   5  s   **"z-TestObstacleSetPathway.test_2D_pathway_lengthc                 C   s   | j | j| jj| jj   | j| jt| j| jj t	| jd | jj   | j
| jt	| j| jj t| jd | jj   t| j| j | j| j
}tdt	| j | j  dtt| jd   }|j|  dksqJ d S r   )r%   rQ   rt   r>   rR   ra   r&   r   r   r   ru   r
   r   r   rW   r   rM   r   r   r   r]   A  s   **0z9TestObstacleSetPathway.test_2D_pathway_extension_velocityc              	   C   s  | j | j| jj| jj   | j| jt| j| jj t	| jd | jj   | j
| jt	| j| jj t| jd | jj   t| j| j | j| j
}tdd | jj| jj  }tdt| j d  d | jj tdt	| j dtt| jd   | jj  }t| jtd  | jj t	| jtd  | jj  }t| j| j| t| j | j | t| j | j| t| j| j | t| j| j| t| j
| j | g}t|| j|ksJ d S )Nr)   r(   r`   )r%   rQ   rt   r>   rR   ra   r&   r   r   r   ru   r
   r   r   r   rB   r   rY   )r"   rC   ZpO_pA_force_vecZpA_pB_force_vecZpB_pI_force_vecrN   r   r   r   r^   M  s,   **".4z/TestObstacleSetPathway.test_2D_pathway_to_loads)rg   rh   ri   r#   rj   r4   rk   rl   r1   r   rz   r|   rK   rO   rm   r   rT   rX   r[   r\   r]   r^   r   r   r   r   rn      sf    	


rn   c                   @   s@  e Zd Zdd Zejdddd Zdd Zej	d	e
d
fe
d
e
de
dfgdd Zeej	d	de
dfe
d
dfgdd Zdd Zej	dededededjgdd Zdd Zdd Zdd Zed d! Zej	d"d#d$ed% fd$ed%d% ed% d% d&fd'e d( fd#ed)d%ed'd% d&fed' fgd*d+ Zej	d"d#d$ed)d%e fd#d,efd,d#efd$ed%d% ed% d% d&fd-e d( fd#ed)d%ed'd% d&fed' fd$ed%ed)d% ed% ed)d% d)fed)ed-d(e d%  fd#ed)d%ed'ed)d% d)fed)ed)d'e d%  fgd.d/ Zej	d0d1d$ed%ed)d% ed% ed)d% d&ffd#ed)d%ed'ed)d% d&ffgd2d3 Zej	d0d1d4d5d$ed%d% ed% d% d&ffd#ed)d%ed'd% d&ffd$ed%ed)d% ed% d% d)ffd#ed)d%ed'd% d)ffgd6d7 Zej	d8d9d$ed%d% ed% d% d&fd#ed%d% ed%d% d&fd:ed%d%  ed% d% d&ffd#ed)d%ed'd% d&fd$ed'd% ed)d% d&fed' d% ed)d%d) d&fffd;d< Zej	d8d9d=d>d$ed%d% ed% d% d&fd,ed% d% ed% d% d&fd)ed%d%  ed%d% d&ffd#ed)d%ed'd% d&fd$ed'd% ed)d% d&fed' d% ed)d%d) d&ffd#ed%d% ed%d% d&fd$ed%d% ed% d% d&fed% d% ed%d% d) d&ffd?d$ed%d% ed% d% d)fd@e edAdBed%    d&d(edAdBed%    fd@ed% e d%edAdBed%     d@ed% e d%edAdBed%     dCedAdBed%    fd-ed%d%  e d%edAdBed%     d-ed% e d%edAdBed%     d&fffdDdE Z dFdG Z!dHdI Z"dJdK Z#dS )LTestWrappingPathwayc                 C   r   r   )r    r   r   r!   r   r   r   r#   i  r$   z1TestWrappingPathway.test_is_pathway_base_subclassTr=   c                 C   s   t d| _t d| _tddd| _t d| _td| _| jj| _	t
| j| j| _t| j| j| j	| _t| j| j| j| _td| _d S )	Nr%   r&   rT)Zpositivert   r>   rB   )r   r%   r&   r   r   rt   r   r>   rb   axr   spherer   cylinderr   rC   rB   r!   r   r   r   _wrapping_pathway_fixturel  s   




z-TestWrappingPathway._wrapping_pathway_fixturec                 C   s   t | j| j| j}t|t sJ t|dsJ t|jdks J t|jd ts*J |jd | jks4J t|jd ts>J |jd | jksHJ t|dsOJ t|j	t
sWJ |j	| jks_J d S )Nr'   r(   r   r)   geometry)r   r%   r&   r   r*   r+   r,   r'   r   r   r   rJ   r   r   r   r1   y  s   z*TestWrappingPathway.test_valid_constructorr'   r%   r&   r2   c                 C   sD   t t tg || jR  }W d    d S 1 sw   Y  d S r   )r4   r5   r;   r   r   )r"   r'   r8   r   r   r   rz     s   "zITestWrappingPathway.test_invalid_constructor_attachments_incorrect_numberNc                 C   r3   r   r{   r7   r   r   r   r|     r:   zBTestWrappingPathway.test_invalid_constructor_attachments_not_pointc                 C   s>   t t t| j| j}W d    d S 1 sw   Y  d S r   r4   r5   r;   r   r%   r&   )r"   r8   r   r   r   1test_invalid_constructor_geometry_is_not_supplied  s   "zETestWrappingPathway.test_invalid_constructor_geometry_is_not_suppliedr   r   r   r>   c                 C   s@   t t t| j| j|}W d    d S 1 sw   Y  d S r   r   )r"   r   r8   r   r   r   "test_invalid_geometry_not_geometry  s   
"z6TestWrappingPathway.test_invalid_geometry_not_geometryc                 C   sv   t t | j| jjd< W d    n1 sw   Y  t t | j| jjd< W d    d S 1 s4w   Y  d S rH   )r4   r5   r;   r&   rC   r'   r%   r!   r   r   r   &test_attachments_property_is_immutable  s   "z:TestWrappingPathway.test_attachments_property_is_immutablec                 C   s8   t t d | j_W d    d S 1 sw   Y  d S r   )r4   r5   rI   rC   r   r!   r   r   r   #test_geometry_property_is_immutable  s   
"z7TestWrappingPathway.test_geometry_property_is_immutablec                 C   s$   d| j d}t| j|ksJ d S )Nz!WrappingPathway(pA, pB, geometry=))r   rL   rC   rZ   r   r   r   rO     s
   zTestWrappingPathway.test_reprc                 C   s   t dd t| |D S )Nc                 s       | ]	\}}|| V  qd S r   r   r   magunitr   r   r   	<genexpr>  s    z9TestWrappingPathway._expand_pos_to_vec.<locals>.<genexpr>)sumzip)posframer   r   r   _expand_pos_to_vec  s   z&TestWrappingPathway._expand_pos_to_veczpA_vec, pB_vec, factorr)   r   r   r   r)   r   r(   r   ro   r`   r)   c                 C   s~   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}|| j }t	|j
| dks=J d S r   )r   r>   r%   rQ   rt   r   r&   r   r   r   rS   r"   pA_vecpB_vecfactorrC   rN   r   r   r   $test_static_pathway_on_sphere_length  s   	
z8TestWrappingPathway.test_static_pathway_on_sphere_lengthr}   r   r   rv   c                 C   s   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}|t	| jd  }t
|j| dksAJ d S rV   )r   r>   r%   rQ   rt   r   r&   r   r   r   r   rS   r   r   r   r   &test_static_pathway_on_cylinder_length  s   z:TestWrappingPathway.test_static_pathway_on_cylinder_lengthzpA_vec, pB_vec)r   r   c                 C   l   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}|j	dks4J d S r   )
r   r>   r%   rQ   rt   r   r&   r   r   rW   r"   r   r   rC   r   r   r   0test_static_pathway_on_sphere_extension_velocity  s   	zDTestWrappingPathway.test_static_pathway_on_sphere_extension_velocity)r   r   )r   r   c                 C   r   r   )
r   r>   r%   rQ   rt   r   r&   r   r   rW   r   r   r   r   2test_static_pathway_on_cylinder_extension_velocity  s   zFTestWrappingPathway.test_static_pathway_on_cylinder_extension_velocityzApA_vec, pB_vec, pA_vec_expected, pB_vec_expected, pO_vec_expected)r   r   r   r   )r}   r}   r   r}   c              	   C   s<  |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}t	dd t
|| jD }t	dd t
|| jD }t	dd t
|| jD }t| j| j| jd t| jd   | t| j| j| jd t| jd   | t| j| j| jd t| jd   | g}|| j|ksJ d S )Nc                 s   r   r   r   r   r   r   r   r   7      
zMTestWrappingPathway.test_static_pathway_on_sphere_to_loads.<locals>.<genexpr>c                 s   r   r   r   r   r   r   r   r   :  r   c                 s   r   r   r   r   r   r   r   r   =  r   ro   rx   )r   r>   r%   rQ   rt   r   r&   r   r   r   r   r   rB   r   rY   )r"   r   r   pA_vec_expectedpB_vec_expectedpO_vec_expectedrC   rN   r   r   r   &test_static_pathway_on_sphere_to_loads  s&   


(((z:TestWrappingPathway.test_static_pathway_on_sphere_to_loads)r   r   r   r   )r   r   )r   r   r   r}   r   r   )r   r(   r   )r   )r   r)   r)   )r   r   r)   )r   r   r}   )r   r   r         c                 C   s   |  || j}|  || j}| j| j| j|  | j| j| j|  t| j| j| j}| j	|  || j }| j	|  || j }| j	|  || j }	t
| j|t
| j|t
| j|	g}
t|| j	|
kshJ d S r   )r   r>   r%   rQ   rt   r   r&   r   r   rB   r   r   rY   )r"   r   r   r   r   r   rC   ZpA_force_expectedZpB_force_expectedZpO_force_expectedrN   r   r   r   (test_static_pathway_on_cylinder_to_loadsG  s&   5





z<TestWrappingPathway.test_static_pathway_on_cylinder_to_loadsc                 C   s   t d}| j| jj }| jt|| jj t|| jj   }| j| j	| | j
| j	| | jt|d  }t| jj| dksCJ d S )Nr   r(   r   )r   r   r>   rR   r   r   ra   r%   rQ   rt   r&   r   r   rC   rS   )r"   r   pA_pospB_posrN   r   r   r   "test_2D_pathway_on_cylinder_length  s   &z6TestWrappingPathway.test_2D_pathway_on_cylinder_lengthc                 C   s   t d}t dd}| j| jj }| jt|| jj t|| jj   }| j| j	| | j
| j	| | jt|d |  | }t| jj| dksLJ d S )Nr   r)   r(   r   )r   r   r>   rR   r   r   ra   r%   rQ   rt   r&   r   r   rC   rW   )r"   r   r   r   r   rN   r   r   r   .test_2D_pathway_on_cylinder_extension_velocity  s   
&zBTestWrappingPathway.test_2D_pathway_on_cylinder_extension_velocityc           	      C   s   t d}| j| jj }| jt|| jj t|| jj   }| j| j	| | j
| j	| | j| jj }| jt|| jj t|| jj   }| jt| | jj t|d | jj   }t| j|t| j
|t| j	|g}t| j| j}||ks~J d S )Nr   r)   )r   r   r>   rR   r   r   ra   r%   rQ   rt   r&   rB   r   r   rC   rY   )	r"   r   r   r   ZpA_forceZpB_forcere   rN   r   r   r   r   $test_2D_pathway_on_cylinder_to_loads  s   &&,


z8TestWrappingPathway.test_2D_pathway_on_cylinder_to_loads)$rg   rh   ri   r#   r4   rm   r   r1   rk   rl   r   rz   rj   r|   r   r   r   r   rR   r   r   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   g  s   





	
( 
	( &
	* 
$

4&&*&
-	
r   )__doc__r4   Zsympyr   r   r   r   r   r   Zsympy.physics.mechanicsr   r	   r
   r   r   r   r   r   r   r   r   Zsympy.simplify.simplifyr   r   r   rn   r   r   r   r   r   <module>   s     4  )