loopspace / spath3

TikZ/PGF package for manipulating soft paths, includes the knots and calligraphy TikZ libraries.
16 stars 2 forks source link

ignore endpoint intersections = false creates a bounding box #26

Open Qrrbrbirlbel opened 1 year ago

Qrrbrbirlbel commented 1 year ago

Consider the following document:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{knots}
\begin{document}
\setlength\fboxsep{0pt}
\setlength\fboxrule{.2pt}
\newcommand*\KNOT[2]{%
  \fbox{%
    \begin{tikzpicture}
      \begin{knot}[consider self intersections = true,#1]
        \strand[line width=0.6pt, looseness=1.4,#2]
          (0,0) to [out=0,in=0] (0.2,0.2) to [out=180,in=180] (.4,0);
      \end{knot}
    \end{tikzpicture}%
  }\par}

\KNOT{}{}
\KNOT{ignore endpoint intersections = false}{}
\KNOT{ignore endpoint intersections = true}{}
\bigskip

\KNOT{}{overlay}
\KNOT{ignore endpoint intersections = false}{overlay}
\KNOT{ignore endpoint intersections = true}{overlay}
\end{document}

When ignore endpoint intersections = false, the picture gets it bounding box adjusted so that it fits a 24pt × 24pt rectangle around, I guess, the strand's path's center:
grafik

When adding overlay to the strand, the \fbox disappears in the other cases because the TikZ picture has no size anymore but in the problematic case the rectangle is still there:
grafik

loopspace commented 1 year ago

If you look carefully at your examples you will see that only in the middle one (of each three) is a crossing found. So it's actually nothing to do with the option ignore endpoint intersections=false except for the fact that your drawing is so small that with the default tolerance then the crossing is judged to be too close to the endpoints to be identified unless that option is set. So the real difference between your versions is whether or not there is an identified crossing.

When a crossing is identified then the relevant strands are redrawn with a clip. It is that clip that is providing the bounding box. The overlay option is applied only to the strand and not to the clipping region (which makes sense since a crossing could well be between two strands and if only one of them has the overlay option then what should the clipping region do?).

There's a case that could be made for the clipping region to always be considered overlayed, since the bounding box of the clipping region should be within the bounding box of the whole knot, but the clipping region doesn't have to be used to clip so I'd rather leave that up to the user to decide, especially as there is an easy fix: simply append overlay to the background clip and clip styles in the knot environment:

Adjusted example with clipping ```[latex] \documentclass{article} \usepackage{tikz} \usetikzlibrary{knots} \begin{document} \setlength\fboxsep{0pt} \setlength\fboxrule{.2pt} \newcommand*\KNOT[2]{% \fbox{% \begin{tikzpicture} \begin{knot}[consider self intersections = true, background clip/.append style={#2}, clip/.append style={#2}, #1] \strand[line width=0.6pt, looseness=1.4,#2] (0,0) to [out=0,in=0] (0.2,0.2) to [out=180,in=180] (.4,0); \end{knot} \end{tikzpicture}% }\par} \KNOT{}{} \KNOT{ignore endpoint intersections = false}{} \KNOT{ignore endpoint intersections = true}{} \bigskip \KNOT{}{overlay} \KNOT{ignore endpoint intersections = false}{overlay} \KNOT{ignore endpoint intersections = true}{overlay} \end{document} ```