@mocanvas/mocanvas · function

labelGapOnBody

declare function labelGapOnBody(body: ArrowBody, box: {
    x: number;
    y: number;
    w: number;
    h: number;
}): {
    from: number;
    to: number;
} | null

The stretch of body, as a parameter range, that runs inside box — the gap the *selection outline* leaves around a label.

Only the outline needs it. The arrow itself is drawn end to end and the label's opaque box covers the stretch under the text, which is what keeps the stroke there to be clicked. The indicator is painted on top of the label, though, so without this it draws a line straight through the words.

Sampled rather than solved: the three body kinds are a segment, an arc and a polyline, and an exact intersection for each is three separate cases to get wrong for an answer that is then rounded to a pixel anyway. The range runs from the first sample inside the box to the last, so a body that enters twice — a tight arc passing its own label on the way out and back — is cut once, across the whole excursion.

null when the body never enters the box, or when the gap would swallow it whole: a label wider than its own arrow leaves the outline alone.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.