loopspace / spath3

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

Useful to have code to use just a component of a soft path. #9

Closed loopspace closed 3 years ago

loopspace commented 3 years ago

In answering a few TeX-SX questions I'm using a wrapper around \clist_item:Nn to get a component of a soft path. I think it's fine to require the use of get components of to split the soft path into its components (if using multiple components - as is often the case - then splitting them once saves time) but then making it easy to use a particular item of that list would be helpful. Not sure whether this should be via keys or that the wrapper I'm using is the way to go.

loopspace commented 3 years ago

An alternative would be to define a separate set of keys that worked with components, but this feels like it won't actually make the interface easier for the user and I'd have to maintain two near-identical bits of code.

So I'm settling on a wrapper around clist_item:Nn. Current working name is \getComponentOf, but \getItemOf might be better as it is just selecting an item in a list rather than being particular to this library of soft paths.

loopspace commented 3 years ago

Here's an example of using \getComponentOf to answer this TeX-SX question.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/383762/86}
\usepackage{tikz}
\usetikzlibrary{spath3, intersections}

\begin{document}
\begin{tikzpicture}
\path[spath/save = line1, draw] (-1,0) .. controls (2,2) and (2,1) .. (0,-1) node {line 1};
\path[spath/save = line2, draw] (-1,1) -- (1,-1) node {line 2};

\tikzset{
  spath/.cd,
  split at intersections with={line1}{line2},
  get components of={line1}\cpts
}

\draw[
  ultra thick,
  spath/restore=\getComponentOf\cpts{2}
  ];

\node[above right] at (spath cs:\getComponentOf\cpts{2} .5) {C};

\end{tikzpicture}
\end{document}

Segment of curve with label

loopspace commented 3 years ago

I'm sticking with \getComponentOf unless someone tells me that's a bad idea.