
    BPc                         d dl Z d dlmZ d dlmZ d dlmZ  G d de j                  Z	e
dk    r e	                                             dS dS )    N)DirectedLineSegment)inkex_gettext)truedivc                   F    e Zd ZdZd Zd Zd Zd Zd Ze	d             Z
dS )	Envelopez.Distort a path/group of paths to a second pathc                 d   t          | j        j                  dk    r!t          j        t          d                    | j        j        \  }}t          |t          j        t          j        f          rt          |t          j                  r|	                    |
                                                                          }|j                            |                                                                          }|                     |          }n}t          |t          j                  r!t          j        t          d                    t          j        t          d                    t          j        t          d                    |                     |||           d S )N   z!You must select two objects only.zMThe 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.)lensvg	selectioninkexAbortExtension_
isinstancePathElementGroupbounding_box	getparentcomposed_transformpath	transformto_superpathenvelope_box_from_pathprocess_object)selfobjenvelopebboxr   tboxs         //usr/share/inkscape/extensions/path_envelope.pyeffectzEnvelope.effect   s   tx!""a''&q)L'M'MNNN*XcE-u{;<< 	(E$566 ''(J(J(L(LMM  }..//11 ,..  22488h44 .A    *?    &;    	Ct,,,,,    c                    t          |          dk     st          |d                   dk     r!t          j        t          d                    d |D             d         d d         }t	          |d         |d                   t	          |d         |d                   t	          |d         |d                   t	          |d         |d                   g}d |D             }d	|d                             |d                   cxk    rK|d                             |d                   cxk    r%|d                             |d                   k    r$n n!t          j        t          d
                    |S )N   r      z>Second selected path is too short. Must be four or more nodes.c                 &    g | ]}d  |D             S )c                 F    g | ]}|d          d         |d          d          fS )r$   r    ).0csps     r    
<listcomp>z>Envelope.envelope_box_from_path.<locals>.<listcomp>.<listcomp>J   s-    999S3q6!9c!fQi(999r"   r(   )r)   subss     r    r+   z3Envelope.envelope_box_from_path.<locals>.<listcomp>J   s'    TTTd99D999TTTr"   r	      c                     g | ]	}|j         
S r(   )vector)r)   segments     r    r+   z3Envelope.envelope_box_from_path.<locals>.<listcomp>T   s    444G444r"           z?The points for the selected envelope must not all be in a line.)r
   r   r   r   r   cross)r   envelope_pathtrafor   vectss        r    r   zEnvelope.envelope_box_from_pathE   s   }!!Sq)9%:%:Q%>%>&RSS   UTmTTTUVWQB

  a%(33a%(33a%(33a%(33	
 54t444Qx~~eAh''( ( ( (Qx~~eAh''( ( ( ( Qx~~eAh''( ( ( ( (
 &STT   r"   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   r   r   s       r    r   zEnvelope.process_object`   sq    c5,-- 	0c4.....U[)) 	0sD$/////	0 	0r"   c                 >    |D ]}|                      |||           dS )z6Go through all groups to process all paths inside themN)r   )r   groupr   r   nodes        r    r8   zEnvelope.process_groupf   s6     	2 	2DdD1111	2 	2r"   c                    |j                                                             |                                                                          }|D ]O}|D ]J} | j        ||g|d         R  |d<    | j        ||g|d         R  |d<    | j        ||g|d         R  |d<   KP|                                                    |                                           |_         d S )Nr   r$   r	   )r   to_absoluter   r   r   transform_pointto_path)r   elementr   r   pointsr,   r*   s          r    r7   zEnvelope.process_pathk   s    L$$&&Yw113344\^^ 	  	C 	CD C C--dDB3q6BBBA--dDB3q6BBBA--dDB3q6BBBAC ~~''1173M3M3O3O2OPPr"   c                 Z   ||f|j         z
  }t          t          ||j        |j        f          \  }}t          | d                             |          | d                             |                    }t          | d                             |          | d                             |                    }|j                            |j                  }	|	dk    r|j	        dk    r|j
        S |j	        dk    r|j
        S |j                            |j                  dk     r&|j
        |j
        z
  j	        dk    r|j
        S |j        S |j
        |j        z
  j	        dk     r|j
        S |j        S |j
        |j
        z
                      |j                  |	z  }
|                    |
          S )z0Transform algorithm thanks to Jose Hevia (freon)r   r	   r-   r$   r1   g:0yE>)minimummapr   widthheightr   point_at_ratior/   r2   lengthstartdotend)r   r   xyr/   xratioyratiohorzvertdenomintersect_ratios              r    r>   zEnvelope.transform_point}   s    Q$,&Wftz4;.GHH"G""6**DG,B,B6,J,J
 
 #G""6**DG,B,B6,J,J
 
 !!$+..C<<{c!!z!{c!!z!{t{++a//J+3t;;:%x
TX%-44z!8O:
299$+FFN""?333r"   N)__name__
__module____qualname____doc__r!   r   r   r8   r7   staticmethodr>   r(   r"   r    r   r      s        88&- &- &-P  60 0 02 2 2
Q Q Q$ 4 4 \4 4 4r"   r   __main__)r   inkex.transformsr   inkex.localizationr   r   operatorr   EffectExtensionr   rT   runr(   r"   r    <module>r_      s   (  0 0 0 0 0 0 1 1 1 1 1 1      A4 A4 A4 A4 A4u$ A4 A4 A4H zHJJNN r"   