
    }fS9                     |   	 d dl Z e j        Zn# eef$ r d dlm Z  dZY nw xY wd dlmZmZm	Z	 d dl
mZmZ eeef         Zeeef         Zee         Zee         Ze	edf         Zee         Zee         ZdZe j         e j        e j        e j        e j        e j        e j        e j        e j        e j        e j        	  	        ded	ed
ededef
d                        ZdededefdZdedededefdZe j        e j         e j        e j        e j        e j        e j        e j        e j                   e j        e          dededededef
d                                                Z e j        e j        e j        e j        e j        e j        e j        e j        e          	 d&dedededefd            Z  e j        e j        e j        e j        e j        e j        ee j                   e            d dfdedededefd            Z!de"defdZ#d eded!efd"Z$	 d'dedededefd$Z%	 d'dededededef
d%Z&dS )(    N)cythonF)SequenceTupleUnion)IntegralReal   )	jnx1x2d1d2scalexdcoordsrc1rd1rc2rd2c                    ddg}dD ]}g x||<   }||         ||         ||         ||         f\  }}	}
}||	k    rIt          |           }|
|k    r|                    |
g|z             n|                    dg|z             {||	k    r|	|}	}||
}}
||
z
  |	|z
  z  }| D ]<}||         }||k    r|
}n||	k    r|}n|
||z
  |z  z   }|                    |           =t          | S )zGiven two reference coordinates `rc1` & `rc2` and their respective
    delta vectors `rd1` & `rd2`, returns interpolated deltas for the set of
    coordinates `coords`.Nr      r   )lenextendappendzip)r   r   r   r   r   
out_arraysr
   outr   r   r   r   r   r   pairr   r   s                    M/var/www/rtfcompare/venv/lib/python3.11/site-packages/fontTools/varLib/iup.pyiup_segmentr#      sB   * J    
1QQQQ7BB88FARxx

B4!8$$$$

A37###77BB bR"W% 	 	DQABwwb !b&E))JJqMMMM	 
    deltasreturnc                 6   t          |           t          |          k    sJ d| vr| S t          |           }d t          |           D             }|sdg|z  S g }t          |          }t          |          }|dk    rWd|||d         f\  }}}	}
|                    t          |||         ||	         | |	         ||
         | |
                              |                    | |                    |D ]|}||z
  dk    rT|dz   |||f\  }}}	}
|                    t          |||         ||	         | |	         ||
         | |
                              |                    | |                    |}}||dz
  k    rZ|dz   |||d         f\  }}}	}
|                    t          |||         ||	         | |	         ||
         | |
                              t          |           t          |          k    s&J t          |           t          |          f            |S )zFor the contour given in `coords`, interpolate any missing
    delta values in delta vector `deltas`.

    Returns fully filled-out delta vector.Nc                     g | ]	\  }}||
S N ).0ivs      r"   
<listcomp>ziup_contour.<locals>.<listcomp>c   s    @@@TQ!-q---r$   )r   r   r   r   )r   	enumerateiternextr   r#   r   )r%   r   r   indicesr    itstarti1i2ri1ri2ends               r"   iup_contourr;   W   sT    v;;#f++%%%%6FA@@Yv..@@@G x!|
C	gBHHEzzeUGBK7BS

r"uvc{F3KfSk 	
 	
 	

 JJve} 	 	;??$qy#uc9BCJJ2b5M6#;sVC[&QT+   
 	

6#;A~~ 19a
:BS

r"uvc{F3KfSk 	
 	
 	
 v;;#c(("""S[[#c(($;"""Jr$   endsc                 H   t          |          |k    r#t          |          |r|d         dz   nddz   k    sJ t          |          }||dz
  |dz
  |dz
  |dz
  gz   }g }d}|D ]>}|dz  }t          | ||         |||                   }|                    |           |}?|S )zFor the outline given in `coords`, with contour endpoints given
    in sorted increasing order in `ends`, interpolate any missing
    delta values in delta vector `deltas`.

    Returns fully filled-out delta vector.r/   r   r            )sortedr   r;   r   )r%   r   r<   r   r    r5   r:   contours           r"   	iup_deltarC      s     $<<4CKKD4ODHqLLaST3T$T$T$T$TFA1q5!a%QA..D
CE  qfU3Y/c	1BCC

