# Custom TikZ pattern not fully showing

I have the following

\documentclass{article}
\usepackage{tikz,amsmath, amssymb,bm,color}
\usepackage[active,tightpage]{preview}
\usetikzlibrary{shapes,arrows}
% needed for BB
\usetikzlibrary{calc}

\PreviewEnvironment{tikzpicture}

\usetikzlibrary{patterns}
\usetikzlibrary{decorations.pathreplacing}

\pgfdeclarepatternformonly[\GridSize]{MyCircleGrid}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\GridSize}{\GridSize}}{\pgfqpoint{\GridSize}{\GridSize}}%
{
\pgfsetlinewidth{0.5pt}
\pgfsetstrokecolor{blue!80!black}
%\pgfpathqcircle{7pt}
\pgfpathcircle\pgfpointorigin{7pt}
%\pgfusepath{stroke}
\pgfusepathqstroke
}

\newdimen\GridSize
\tikzset{
GridSize/.code={\GridSize=#1},
GridSize=3pt
}
\begin{document}
\begin{tikzpicture}

\draw [GridSize=10 pt,pattern=MyCircleGrid] (0,-4.5) rectangle (-7.5,-1.5);

\draw [thick] (-7.5,-3) -- (0,-3);
\draw  (-7.5,3.5) rectangle (0,-1.5);
\begin{scope}
\clip (-7.5,3.5) rectangle (0,-1.5);

\draw  (-7.5,-1) ellipse (0.5 and 0.5);
\draw  (0,-1) ellipse (0.5 and 0.5);
\draw  (-7,-1) ellipse (0.5 and 0.5);
\draw  (-6,-1) ellipse (0.5 and 0.5);
\draw  (-4,-1) ellipse (0.5 and 0.5);
\draw  (-3,-1) ellipse (0.5 and 0.5);
\draw  (-5,-1) ellipse (0.5 and 0.5);
\draw  (-2,-1) ellipse (0.5 and 0.5);
\draw  (-1,-1) ellipse (0.5 and 0.5);
\draw  (-7.5,2) ellipse (1.5 and 1.5);
\draw  (-3.5,2.5) ellipse (2 and 2);
\draw  (-5.5,2.5) ellipse (2 and 2);
\draw  (-1,2.5) ellipse (2 and 2);
\draw  (-5.5,0) ellipse (1 and 1);
\draw  (-7,0) ellipse (1 and 1);
\draw  (-4,0) ellipse (1 and 1);
\draw  (-0.5,0) ellipse (1 and 1);
\draw  (-2.5,0) ellipse (1 and 1);
\draw  (-1,0) ellipse (1 and 1);
\end{scope}

\draw  (-6.5,-1.5) ellipse (0.5 and 0.5);
\draw  (-7,-1.5) ellipse (0.5 and 0.5);
\draw  (-5,-1.5) ellipse (0.5 and 0.5);
\draw  (-4.5,-1.5) ellipse (0.5 and 0.5);
\draw  (-4,-1.5) ellipse (0.5 and 0.5);
\draw  (-3.5,-1.5) ellipse (0.5 and 0.5);
\draw  (-3,-1.5) ellipse (0.5 and 0.5);
\draw  (-6,-1.5) ellipse (0.5 and 0.5);
\draw  (-5.5,-1.5) ellipse (0.5 and 0.5);
\draw  (-1,-1.5) ellipse (0.5 and 0.5);
\draw  (-2,-1.5) ellipse (0.5 and 0.5);
\draw  (-0.5,-1.5) ellipse (0.5 and 0.5);
\draw  (-2.5,-1.5) ellipse (0.5 and 0.5);
\draw  (-1.5,-1.5) ellipse (0.5 and 0.5);

\draw [decorate,decoration={brace,amplitude=10pt}] (0.5,3.5) -- (0.5,-1.5) node [black,midway,xshift=25pt] {\footnotesize
$X\setminus Z$};
\draw [decorate,decoration={brace,amplitude=10pt}] (-8,-4.5) -- (-8,-1.5) node [black,midway,xshift=-25pt] {\footnotesize
$N_\rho(Z)$};
\draw [decorate,decoration={brace,amplitude=10pt}] (0.5,-3) -- (0.5,-4.5) node [black,midway,xshift=17pt] {\footnotesize
$Z$};

\end{tikzpicture}
\end{document}


I expect it to produce this:

but in the pdf produced I get this

what am I doing wrong?

The tile consists of a circle at the origin and radius 7 pt and line width of 0.5 pt. That would make a bounding box of "(-7.25 pt, -7.25 pt) rectangle (7.25 pt, 7.25 pt)".

But the arguments are:

\pgfdeclarepatternformonly[\GridSize]{MyCircleGrid}
{\pgfqpoint{-1pt}{-1pt}}% Lower left corner of the bounding box
{\pgfqpoint{\GridSize}{\GridSize}}% Upper right corner of the bounding box
{\pgfqpoint{\GridSize}{\GridSize}}% Tile size


If \GridSize is larger than 7.25 pt (the example uses 10 pt), then you get the upper right quadrant of the circle (a little more on the left and bottom by 1pt).

If you want to have the full circle, a bounding box covering the full circle needs to be specified.

The tile size however can be smaller. Then the tile confined to the bounding box would partially print itself outside the tile.

The total width and height of the circle is 14.5 pt. Using a tile size of 10 pt will result in overlapping circles:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{patterns}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\newdimen\GridSize
\tikzset{
GridSize/.code={\GridSize=#1},
GridSize=3pt
}

\pgfdeclarepatternformonly[\GridSize]{MyCircleGrid}
{\pgfqpoint{-7.25pt}{-7.25pt}}% Lower left corner of bounding box
{\pgfqpoint{7.25pt}{7.25pt}}% Upper right corner of bounding box
{\pgfqpoint{\GridSize}{\GridSize}}% Tile size
{
\pgfsetlinewidth{0.5pt}
\pgfsetstrokecolor{blue!80!black}
%\pgfpathqcircle{7pt}
\pgfpathcircle\pgfpointorigin{7pt}
%\pgfusepath{stroke}
\pgfusepathqstroke
}

\begin{document}
\begin{tikzpicture}
\draw [GridSize=10 pt,pattern=MyCircleGrid] (0,-4.5) rectangle (-7.5,-1.5);
\end{tikzpicture}
\end{document}