Trimming TikZ grid

I have the following picture: obtained from:

\begin{tikzpicture}
\draw (0,0) grid (4,4);
\draw[invmidarrow=0.5]
(0,0) to[out=110,in=250] (0,2)
(0,2) to[out=70,in=190] (1,4)
(1,4) to[out=10,in=170] (3,4)
(3,4) to[out=-10,in=180] (4,4)
(4,4) to[out=0.in=45] (4,3)
(4,3) to[out=225,in=135] (4,2)
(4,2) to[out=-45,in=190] (4,1)
(4,1) to[out=-10,in=-10] (3,0)
(3,0) to[out=190,in=290] (0,0);
\end{tikzpicture}

with the following key definition:

\tikzset{invmidarrow/.style={postaction=decorate,decoration={markings,mark={at position #1 with {\arrow{latex reversed}}}}}}

and using the decorations.markings library. I would like to know if there are easy ways to:

1. Trim and extend the grid so that it only fills the curve;
2. Add arrows to the grid so that all (or some of) the squares have counterclockwise arrows;
3. Add arrow tips every x*(curve length) to the curve, x being a fraction I can choose.

The picture is in Physics notes, where the teacher derived conservativity of the electric field from the nullity of its curl, and is illustrating the process by which we do so, turning the line integral into a sum of line integrals which are then turned into surface integrals of the curl over the single squares, which are imagined to become smaller and smaller.

MWE:

\documentclass[a4paper]{report}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{invmidarrow/.style={postaction=decorate,decoration={markings,mark={at position #1 with {\arrow{latex reversed}}}}}}

\begin{document}

\begin{tikzpicture}
\draw (0,0) grid (4,4);
\draw[invmidarrow=0.5]
(0,0) to[out=110,in=250] (0,2)
(0,2) to[out=70,in=190] (1,4)
(1,4) to[out=10,in=170] (3,4)
(3,4) to[out=-10,in=180] (4,4)
(4,4) to[out=0.in=45] (4,3)
(4,3) to[out=225,in=135] (4,2)
(4,2) to[out=-45,in=190] (4,1)
(4,1) to[out=-10,in=-10] (3,0)
(3,0) to[out=190,in=290] (0,0);
\end{tikzpicture}
\end{document}
• For (1) use \draw[clip] (0,0) grid (4,4); – Sigur Oct 25 '14 at 13:13
• @Sigur maybe I'm missing something, but simply adding [clip] to my code for the grid makes the curve vanish. – MickG Oct 25 '14 at 13:21
• I tried to reproduce your code but something is wrong with the markings.decorations. Please, edit your post and add the minimal code so we can copy and paste it. – Sigur Oct 25 '14 at 13:25
• @Sigur see if decorations.markings works. I'm afraid I swapped the two parts of the library name :). If it doesn't, I'll post the complete minimal code. – MickG Oct 25 '14 at 13:29
• OK, it works now. But now I understand your problem. No solution for a while. – Sigur Oct 25 '14 at 13:57

Do you want something like this? \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{invmidarrow/.style={postaction=decorate,decoration={markings,mark={between positions 0 and 1 step #1
with {\arrow{latex reversed}}}}}}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\draw [clip]
(0,0) to[out=110,in=250]
(0,2) to[out=70,in=190]
(1,4) to[out=10,in=170]
(3,4) to[out=-10,in=180]
(4,4) to[out=0.in=45]
(4,3) to[out=225,in=135]
(4,2) to[out=-45,in=190]
(4,1) to[out=-10,in=-10]
(3,0) to[out=190,in=290] (0,0);
\draw (-1,-1) grid (5,5);
\end{scope}
\draw [thick,invmidarrow=10mm]
(0,0) to[out=110,in=250]
(0,2) to[out=70,in=190]
(1,4) to[out=10,in=170]
(3,4) to[out=-10,in=180]
(4,4) to[out=0.in=45]
(4,3) to[out=225,in=135]
(4,2) to[out=-45,in=190]
(4,1) to[out=-10,in=-10]
(3,0) to[out=190,in=290] (0,0);
\draw[red,invmidarrow=5mm] (1,1) rectangle (3,3);
\end{tikzpicture}
\end{document}

Edit

Putting

\draw[red,invmidarrow=10mm] (1.5,1) -- (1,1) -- (1,3) -- (3,3) -- (3,1) -- cycle;

\draw[red,invmidarrow=5mm] (1,1) rectangle (3,3);

we get and we avoid markings on the vertices.

• Why did you use a scope? It isn't strictly necessary after all, and it duplicates the code for the curve. Anyway that's exactly what I want, provided I choose which rectangles to put arrows on. – MickG Oct 25 '14 at 15:48
• And the markings on the vertexes look bad, how do I only put those on the edges? – MickG Oct 25 '14 at 15:51
• @MickG scope is strictly for use clip option for the grid and to avoid trim the arrows on the border – skpblack Oct 25 '14 at 15:52
• I see now: the arrow tips get trimmed without the scope, since [clip] will clip anything that crosses the border of the curve, including marks on the curve. But how do I get the arrows on the angle vertexes to vanish? @skpblack – MickG Oct 25 '14 at 16:18
• @MickG View edit – skpblack Oct 25 '14 at 16:22