• Re: undesirable feature of pathbbox

    From jdaw1@21:1/5 to All on Tue Aug 9 10:04:38 2022
    This reply might be too late for the original poster; nonetheless might help later readers.

    PostScript’s pathbbox is not clever. It takes limits in current x-y space of curve control points and line segment ends. So the reported box can be larger than the actual box.

    In https://github.com/jdaw1/placemat/blob/main/PostScript/placemat.ps is a function PathBBox, (currently lines 2884–2993, search for “/PathBBox”), which does what pathbbox ought to have done.

    First pass it computes the x (and then y) bounds, considering only the ends points of straight lines, and the endpoints of curves (ignores middle controls).

    Second pass is for curves only. For those curves with any interior control points outside the already-computed limits (x or y or both), it computes for those axes the cubic coefficients, differentiates once, solves for 0 subject to 0 < t < 1, and
    then computes the values at those turning points. If these turning points expand the bounding box, the the bounding box is expanded.

    A test:

    0 0 moveto   1 0  1 1  0 1 curveto

    then

    pathbbox returns: 0.0 0.0 1.0 1.0, being the bounding box of the control points;

    PathBBox returns: 0.0 0.0 0.75 1.0, being the bounding box of the path. Observe that Max[x]=¾.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)