I'll also post the code of LineWidthThatCoversPath, in case it changes in a later version. But be careful with line breaks that you can copy but that weren't in my original code.
% TargetAccuracy LineWidthThatCoversPath WidthMax WidthMin
% Calculates, for the current path, the greatest distance from an interior point to the edge.
% WidthMin is known to be less than this distance. WidthMax will be greater.
%
https://groups.google.com/forum/#!topic/comp.lang.postscript/86b7Sg8v7B0
/LineWidthThatCoversPath
{
DeBugLevel 25 le {(+LineWidthThatCoversPath) OutputToLog} if
20 dict begin
//PrinterEpsilon 2 copy lt {exch} if pop /TargetAccuracy exch def
% Target accuracy is split into two equal parts. The grid separation is half. And then the WidthMax-WidthMin separation is allowed the other half, and sometimes less than that.
PathBBox /ury exch def /urx exch def /lly exch def /llx exch def
urx llx sub //PrinterEpsilon gt ury lly sub //PrinterEpsilon gt and
{
% For an equilateral triangle the point furthest from the three corners is 2/3 of the height from the corners, which is Sqrt3/3 of the base.
/NumRows ury lly sub TargetAccuracy 0.75 mul div def % Error to be <= TargetAccuracy/2, which is 2/3 of row height. So row height = 0.75*TargetAccuracy.
/NumCols urx llx sub TargetAccuracy 1.5 mul Sqrt3 div div def % Error to be <= TargetAccuracy/2, which is Sqrt3/3 of the width. So width = TargetAccuracy * 1.5 / Sqrt3.
30000 NumRows ceiling 1 add NumCols ceiling 1 add mul div dup 1 gt % 30k => max stack of about 60k
{sqrt dup NumRows mul ceiling cvi 1 add /NumRows exch def NumCols mul ceiling cvi 1 add /NumCols exch def}
{pop /NumRows NumRows ceiling cvi 1 add def /NumCols NumCols ceiling cvi 1 add def}
ifelse % NumRows*NumCols small
/HalfGapRows ury lly sub NumRows 2 mul div def
/HalfGapCols urx llx sub NumCols 2 mul div def
/MaxResolutionError HalfGapRows dup 4 mul HalfGapCols dup mul exch div add def
DeBugLevel 15 le {mark ( LineWidthThatCoversPath: NumRows = ) NumRows (; NumCols = ) NumCols (; HalfGapRows = ) HalfGapRows (; HalfGapCols = ) HalfGapCols (; MaxResolutionError = ) MaxResolutionError ConcatenateToMark OutputToLog} if
count currentsystemparams /MaxOpStack 2 copy known {get} {pop pop 65535} ifelse exch sub /StackSpaceRemaining exch def
/PointsMostDistanceFromEdge
[
1 1 NumCols 2 mul 1 sub
{
/ColNum exch def /X ColNum HalfGapCols mul llx add def
1 2 NumRows 2 mul
{
/RowNum exch def /Y RowNum HalfGapRows mul lly add def
RowNum 4 mod 2 idiv ColNum 2 mod eq {X Y infill {X Y /StackSpaceRemaining StackSpaceRemaining 2 sub def} if StackSpaceRemaining 2 lt {exit} if} if
} for % Y
StackSpaceRemaining 2 lt {exit} if
} for % X
] def % /PointsMostDistanceFromEdge
StackSpaceRemaining 2 lt {(Warning: LineWidthThatCoversPath has incomplete calculation because there might be too little stack space. Increasing TargetAccuracy would help.) OutputToLog} if
DeBugLevel 15 le {mark ( LineWidthThatCoversPath: PointsMostDistanceFromEdge length = ) PointsMostDistanceFromEdge length ConcatenateToMark OutputToLog} if
/WidthMin null def /WidthMax null def
/Width ury lly sub 6 div PrinterEpsilon 2 copy lt {exch} if pop def
{
gsave
Width setlinewidth strokepath
/NewArrayLength 0 def
0 2 PointsMostDistanceFromEdge length 2 sub
{
dup PointsMostDistanceFromEdge exch get exch 1 add PointsMostDistanceFromEdge exch get 2 copy
infill not
{
PointsMostDistanceFromEdge NewArrayLength 1 add 3 -1 roll put PointsMostDistanceFromEdge NewArrayLength 3 -1 roll put
/NewArrayLength NewArrayLength 2 add def
} {pop pop} ifelse % infill not
} for % PointsMostDistanceFromEdge
NewArrayLength 0 gt {/WidthMin Width def /PointsMostDistanceFromEdge PointsMostDistanceFromEdge 0 NewArrayLength getinterval def} {/WidthMax Width def} ifelse
grestore
DeBugLevel 15 le {mark ( LineWidthThatCoversPath: WidthMin = ) WidthMin (; WidthMax = ) WidthMax (; PointsMostDistanceFromEdge length = ) PointsMostDistanceFromEdge length ConcatenateToMark OutputToLog} if
WidthMax null ne
{
WidthMin null ne
{
% Complicated exit conditions. Generally by the time this becomes close, PointsMostDistanceFromEdge is short, so a a few extra rounds are fast.
WidthMax WidthMin sub MaxResolutionError lt WidthMin TargetAccuracy div cvi WidthMax MaxResolutionError add TargetAccuracy div cvi eq and {exit} if
WidthMax WidthMin sub dup TargetAccuracy 64 div lt exch //PrinterEpsilon le or {exit} if
} {WidthMax TargetAccuracy 2 div le WidthMax PrinterEpsilon le or {/WidthMin 0 def exit} if} ifelse % WidthMin null ne
} if % WidthMax null ne
/Width WidthMax null eq {WidthMin 2 mul} {WidthMin null eq {WidthMax 2 div} {WidthMin WidthMax add 2 div} ifelse} ifelse def
} loop
WidthMax MaxResolutionError add WidthMin
} {//PrinterEpsilon 0} ifelse end % Non-zero area
DeBugLevel 25 le {(-LineWidthThatCoversPath) OutputToLog} if
} def % /LineWidthThatCoversPath