[Tex/LaTex] Overwriting fill patterns in TikZ

fillpatterntikz-pgf

A circle lies within a square. The square has a fill pattern, say , A, and the circle has fill pattern, say, B. I wish the two patterns not to overlap. In case this is unclear, here is an MWE:

\documentclass[10pt,class=memoir]{standalone}
\usepackage[cmyk,dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
  \usetikzlibrary{calc,shapes,decorations,decorations.text, mindmap,shadings,patterns,matrix,arrows,intersections,automata,backgrounds}
\begin{document}
\begin{tikzpicture}
\draw[pattern=dots, pattern color=green] (0, 0) rectangle (4, 4);
% \draw[fill=white] (2, 2) circle[radius=1]; 
\draw[pattern=bricks, pattern color=brown] (2, 2) circle[radius=1]; 
\end{tikzpicture}
\end{document}

If I uncomment the line with \fill[white] I get the result I want. But this seems an inelegant hack. Is there a better way of achieving the same result?

Thanks.

Best Answer

you can also clip the rectangle without the circle

\documentclass{article}
\usepackage[cmyk,dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{patterns}
\begin{document}

\begin{tikzpicture} 
\begin{scope}
   \clip[insert path={(0, 0) rectangle (4, 4)}]  (2, 2) circle[radius=1];  
   \draw[pattern=dots, pattern color=red] (0, 0) rectangle (4, 4);
\end{scope}
\draw[pattern=bricks, pattern color=brown] (2, 2) circle[radius=1]; 
\end{tikzpicture}
\end{document}

enter image description here