7Jr$   )r,   r
   r   ypqr,   r
   	tolerancec                     ||z
  dk    sJ t          ||dz   |         ||         | |         ||         | |                   }| |dz   |         } t          fdt          | |          D                       S )zReturn true if the deltas for points at `i` and `j` (`i < j`) can be
    successfully used to interpolate deltas for points in between them within
    provided error tolerance.r@   r   c              3   x   K   | ]4\  \  }}\  }}t          t          ||z
  ||z
                      k    V  5d S r)   abscomplex)r+   r   rD   rE   rF   rG   s        r"   	<genexpr>z%can_iup_in_between.<locals>.<genexpr>   sb        FQFQ 	GAE1q5!!""i/     r$   )r#   allr   )r%   r   r,   r
   rG   interps       ` r"   can_iup_in_betweenrP      s    . q5A::::A	*F1Ivay&)VTUYWWFAEAIF    !&&11     r$   )cjdjlcjldjncjndjforceforcedc                    t          |           t          |          k    sJ t          |           }t                      }t          t          |           dz
  dd          D ]}| |dz
           ||dz
           }}| |         ||         }	}| ||z
  dz            |||z
  dz            }}
dD ]`}|	|         }||         }||         }||         }||         }|
|         }||k    r	||}}||}}n||}}||}}d}||k    r,t          ||z
            |k    rt          |          |k    rd}n||cxk    r|k    r7n n4t	          ||          |z
  |cxk    rt          ||          |z   k    sn d}n||k    r||k     r=t          |          |k    r)t          ||z
            |k    r||z
  |k     ||k     k    rd}n<t          |          |k    r)t          ||z
            |k    r|||z   k     ||k     k    rd}|r|                    |            nb|S )a  The forced set is a conservative set of points on the contour that must be encoded
    explicitly (ie. cannot be interpolated).  Calculating this set allows for significantly
    speeding up the dynamic-programming, as well as resolve circularity in DP.

    The set is precise; that is, if an index is in the returned set, then there is no way
    that IUP can generate delta for that point, given `coords` and `deltas`.
    r   r/   r   FT)r   setrangerK   minmaxadd)r%   r   rG   r   rX   r,   ldlcr   cndncr
   rQ   rR   rS   rT   rU   rV   c1c2r   r   rW   s                           r"   _iup_contour_bound_forced_setrf      sv   ( v;;#f++%%%%FAUUF3v;;?B++ = =Aq1uBay&)1A	"F1q519$5B 8	 8	A1B1BQ%CQ%CQ%CQ%CczzcBcBcBcBE RxxrBw<<)++B)0C0C E rRBi/2PPPPRy9PPPPP E
 88BwwGGi// #BGy 8 8"$y.2"527!C!C$(E  GGi// #BGy 8 8"$rI~"527!C!C$(E 

1 Mr$   )r,   r
   	best_costbest_jcostrX   rG   lookbackc           	         t          |           }||}t          |t                    }ddi}ddi}t          d|          D ]}||dz
           dz   }	|	||<   |dz
  ||<   |dz
  |v r%t          |dz
  t	          ||z
  d          d          D ]8}
||
         dz   }||	k     rt          | ||
||          r|x||<   }	|
||<   |
|v r n9||fS )a  Straightforward Dynamic-Programming.  For each index i, find least-costly encoding of
    points 0 to i where i is explicitly encoded.  We find this by considering all previous
    explicit points j and check whether interpolation can fill points between j and i.

    Note that solution always encodes last point explicitly.  Higher-level is responsible
    for removing that restriction.

    As major speedup, we stop looking further whenever we see a "forced" point.Nr/   r   r   r@   )r   r\   MAX_LOOKBACKr[   r]   rP   )r%   r   rX   rG   rj   r   costschainr,   rg   r
   ri   s               r"   _iup_contour_optimize_dprp   !  s   2 	FA8\**HGEJE1a[[  !a%L1$	aq5aq5F??q1uc!h,33R88 	 	A8a<Di$6vvq!Y$W$W'++a9aF{{  %<r$   lkc                 h    t          |           }||z  }|s| S | ||z
  d         | d||z
           z   S )z{Rotate list by k items forward.  Ie. item at position 0 will be
    at position k in returned list.  Negative k is allowed.N)r   )rq   rr   r   s      r"   	_rot_listrt   V  sH     	AAFA QUWW:'AE'
