2

I'm trying to employ the extremely cool inverted clipping from this question in combination with reusage of named paths with the use path key I stole from this question. However, it seems like my cargo-cult skills of stealing TikZ code from stackexchange are insufficient here, because in the MWE I constructed, the inversion of the clipping does not work as expected:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}

\tikzset{invclip/.style={clip,insert path={{[reset cm]
      (-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)
}}}}

\makeatletter
\tikzset{
  use path for main/.code={%
    \tikz@addmode{%
      \expandafter\pgfsyssoftpath@setcurrentpath\csname tikz@intersect@path@name@#1\endcsname
    }%
  },
  use path for actions/.code={%
    \expandafter\def\expandafter\tikz@preactions\expandafter{\tikz@preactions\expandafter\let\expandafter\tikz@actions@path\csname tikz@intersect@path@name@#1\endcsname}%
  },
  use path/.style={%
    use path for main=#1,
    use path for actions=#1,
  }
}
\makeatother

\begin{tikzpicture}[outer sep=0mm]
  \coordinate (A) at (-1,-1);
  \coordinate (B) at (1,-1);
  \coordinate (C) at (1,1);
  \coordinate (D) at (-1,1);
  \path[draw=black,name path=P] (A) -- (B) -- (C) -- (D) --cycle;
  \begin{scope}
    \begin{pgfinterruptboundingbox} % useful to avoid the rectangle in the bounding box
      \path[invclip] (A) -- (B) -- (C) -- (D); % works just fine
      %\path[invclip,use path=P]; % doesn't work at all
    \end{pgfinterruptboundingbox} 
  \fill[orange!50] (-2,-2) rectangle (2,2);
  \end{scope}
\end{tikzpicture} 
\end{document}

This works just fine:

this works

But this doesn't work:

this doesn't work

How can I use inverted clipping with use path?

carsten
  • 2,966
  • In this example, of course, you could draw what you need much more easily. But I assume your real case is not so simple. – cfr Jul 19 '17 at 19:58
  • Yes, my actual case involves very complicated paths instead of rectangles, but is conceptually the same (an inner shape, an outer shape, and I want to fill just the area between the two). – carsten Jul 19 '17 at 20:40
  • Then why not just use the even odd rule? – cfr Jul 20 '17 at 00:29
  • It doesn't have anything to do with the saved paths. This doesn't work even if you substitute in the original path specifications rather than reusing them. – cfr Jul 20 '17 at 00:44
  • To get it to work without saving paths, you need to eliminate the use of rectangle and specify it explicitly. At least, that's what I found. – cfr Jul 20 '17 at 00:52
  • Not sure what to make of this. Are you saying that there's a clash between saving paths and inverted clipping? Because that's what I find, see here: http://mathb.in/149713 – carsten Jul 20 '17 at 10:20
  • That seems to be true, but also irrelevant in your example. That doesn't work even if you take the saved paths out and substitute their originals, because the use of rectangle seems to conflict with invclip. – cfr Jul 20 '17 at 11:58
  • ok, so since the question of rectangles is irrelevant for my actual usecase, I'll change the question accordingly. – carsten Jul 20 '17 at 12:16
  • You don't need pgfplots here, either. – cfr Jul 20 '17 at 12:18
  • done editing the question accordingly – carsten Jul 20 '17 at 12:21
  • 1
    There is an unofficial package spath that helps you connect two or more paths into one. In this case, you are connecting a huge rectangle with whatever complicated path you used to have. After all this is a matter of softpath operation. – Symbol 1 Jul 20 '17 at 12:48
  • Is there any way to make it work with standard packages? – carsten Jul 20 '17 at 13:57
  • @Symbol1 Is that distinct from spath3? – cfr Jul 23 '17 at 01:55
  • 1
    @cfr According to Loop Space's comment, it is distinct but the same. (What am I talking about...) – Symbol 1 Jul 23 '17 at 08:56
  • @Symbol1 Thanks - I'd completely forgotten that comment. – cfr Jul 23 '17 at 09:36
  • @carsten Well, spath3 is in TeX Live, on CTAN etc., so it is as standard as most packages. – cfr Jul 23 '17 at 09:38

0 Answers0