ó ;œPc@sdZddlmZmZmZdefd„ƒYZdefd„ƒYZdeefd„ƒYZd „Z d „Z d dd „ƒYZ d e efd„ƒYZ de efd„ƒYZ d„Zgdgdd„Zdgdd„Zd„Zd„ZdS(s Support functions for RE simplification. This module is intended for use by the RE module. It is in a separate module to keep RE itself cleaner since the algorithm, 'rectangle selection', is a quite separate part that depends on some tricky heuristics. The primary entry function is chooserects(lines, gauges, trace) It chooses 'the best' rectangles from lines to base simplification on. A weight on atoms is given by gauges. The trace parameter is for debugging. pr() gives some example usages of chooserects. iÿÿÿÿ(t immbitsett mutbitsett immbitrangetRectcBsDeZd Zd„Zd„Zd„Zd d „Zd „ZeZRS( twidthtlinestgainmemotlnost all_linest common_partcCs>||_||_|o't|ƒdk s1t‚i|_dS(Ni(RRtlentAssertionErrorR(tselfRR((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyt__init__s  cCsK||_tg|jD]}|t|ƒ^qƒ|_|jƒ|_dS(N(RRRtidRtget_common_partR (R tlnobyidRtline((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pytinit2s /cCs~|j}||@}||krO||_g|D]}|j|^q0|_nt|ƒdkrzt|jdƒ|_ndS(Nii(RRRR R(R Rtolnostlno((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyt reducelines#s    &icCs7g}x*|j|@D]}|j|j|ƒqW|S(N(RtappendR(R t pickednosRti((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyt get_lines/scCs&d|j|jt|jƒ|jfS(Ns0< dir = %d width = %d lnos = %s lines = %s >(tdirRtlistRR(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyt__str__5s(RRRRRR ( t__name__t __module__t __slots__R RRRRt__repr__(((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyRs    tLeftRectcBs)eZdZdZd„Zdd„ZRS(icCs|jd|j S(Ni(RR(R ((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR?scCs8g}x+|j|ƒD]}|j||jƒqW|S(N(RRR(R RtucR((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyt get_uncommonsBs((RRRRRR#(((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR!<s t RightRectcBs)eZdZdZd„Zdd„ZRS(iÿÿÿÿcCs)|j }|dkrgS|jd|S(Ni(RR(R tlo((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyRKs  icCsTg}|j }|dkr%d}nx(|j|ƒD]}|j|| ƒq5W|S(Ni(RtNoneRR(R RR"thiR((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR#Qs   ((RRRRRR#(((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR$Hs cCsA|dkrt|ƒSd}x|D]}|||ƒ7}q#W|S(Ni(R&R (tgaugetlsttgaintx((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyt sum_gaugeZs    cCsLxE|D]=}t||ƒ}t||ƒ}t||ƒ}|r|SqWdS(Ni(R,tcmp(txstystgaugesR(tgxtgytc((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyt cmp_gaugedds t InducedRectcBseZd„ZRS(cCs7||_|j|_|j|_||_||_dS(N(tsRRRR(R R6RR((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR ns     (RRR (((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR5mstInducedRightRectcBseZRS((RR(((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR7wstInducedLeftRectcBseZRS((RR(((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyR8zsc Cs~t|ƒdkr"td|ƒgStd|ƒtd|ƒg}g}x1|ry|}g}x|D]}|j}x–d}i}||jA}xI|jD]>} |t| ƒkrÏ|j| |gƒj| ƒq—d}q—W|sñt|ƒdkrõPn|d|_}qtW|j|ƒ|d7}xN|jƒD]@\} } t| ƒdkr.|j || ƒ} |j| ƒq.q.WqbWqIW|S(Nii( R R!R$RRRt setdefaultRtitemst __class__( Rtnewrectst donerectstoldrectstrRtis_donetdtposRtktvtnew_r((sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pytbrects6        tcs®‡‡‡‡‡fd†}‡‡‡‡‡fd†}‡‡‡‡‡fd†}d„}ˆddkrwˆd‰ntgtˆƒD]\}} t| ƒ|f^q‡ƒ} ˆ} t| ƒ‰xˆD]} | j| ˆƒqÇWˆj|ƒttˆƒƒ} t ƒ‰g}g‰x`ˆ| krw|ƒ} ˆ| j O‰|j | ƒ|| ƒˆdkrjt j ƒn|| ƒqWˆdkr‘t j ƒnˆd krªt j ƒn|S( Nc s›ˆdkrtjƒn|jƒ}t|ƒdkr;dSg}x=ˆD]5}|j|jkrfqHng}|jˆƒ}|jˆ@}t|ƒt|ƒks§t‚x9t||ƒD](\}}||kr·|j|ƒq·q·Wt|ƒt|ƒkrHt |ƒ} g|D]}ˆ|^q}|jdkr<t } nt } | ||| ƒ} ˆdkrmtjƒn|j| ƒqHqHW|r—ˆj |ƒndS(Ntinduceiiÿÿÿÿtindap( tpdbt set_traceR#R RRR tzipRRR7R8textend( R?t uncommonstirsR6tpsstuncsRtuncRtpslnosR3tir(RtnewsRtrectsttrace(sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyRHŸs8         c sÃdˆkrtjƒn|j}g}xhˆD]`}||krGq/n|j|jkr_q/n|j}||@sxq/n|ˆM}|sq/n|j}|s¤q/nxèˆD]Æ}||krÃq«n|j|jkrÛq«n|jˆ@}||@rùq«n||@}|sq«n||kr!q«n|j} | s6q«nt|| ˆƒ} | dkrZq«nˆdkrptjnPq«W|j|ƒˆj|ƒq/Wt|ƒdkr²tjƒnˆj |ƒdS(Ntoverlapitobreaki( RJRKRRR R4RtremoveR RM( R?trlnosttonewsR6tslnostscomttttlnosRttcomR3(R0RURRVRW(sD/opt/alt/python27/lib64/python2.7/site-packages/guppy/etc/RE_Rect.pyRXÁsZ                    csxˆr6ˆdkr"tjƒnˆd}ˆd=n±d}xŒtˆƒD]~}|jˆ}|suˆj|ƒqInt|ƒd}|j}|dk r›|s¤Pn|s°qIn|r›|j}|j}d}x²ˆD]ª} y|| } Wn-t k rt | |j ƒ} | || s&    à K