%! /intersection { 1 dict begin /L exch def /A L 0 get def /B L 1 get def /C L 2 get def /f00 A -1 mul B -1 mul add C add def /f10 A 1 mul B -1 mul add C add def /f11 A 1 mul B 1 mul add C add def /f01 A -1 mul B 1 mul add C add def % f01 f11 % f00 f10 [ f00 f10 mul 0 lt { /t f00 f00 f10 sub div def % (1-t)(00) + t(10) [-1 -1] [1 -1] t interpolate } if f10 0 eq { [1 -1] } if f10 f11 mul 0 lt { /t f10 f10 f11 sub div def [ 1 -1] [1 1] t interpolate } if f11 0 eq { [1 1] } if f11 f01 mul 0 lt { /t f11 f11 f01 sub div def [1 1] [-1 1] t interpolate } if f01 0 eq { [-1 1] } if f01 f00 mul 0 lt { /t f01 f01 f00 sub div def [-1 1] [-1 -1] t interpolate } if f00 0 eq { [-1 -1] } if ] end } def % --- utilities ------------------------------------------ % P Q -> (1-t)P + tQ /interpolate { 1 dict begin /t exch def /Q exch def /P exch def [ 1 t sub P 0 get mul Q 0 get t mul add 1 t sub P 1 get mul Q 1 get t mul add ] end } def % --- sample usage --------------------------------------- /S 72 def S dup scale 1 S div setlinewidth 4.25 5.5 translate newpath -1 -1 moveto 1 -1 lineto 1 1 lineto -1 1 lineto closepath stroke /I [3 -1 2] intersection def I length 2 eq { newpath I 0 get 0 get I 0 get 1 get moveto I 1 get 0 get I 1 get 1 get lineto stroke } if