[Tex/LaTex] Problems with filling a path that includes decorations in TikZ

decorationstikz-pgf

I want to construct a rectangle with two sides having a slight curvature and the other two sides being zigzag lines. In the end, I want to fill it. While the construction of the path worked the way I expected, the filling did not. How can I tell TikZ to fill the area inside this rectangle?

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, decorations}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[scale=2]

\coordinate (A) at (0,0);
\coordinate (B) at (8,0);
\coordinate (C) at (8,2);
\coordinate (D) at (0,2);

\begin{scope}[decoration=zigzag]
\def\mypath{ (A)  to[out=10,in=170] (B)
decorate[decoration=zigzag] {(B)-- (C)}  (C) to[out=170,in=10] (D)
decorate[decoration=zigzag]{(D)--(A)}
  };
  \draw [fill=red] \mypath;
\end{scope}
\end{tikzpicture}
\end{document}

Best Answer

You are breaking the path into pieces by repeating the coordinate names (B) and (D) hence each piece is filled individually. Removing them inside the braces (and the extra (C)) fixes the problem.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (2,0);
\coordinate (C) at (2,2);
\coordinate (D) at (0,2);
\begin{scope}[decoration=zigzag]
  \draw[fill=red] (A) to[out=10,in=170] (B) 
                decorate {-- (C)}  
                to[out=170,in=10] (D) 
                decorate {--(A)};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here