loopspace / spath3

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

The new version of knots bug #15

Open adamny opened 2 years ago

adamny commented 2 years ago

I updated MacTex(LiveTex) from 2019 to 2021 including the knots package, and the following started giving me an error:

    \begin{tikzpicture}[scale=0.5] %scale plays a role in this error.
    \begin{knot}[clip width=5, clip radius=15pt, consider self intersections, end tolerance=3pt]
       \strand (2,0)
          to[out=left, in=right] 
             (1.4,0)
          to[out=left, in=down] (0.6,0.4)
          to[out=up, in=left] (1,.8)
          to[out=right, in=up]  (1.4,0.4)
          to[out=down, in=right]  (0.6,0);   %removing this line resolves the problem.   
    \end{knot}
loopspace commented 2 years ago

This is another where the error messages could be more useful. It is because when dealing with self intersections then it has to split the path into pieces and test them against each other. There can be difficulties if the intersection point is close to an end point of one of these pieces. Since bézier curves can self-intersect, in addition to splitting the path into its specified components, it also splits curves into two to ensure that they don't self-intersect. If I disable that option with your code then it works.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{
  knots,
}

\begin{document}

\begin{tikzpicture}[scale=0.5] %scale plays a role in this error.
\begin{knot}[
  clip width=5,
  clip radius=15pt,
  consider self intersections=no splits,
  end tolerance=3pt
]
       \strand (2,0)
          to[out=left, in=right] (1.4,0)
          to[out=left, in=down] (0.6,0.4)
          to[out=up, in=left] (1,.8)
          to[out=right, in=up]  (1.4,0.4)
          to[out=down, in=right]  (0.6,0)   %removing this line resolves the problem.
          to[out=left, in=right] (0,0)
          ;
    \end{knot}
\end{tikzpicture}
\end{document}

(I added a little more on the path to make the overlap more obvious.)

loopspace commented 2 years ago

Actually, there was a bug in what happens when a curve is split in that fashion. I think I've fixed it in the latest commit: https://github.com/loopspace/spath3/commit/b0fd0c8a4fcac0ac9d46358b07e74ba08d659808