I can use spath3 with paths (not nodes) in this way:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spath3, intersections}
\begin{document}
\begin{tikzpicture}
\draw[spath/save = rect, rounded corners=12pt] (0,0) rectangle (2,1);
\draw[spath/save global = line3] (-1,-1) -- (0.4,0.75);
\draw[spath/save global = line4] (-1,-1) -- (1,0.5);
\tikzset{spath/.cd,
split at intersections with={rect}{line3},
split at intersections with={rect}{line4},
get components of={rect}\cpts
}
\draw[ultra thick, color=red, spath/restore=\getComponentOf\cpts{3}] node {};
\end{tikzpicture}
\end{document}
Result:

So far so good.
But what I really need is highlight a part of rectangle node in the intersection with a double line, and it does not work:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{spath3, intersections}
\begin{document}
\begin{tikzpicture}
\node[spath/save global = rect, rectangle, rounded corners=12pt, draw=black!50, thick, fill=white, minimum height=27pt] {asdfasdfasdfasdf};
\draw[spath/save global = line, line width=1pt, double=white, draw=black!20, double distance=3pt] (-2, -1) -- (-0.5,0.0);
\tikzset{spath/.cd,
split at intersections with={rect}{line},
split at intersections with={rect}{line},
get components of={rect}\cpts
}
\draw[ultra thick, color=red, spath/restore=\getComponentOf\cpts{2}] node {};
\end{tikzpicture}
\end{document}

Any ideas?
\behindbackgroundpath,\beforebackgroundpath,\foregroundpath, and\behindand\beforeversions of that. I doubt that these approaches are robust in the presence of any of these. – Henri Menke Nov 26 '21 at 10:24shortendistances, and it does not work if rectangles are filled with different colours) – DimanNe Nov 26 '21 at 10:31lineis just a line on the path level. It has no width, there is only one intersection point. You will need to have to parallel paths here (trivial for straight lines, difficult for curves). – Qrrbrbirlbel Mar 15 '23 at 19:24