
    BPc                         d Z ddlZddlmZ  ed          \  ZZ	 ddlZ	ddl
mZ e	j        Zn# e$ r dZ	Y nw xY w G d dej                  Zedk    r e                                             dS dS )zJ
Perspective approach & math by Dmitry Platonov, shadowjack@mail.ru, 2006
    N)inkex_gettext   c                   @    e Zd ZdZd Zd Zd Zd Zed             Z	dS )Perspectivez,Apply a perspective to a path/group of pathsc                 ~	   t           !t          j        t          d                    t	          | j        j                  dk    r!t          j        t          d                    | j        j        \  }}t          |t          j        t          j	        f          rt          |t          j                  r|j
                            |                                                                          }t	          |          dk     st	          |d                   dk     r!t          j        t          d                    t          j        dt          	          }t!          d          D ]H}|d         |         d         d         ||         d<   |d         |         d         d         ||         d<   I|                    |                                                                          }t          j        |j        |j        g|j        |j        g|j        |j        g|j        |j        ggt          	          }n}t          |t          j	                  r!t          j        t          d
                    t          j        t          d                    t          j        t          d                    t          j        dt          	          }t          j        dt          	          }	dD ]E}||         d         ||         d<   ||         d         ||         d<   d||         d<   ||         d          ||         d         z  ||         d<   ||         d          ||         d         z  ||         d<   ||         d         ||dz            d<   ||         d         ||dz            d<   d||dz            d<   ||         d          ||         d         z  ||dz            d<   ||         d          ||         d         z  ||dz            d<   ||         d         |	|<   ||         d         |	|dz   <   Gt1          j        ||	          }
t          j        |
d         |
d         |
d         g|
d         |
d         |
d         g|
d         |
d         dggt          	          }|                     ||           d S )NzFailed to import the numpy or numpy.linalg modules. These modules are required by this extension. Please install them.  On a Debian-like system this can be done with the command, sudo apt-get install python-numpy.r   z-This extension requires two selected objects.   r      z@This extension requires that the second path be four nodes long.)r	   r   )dtypezMThe second selected object is a group, not a path.
Try using Object->Ungroup.zWThe second selected object is not a path.
Try using the procedure Path->Object to Path.zfThe first selected object is neither a path nor a group.
Try using the procedure Path->Object to Path.)   r   r   )r   r   r            r      g      ?)npinkexAbortExtension_lensvg	selection
isinstancePathElementGrouppath	transformcomposed_transformto_superpathzerosFLOATrangebounding_box	getparentarrayleftbottomtoprightlinsolveprocess_object)selfobjenveloper   dipibboxsip	solmatrix	free_termres
projmatrixs               -/usr/share/inkscape/extensions/perspective.pyeffectzPerspective.effect(   s   :&9    tx!""a''&ABB   *XcE-u{;<< 3	(E$566 +}..//11 ,..  t99q==CQLL1$4$4.*    hvU333q 1 1A $Q
1a 0CF1I $Q
1a 0CF1II ''(J(J(L(LMMhDK0DH-TX.T[1	     h44 .A    *?    &@    HV5111	HQe,,,	 	) 	)A!!fQiIaLO!!fQiIaLOIaLO"1vayj3q6!94IaLO"1vayj3q6!94IaLO"%a&)Ia!eQ"%a&)Ia!eQ"#Ia!eQ#&q6!9*s1vay"8Ia!eQ#&q6!9*s1vay"8Ia!eQq6!9IaL"1vayIa!ei	9--X!fc!fc!f%AAA'?#a&#a&RUAVW
 
 


 	C,,,,,    c                     t          |t          j                  r|                     ||           d S t          |t          j                  r|                     ||           d S d S )N)r   r   r   process_pathr   process_group)r+   r,   matrixs      r6   r*   zPerspective.process_object   sm    c5,-- 	,c6*****U[)) 	,sF+++++	, 	,r8   c                 <    |D ]}|                      ||           dS )z6Go through all groups to process all paths inside themN)r*   )r+   groupr<   nodes       r6   r;   zPerspective.process_group   s4     	. 	.Df----	. 	.r8   c                    |j                                                             |                                                                          }|D ]d}|D ]_}|                     |d         |          |d<   |                     |d         |          |d<   |                     |d         |          |d<   `et          j        |                              |                                           |_         dS )z-Apply the transformation to the selected pathr   r   r   N)r   to_absoluter   r   r   project_pointr   Path)r+   elementr<   pointsubscsps         r6   r:   zPerspective.process_path   s     L$$&&Yw113344\^^ 	
  	< 	<D < <++CFF;;A++CFF;;A++CFF;;A< z%((22G4N4N4P4P3PQQr8   c                 F   | t                    |d         d         z  | t                   |d         d         z  z   |d         d         z   | t                    |d         d         z  | t                   |d         d         z  z   |d         d         z   z  | t                    |d         d         z  | t                   |d         d         z  z   |d         d         z   | t                    |d         d         z  | t                   |d         d         z  z   |d         d         z   z  gS )z#Apply the matrix to the given pointr   r   r   )XY)rE   r<   s     r6   rB   zPerspective.project_point   s     1Xq	!$uQx&)A,'>>1MQx&)A,&qF1IaL)@@6!9Q<OQ1Xq	!$uQx&)A,'>>1MQx&)A,&qF1IaL)@@6!9Q<OQ
 	
r8   N)
__name__
__module____qualname____doc__r7   r*   r;   r:   staticmethodrB    r8   r6   r   r   %   sx        66\- \- \-|, , ,. . .
R R R 
 
 \
 
 
r8   r   __main__)rN   r   inkex.localizationr   r   r    rI   rJ   numpyr   numpy.linalglinalgr(   float64r   ImportErrorEffectExtensionr   rK   runrP   r8   r6   <module>rZ      s   &   1 1 1 1 1 1uQxx1JEE   	BBBB
 B
 B
 B
 B
%' B
 B
 B
J zKMM s   . 88