""r$   sr   c                 6    z  s| S fd| D             S )Nc                      h | ]
}|z   z  S r*   r*   )r+   r-   rr   r   s     r"   	<setcomp>z_rot_set.<locals>.<setcomp>d  s!    ###AQUaK###r$   r*   )ru   rr   r   s    ``r"   _rot_setry   `  s7    FA #########r$           c                     t                     }t          fd D                       rdg|z  S |dk    r S  d         t          fd D                       rgdg|dz
  z  z   S t           |          }|r|dz
  t          |          z
  }|dk    sJ t	           |           t	          ||          }t          |||          }t           ||          \  }}t                      |dz
  }|                    |           ||         }|	                    d           |k    sJ |f             fdt          |          D              t	           |            nt            z   ||z   ||          \  }}d|dz   c}	t          |dz
  t          |          dz
            D ]l}
t                      |
}||
|z
  k    r)                    ||z             ||         }||
|z
  k    )||
|z
  k    r||
         ||
|z
           z
  }||	k    r|c}	m|k    sJ |f             fdt          |          D               S )	zFor contour with coordinates `coords`, optimize a set of delta
    values `deltas` within error `tolerance`.

    Returns delta vector that has most number of None items instead of
    the input delta.
    c              3   L   K   | ]}t          t          |           k    V  d S r)   rJ   )r+   rE   rG   s     r"   rM   z'iup_contour_optimize.<locals>.<genexpr>v  s4      
9
9Q3w{y(
9
9
9
9
9
9r$   Nr   r   c              3   $   K   | ]
}|k    V  d S r)   r*   )r+   r   d0s     r"   rM   z'iup_contour_optimize.<locals>.<genexpr>  s'      
#
#q27
#
#
#
#
#
#r$   r/   c                 ,    g | ]}|v r|         nd S r)   r*   )r+   r,   r%   solutions     r"   r.   z(iup_contour_optimize.<locals>.<listcomp>  )    III1qH}}&))$IIIr$   c                 ,    g | ]}|v r|         nd S r)   r*   )r+   r,   best_solr%   s     r"   r.   z(iup_contour_optimize.<locals>.<listcomp>  r   r$   )r   rN   rf   r]   rt   ry   rp   rZ   r^   remover[   )r%   r   rG   r   rX   rr   ro   rn   r,   rg   r5   ri   r   r~   r   s   ` `         @@@r"   iup_contour_optimizer   g  s    	FA
 
9
9
9
9&
9
9
999 vz 	Avv 
B

#
#
#
#F
#
#
### 'ttfA&&& +669EEF  :J Uc&kk!Avvvv61%%61%%&!Q'' 0	RRu 55EmLLOOOaA m 	 !!!FH#5!!!IIIIIaIII6A2&&
 0VOVf_fi
 
u #AE)1q5#e**q.11 
	9 
	9EuuHAeai--QU###!H eai-- EAI~~U|eEAI&669$$*2D'Hi !!!FH#5!!!IIIIIaIIIMr$   c                    t          |          |k    r#t          |          |r|d         dz   nddz   k    sJ t          |          }||dz
  |dz
  |dz
  |dz
  gz   }g }d}|D ]^}t          | ||dz            |||dz            |          }t          |          ||z
  dz   k    sJ |                    |           |dz   }_|S )a  For the outline given in `coords`, with contour endpoints given
    in sorted increasing order in `ends`, optimize a set of delta
    values `deltas` within error `tolerance`.

    Returns delta vector that has most number of None items instead of
    the input delta.
    r/   r   r   r>   r?   r@   )rA   r   r   r   )	r%   r   r<   rG   r   r    r5   r:   rB   s	            r"   iup_delta_optimizer     s     $<<4CKKD4ODHqLLaST3T$T$T$T$TFA1q5!a%QA..D
CE  &537?#VEC!GO%<i
 
 7||sU{Q....

7aJr$   )r   )rz   )'r   compiledCOMPILEDAttributeErrorImportErrorfontTools.misctypingr   r   r   numbersr   r   _Point_Delta_PointSegment_DeltaSegment_DeltaOrNone_DeltaOrNoneSegment
_Endpointsrm   cfunclocalsintdoubler#   r;   rC   inlinereturnsrP   rZ   rf   rp   listrt   ry   r   r   r*   r$   r"   <module>r      s  MMMHH$   %%%%%%HHH	         
 # " " " " " " " 
tTz		tTz	  VT\"|, h
  jj}}}}
-mm
 
 
)) &)-3):@)GM) ) )
 
 )X1+ 1] 1} 1 1 1 1h)6>H   4 jjmmmm     	
       * }}
*	 	 	 EFN NN#0N=ANN N N	 	Nb jjm:	m   355) ))) 	)
 ) ) ) )X# ## # # # #$ $ $ $ $ $ $ EHb bb#0b=Abb b b bR 	   	
      s      