%%
%% This is file `venndiagram.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% venndiagram.dtx  (with options: `venndiagram.sty,package')
%% 
%%  venndiagram.dtx
%%  Copyright 2016 Nicola Talbot
%% 
%%  This work may be distributed and/or modified under the
%%  conditions of the LaTeX Project Public License, either version 1.3
%%  of this license of (at your option) any later version.
%%  The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%%  and version 1.3 or later is part of all distributions of LaTeX
%%  version 2005/12/01 or later.
%% 
%%  This work has the LPPL maintenance status `maintained'.
%% 
%%  The Current Maintainer of this work is Nicola Talbot.
%% 
%%  This work consists of the files venndiagram.dtx and venndiagram.ins and the derived file venndiagram.sty.
%% 
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{venndiagram}[2016/03/16 v1.1 (NLCT) Venn diagrams]
\RequirePackage{xkeyval}
\RequirePackage{tikz}
\RequirePackage{etoolbox}
\newif\ifvennoldpgf
\ifdef\pgfversion
{
  \def\@venn@checkversion#1.#2\@venn@end@checkversion{%
  \ifnum#1<3 \vennoldpgftrue \else \vennoldpgffalse\fi}
  \expandafter\@venn@checkversion\pgfversion.0\@venn@end@checkversion
}
{
  \vennoldpgftrue
}
\newcommand*{\@venn@label@A}{$A$}
\newcommand*{\@venn@label@B}{$B$}
\newcommand*{\@venn@label@C}{$C$}
\newcommand*{\@venn@shade}{lightgray}
\newcommand*{\@venn@label@OnlyA}{}
\newcommand*{\@venn@label@OnlyB}{}
\newcommand*{\@venn@label@OnlyC}{}
\newcommand*{\@venn@label@OnlyAB}{}
\newcommand*{\@venn@label@OnlyAC}{}
\newcommand*{\@venn@label@OnlyBC}{}
\newcommand*{\@venn@label@ABC}{}
\newcommand*{\@venn@label@NotABC}{}
\newcommand*{\@venn@label@NotAB}{}
\newcommand*{\@venn@label@AB}{}
\newcommand*{\@venn@radius}{1.2cm}
\newcommand*{\@venn@hgap}{0.5cm}
\newcommand*{\@venn@vgap}{0.5cm}
\newcommand*{\@venn@overlap}{0.75cm}
\newcommand*{\@venn@tikzoptions}{}
\newlength\@venn@Ax
\newlength\@venn@Ay
\newlength\@venn@Bx
\newlength\@venn@By
\newlength\@venn@Cx
\newlength\@venn@Cy
\newlength\@venn@w
\newlength\@venn@h
\define@key{venn}{shade}{\def\@venn@shade{#1}}
\define@key{venn}{labelA}{\def\@venn@label@A{#1}}
\define@key{venn}{labelB}{\def\@venn@label@B{#1}}
\define@key{venn}{labelC}{\def\@venn@label@C{#1}}
\define@key{venn}{labelOnlyA}{\def\@venn@label@OnlyA{#1}}
\define@key{venn}{labelOnlyB}{\def\@venn@label@OnlyB{#1}}
\define@key{venn}{labelOnlyC}{\def\@venn@label@OnlyC{#1}}
\define@key{venn}{labelOnlyAB}{\def\@venn@label@OnlyAB{#1}}
\define@key{venn}{labelOnlyAC}{\def\@venn@label@OnlyAC{#1}}
\define@key{venn}{labelOnlyBC}{\def\@venn@label@OnlyBC{#1}}
\define@key{venn}{labelABC}{\def\@venn@label@ABC{#1}}
\define@key{venn}{labelNotABC}{\def\@venn@label@NotABC{#1}}
\define@key{venn}{labelAB}{\def\@venn@label@AB{#1}}
\define@key{venn}{labelNotAB}{\def\@venn@label@NotAB{#1}}
\define@key{venn}{radius}{\def\@venn@radius{#1}}
\define@key{venn}{hgap}{\def\@venn@hgap{#1}}
\define@key{venn}{vgap}{\def\@venn@vgap{#1}}
\define@key{venn}{overlap}{\def\@venn@overlap{#1}}
\define@key{venn}{tikzoptions}{\def\@venn@tikzoptions{#1}}
\newcommand*{\@venn@computecircleintersects}[4]{%
 \ifdim#1=#3\relax
  \pgfmathsetlength{\@venn@intersect@i@y}{0.5*(#4+#2)}%
  \setlength{\@venn@intersect@ii@y}{\@venn@intersect@i@y}%
  \pgfmathsetlength{\dimen@i}{#4-#2}%
  \pgfmathsetlength{\dimen@}{\@venn@radius*\@venn@radius-0.25*\dimen@i*\dimen@i}%
  \setlength{\@venn@intersect@i@x}{#1}%
  \setlength{\@venn@intersect@ii@x}{#1}%
  \ifdim\dimen@=0pt\relax
   \def\@venn@intersect@n{1}%
  \else
   \ifdim\dimen@>0pt\relax
     \def\@venn@intersect@n{2}%
     \pgfmathsetlength{\dimen@i}{sqrt(\dimen@)}%
     \addtolength{\@venn@intersect@i@x}{\dimen@i}%
     \addtolength{\@venn@intersect@ii@x}{-\dimen@i}%
   \else
     \def\@venn@intersect@n{0}%
   \fi
  \fi
 \else
   \ifdim#2=#4\relax
     \pgfmathsetlength{\@venn@intersect@i@x}{0.5*(#3+#1)}%
     \setlength{\@venn@intersect@ii@x}{\@venn@intersect@i@x}%
     \setlength{\dimen@i}{#3}%
     \addtolength{\dimen@i}{-#1}%
     \pgfmathsetlength{\dimen@}{\@venn@radius*\@venn@radius
       -0.25*\dimen@i*\dimen@i}%
     \setlength{\@venn@intersect@i@y}{#2}%
     \setlength{\@venn@intersect@ii@y}{#2}%
     \ifdim\dimen@=0pt\relax
      \def\@venn@intersect@n{1}%
     \else
      \ifdim\dimen@>0pt\relax
        \def\@venn@intersect@n{2}%
        \pgfmathsetlength{\dimen@i}{sqrt(\dimen@)}%
        \addtolength{\@venn@intersect@i@y}{\dimen@i}%
        \addtolength{\@venn@intersect@ii@y}{-\dimen@i}%
      \else
        \def\@venn@intersect@n{0}%
      \fi
     \fi
   \else
    \pgfmathparse{#1/72.27}\let\@vnn@ax\pgfmathresult
    \pgfmathparse{#2/72.27}\let\@vnn@ay\pgfmathresult
    \pgfmathparse{#3/72.27}\let\@vnn@bx\pgfmathresult
    \pgfmathparse{#4/72.27}\let\@vnn@by\pgfmathresult
    \pgfmathparse{\@venn@radius/72.27}\let\@vnn@r\pgfmathresult
    \pgfmathparse{\@vnn@ax*\@vnn@ax}\let\@vnn@ax@sq\pgfmathresult
    \pgfmathparse{\@vnn@ay*\@vnn@ay}\let\@vnn@ay@sq\pgfmathresult
    \pgfmathparse{\@vnn@bx*\@vnn@bx}\let\@vnn@bx@sq\pgfmathresult
    \pgfmathparse{\@vnn@by*\@vnn@by}\let\@vnn@by@sq\pgfmathresult
    \pgfmathparse{\@vnn@r*\@vnn@r}\let\@vnn@r@sq\pgfmathresult
    \pgfmathparse{0.5*(\@vnn@bx@sq-\@vnn@ax@sq+\@vnn@by@sq-\@vnn@ay@sq)
       /(\@vnn@by-\@vnn@ay)}%
    \let\@vnn@c\pgfmathresult
    \pgfmathparse{(\@vnn@ax-\@vnn@bx)/(\@vnn@by-\@vnn@ay)}%
    \let\@vnn@m\pgfmathresult
    \pgfmathparse{1+\@vnn@m*\@vnn@m}%
    \let\@vnn@one@plus@m@sq\pgfmathresult
     \pgfmathparse{\@vnn@m*(\@vnn@c-\@vnn@ay)-\@vnn@ax}%
     \let\@vnn@b\pgfmathresult
     \pgfmathparse{\@vnn@b*\@vnn@b
      - \@vnn@one@plus@m@sq
       *(\@vnn@ax@sq+\@vnn@ay@sq+\@vnn@c*\@vnn@c
         -2*\@vnn@ay*\@vnn@c-\@vnn@r@sq)}%
     \let\@vnn@root\pgfmathresult
     \setlength\dimen@{\pgfmathresult in}%
     \ifdim\dimen@=0pt\relax
       \def\@venn@intersect@n{1}%
        \pgfmathparse{-\@vnn@b/\@vnn@one@plus@m@sq}%
        \setlength{\@venn@intersect@i@x}{\pgfmathresult in}%
        \setlength{\@venn@intersect@ii@x}{\@venn@intersect@i@x}%
        \pgfmathparse{\pgfmathresult*\@vnn@m+c}%
        \setlength{\@venn@intersect@i@y}{\pgfmathresult in}%
        \setlength{\@venn@intersect@ii@y}{\@venn@intesect@i@y}%
     \else
       \ifdim\dimen@>0pt\relax
         \def\@venn@intersect@n{2}%
         \pgfmathsqrt{\@vnn@root}%
         \let\@vnn@root\pgfmathresult
         \pgfmathparse{(-\@vnn@b+\@vnn@root)/\@vnn@one@plus@m@sq}%
         \setlength{\@venn@intersect@i@x}{\pgfmathresult in}%
         \pgfmathparse{\pgfmathresult*\@vnn@m+\@vnn@c}%
         \setlength{\@venn@intersect@i@y}{\pgfmathresult in}%
         \pgfmathparse{(-\@vnn@b-\@vnn@root)/\@vnn@one@plus@m@sq}%
         \setlength{\@venn@intersect@ii@x}{\pgfmathresult in}%
         \pgfmathparse{\pgfmathresult*\@vnn@m+\@vnn@c}%
         \setlength{\@venn@intersect@ii@y}{\pgfmathresult in}%
       \else
         \def\@venn@intersect@n{0}%
       \fi
     \fi
   \fi
 \fi
}
\newlength\@venn@intersect@i@x
\newlength\@venn@intersect@i@y
\newlength\@venn@intersect@ii@x
\newlength\@venn@intersect@ii@y
\newenvironment{venndiagram3sets}[1][]%
{%
  \disable@keys{venn}{labelAB,labelNotAB}%
  \setkeys{venn}{#1}%
  \pgfmathsetlength{\@venn@Cx}{\@venn@hgap + 2*\@venn@radius
    -0.5*\@venn@overlap}%
  \pgfmathsetlength{\@venn@Cy}{\@venn@vgap+\@venn@radius}%
  \pgfmathsetlength{\@venn@Ax}{\@venn@hgap+\@venn@radius}%
  \pgfmathsetlength{\@venn@Ay}{\@venn@Cy
    + (\@venn@radius - 0.5*\@venn@overlap)*1.73205}%
  \pgfmathsetlength{\@venn@Bx}{\@venn@hgap+3*\@venn@radius
    -\@venn@overlap}%
  \setlength{\@venn@By}{\@venn@Ay}%
  \pgfmathsetlength{\@venn@w}{2*\@venn@hgap+4*\@venn@radius
     -\@venn@overlap}%
  \pgfmathsetlength{\@venn@h}{2*\@venn@vgap+4*\@venn@radius
     -\@venn@overlap}%
  \def\fillA{\path[fill=\@venn@shade] (\@venn@Ax,\@venn@Ay)
    circle (\@venn@radius);}%
  \def\fillB{\path[fill=\@venn@shade] (\@venn@Bx,\@venn@By)
    circle (\@venn@radius);}%
  \def\fillC{\path[fill=\@venn@shade] (\@venn@Cx,\@venn@Cy)
    circle (\@venn@radius);}%
  \def\fillAll{\path[fill=\@venn@shade] (0,0)
    rectangle (\@venn@w,\@venn@h);}%
  \def\fillNotA{\path[fill=\@venn@shade,even odd rule]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);}%
  \def\fillNotB{\path[fill=\@venn@shade,even odd rule]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Bx,\@venn@By) circle (\@venn@radius);}%
  \def\fillNotC{\path[fill=\@venn@shade,even odd rule]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);}%
  \let\fillOnlyA\@venn@fillOnlyA@threesets
  \let\fillOnlyB\@venn@fillOnlyB@threesets
  \let\fillOnlyC\@venn@fillOnlyC@threesets
  \let\fillNotABC\@venn@fillNotABC@threesets
  \def\fillANotB{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Ax,\@venn@Ay) circle (\@venn@radius)
        (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \end{scope}
  }%
  \def\fillBNotA{%
    \begin{scope}
      \clip (\@venn@Bx,\@venn@By) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Bx,\@venn@By) circle (\@venn@radius)
        (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
    \end{scope}
  }%
  \def\fillANotC{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Ax,\@venn@Ay) circle (\@venn@radius)
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
    \end{scope}
  }%
  \def\fillCNotA{%
    \begin{scope}
      \clip (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius)
        (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
    \end{scope}
  }%
  \def\fillBNotC{%
    \begin{scope}
      \clip (\@venn@Bx,\@venn@By) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Bx,\@venn@By) circle (\@venn@radius)
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
    \end{scope}
  }%
  \def\fillCNotB{%
    \begin{scope}
      \clip (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius)
        (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \end{scope}
  }%
  \def\fillACapB{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \path[fill=\@venn@shade]
        (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillBCapA\fillACapB
  \def\fillACapC{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \path[fill=\@venn@shade]
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillCCapA\fillACapC
  \def\fillBCapC{%
    \begin{scope}
      \clip (\@venn@Bx,\@venn@By) circle (\@venn@radius);
      \path[fill=\@venn@shade]
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillCCapB\fillBCapC
  \def\fillACapBNotC{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \clip (\@venn@Bx,\@venn@By) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Bx,\@venn@By) circle (\@venn@radius)
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillBCapANotC\fillACapBNotC
  \def\fillACapCNotB{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \clip (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius)
        (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillCCapANotB\fillACapCNotB
  \def\fillBCapCNotA{%
    \begin{scope}
      \clip (\@venn@Bx,\@venn@By) circle (\@venn@radius);
      \clip (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
      \path[fill=\@venn@shade,even odd rule]
        (\@venn@Cx,\@venn@Cy) circle (\@venn@radius)
        (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillCCapBNotA\fillBCapCNotA
  \def\fillACapBCapC{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \clip (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
      \path[fill=\@venn@shade]
        (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillACapCCapB\fillACapBCapC
  \let\fillBCapACapC\fillACapBCapC
  \let\fillBCapCCapA\fillACapBCapC
  \let\fillCCapACapB\fillACapBCapC
  \let\fillCCapBCapA\fillACapBCapC
  \ifdefempty{\@venn@tikzoptions}%
  {%
    \def\@venn@dobegin{\begin{tikzpicture}}%
  }%
  {%
    \edef\@venn@dobegin{\noexpand\begin{tikzpicture}%
       [\expandonce\@venn@tikzoptions]}%
  }%
  \@venn@dobegin
  \path (0,0) coordinate (venn bottom left)
        (0,\@venn@h) coordinate (venn top left)
        (\@venn@w,\@venn@h) coordinate (venn top right)
        (\@venn@w,0) coordinate (venn bottom right);
}%
{%
    \draw (0,0) rectangle (\@venn@w,\@venn@h);
    \draw (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
    \draw (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \draw (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);
    \draw (\@venn@Ax,\@venn@Ay) node[above,left] (labelOnlyA) {\@venn@label@OnlyA};
    \draw (\@venn@Bx,\@venn@By) node[above,right] (labelOnlyB) {\@venn@label@OnlyB};
    \draw (\@venn@Cx,\@venn@Cy) node[below] (labelOnlyC) {\@venn@label@OnlyC};
    \draw (\@venn@vgap,\@venn@hgap) node (labelNotABC) {\@venn@label@NotABC};
    \draw (\@venn@Ax,\@venn@Ay+\@venn@radius)
      node[below] (labelA) {\@venn@label@A};
    \draw (\@venn@Bx,\@venn@By+\@venn@radius)
      node[below] (labelB) {\@venn@label@B};
    \draw (\@venn@Cx,\@venn@vgap) node[above] (labelC) {\@venn@label@C};
    \draw (\@venn@Cx,0.5*\@venn@h) node (labelABC) {\@venn@label@ABC};
    \draw (\@venn@Cx,\@venn@Ay) node[above] (labelOnlyAB) {\@venn@label@OnlyAB};
    \draw (\@venn@Ax,\@venn@Ay) ++(-60:\@venn@radius-0.5*\@venn@overlap)
      node[below left] (labelOnlyAC) {\@venn@label@OnlyAC};
    \draw (\@venn@Bx,\@venn@By) ++(-120:\@venn@radius-0.5*\@venn@overlap)
      node[below right] (labelOnlyBC) {\@venn@label@OnlyBC};
    \@postvennhook
  \end{tikzpicture}
}
\newcommand*{\@postvennhook}{}
\newcommand*{\setpostvennhook}[1]{\def\@postvennhook{#1}}
\newcommand*\@venn@fillOnlyA@threesets{%
    \@venn@computecircleintersects{\@venn@Ax}{\@venn@Ay}{\@venn@Bx}{\@venn@By}%
    \ifnum\@venn@intersect@n=2\relax
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Ay}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@i@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Ay}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@i@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Ax}{\@venn@Ay}{\@venn@Cx}{\@venn@Cy}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Ay}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Ay}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathadd{\@venn@end@i@angle}{360}%
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@i@x-\@venn@Cx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@i@y-\@venn@Cy}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@ii@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Bx}{\@venn@By}{\@venn@Cx}{\@venn@Cy}%
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@<\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Cy}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Cy}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@ii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@ii@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@ii@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@iii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@start@pt@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@start@pt@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@iii@angle\pgfmathresult
      \pgfmathsubtract{\@venn@end@iii@angle}{360}%
      \let\@venn@end@iii@angle\pgfmathresult
      \path[fill=\@venn@shade] (\@venn@start@pt@x,\@venn@start@pt@y)
      arc[radius=\@venn@radius,start angle=\@venn@start@i@angle,
      end angle=\@venn@end@i@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@ii@angle,
      end angle=\@venn@end@ii@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@iii@angle,
      end angle=\@venn@end@iii@angle] -- cycle;
    \else
       \fillOnlyA
    \fi
}%
\newcommand*\@venn@fillOnlyB@threesets{%
    \@venn@computecircleintersects{\@venn@Bx}{\@venn@By}{\@venn@Ax}{\@venn@Ay}%
    \ifnum\@venn@intersect@n=2\relax
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Bx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@By}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@i@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Bx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@By}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@i@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Bx}{\@venn@By}{\@venn@Cx}{\@venn@Cy}%
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Bx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@By}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Bx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@By}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@i@x-\@venn@Cx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@i@y-\@venn@Cy}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@ii@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Ax}{\@venn@Ay}{\@venn@Cx}{\@venn@Cy}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@<\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Cy}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Cy}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@ii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@ii@x-\@venn@Ax}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@ii@y-\@venn@Ay}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@iii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@start@pt@x-\@venn@Ax}%
      \pgfmathsetlength{\dimen@ii}{\@venn@start@pt@y-\@venn@Ay}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@iii@angle\pgfmathresult
      \path[fill=\@venn@shade]
      (\@venn@start@pt@x,\@venn@start@pt@y)
      arc[radius=\@venn@radius,start angle=\@venn@start@i@angle,
      end angle=\@venn@end@i@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@ii@angle,
      end angle=\@venn@end@ii@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@iii@angle,
      end angle=\@venn@end@iii@angle] -- cycle;
    \else
       \fillOnlyB
    \fi
}%
\newcommand*\@venn@fillOnlyC@threesets{%
    \@venn@computecircleintersects{\@venn@Cx}{\@venn@Cy}{\@venn@Bx}{\@venn@By}%
    \ifnum\@venn@intersect@n=2\relax
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Cy}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@i@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Cy}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@i@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Cx}{\@venn@Cy}{\@venn@Ax}{\@venn@Ay}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Cy}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Cy}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathsubtract{\@venn@end@i@angle}{360}%
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@i@x-\@venn@Ax}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@i@y-\@venn@Ay}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@ii@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Bx}{\@venn@By}{\@venn@Ax}{\@venn@Ay}%
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@<\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Ay}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Ay}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@ii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@ii@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@ii@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@iii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@start@pt@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@start@pt@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@iii@angle\pgfmathresult
      \path[fill=\@venn@shade] (\@venn@start@pt@x,\@venn@start@pt@y)
      arc[radius=\@venn@radius,start angle=\@venn@start@i@angle,
      end angle=\@venn@end@i@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@ii@angle,
      end angle=\@venn@end@ii@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@iii@angle,
      end angle=\@venn@end@iii@angle] -- cycle;
    \else
       \fillOnlyC
    \fi
}%
\newcommand*\@venn@fillNotABC@threesets{%
    \@venn@computecircleintersects{\@venn@Ax}{\@venn@Ay}{\@venn@Bx}{\@venn@By}%
    \ifnum\@venn@intersect@n=2\relax
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Cx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Cy-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Ay}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@i@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Ay}%
        \edef\@venn@start@pt@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@start@pt@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@i@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Ax}{\@venn@Ay}{\@venn@Cx}{\@venn@Cy}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Bx-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@By-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Ay}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Ax}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Ay}%
        \edef\@venn@end@pt@i@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@i@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathadd{\@venn@end@i@angle}{360}%
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@i@x-\@venn@Cx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@i@y-\@venn@Cy}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@ii@angle\pgfmathresult
      \@venn@computecircleintersects{\@venn@Cx}{\@venn@Cy}{\@venn@Bx}{\@venn@By}%
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@i@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@i@y}%
      \pgfmathsetlength{\dimen@}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \pgfmathsetlength{\dimen@i}{\@venn@Ax-\@venn@intersect@ii@x}%
      \pgfmathsetlength{\dimen@ii}{\@venn@Ay-\@venn@intersect@ii@y}%
      \pgfmathsetlength{\dimen@i}{\dimen@i*\dimen@i+\dimen@ii*\dimen@ii}%
      \ifdim\dimen@>\dimen@i
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Cy}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@i@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@i@y}%
      \else
        \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Cx}%
        \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Cy}%
        \edef\@venn@end@pt@ii@x{\the\@venn@intersect@ii@x}%
        \edef\@venn@end@pt@ii@y{\the\@venn@intersect@ii@y}%
      \fi
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@ii@angle\pgfmathresult
      \pgfmathadd{\@venn@end@ii@angle}{360}%
      \let\@venn@end@ii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@end@pt@ii@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@end@pt@ii@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@iii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@start@pt@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@start@pt@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@iii@angle\pgfmathresult
      \path[fill=\@venn@shade,even odd rule]
        (0,0) rectangle (\@venn@w,\@venn@h)
       (\@venn@start@pt@x,\@venn@start@pt@y)
      arc[radius=\@venn@radius,start angle=\@venn@start@i@angle,
      end angle=\@venn@end@i@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@ii@angle,
      end angle=\@venn@end@ii@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@iii@angle,
      end angle=\@venn@end@iii@angle]
      -- cycle;
    \else
      \path[fill=\@venn@shade,even odd rule]
        (0,0) rectangle (\@venn@w,\@venn@h)
       (\@venn@Ax,\@venn@Ay) circle (\@venn@radius)
       (\@venn@Bx,\@venn@By) circle (\@venn@radius)
       (\@venn@Cx,\@venn@Cy) circle (\@venn@radius);%
    \fi
}%
\newenvironment{venndiagram2sets}[1][]%
{%
  \disable@keys{venn}{labelABC,labelOnlyC,labelOnlyAC,labelOnlyBC,%
    labelNotABC,labelC,labelOnlyAB}%
  \setkeys{venn}{#1}%
  % Calculate centre of A
  \pgfmathsetlength{\@venn@Ax}{\@venn@hgap+\@venn@radius}%
  \pgfmathsetlength{\@venn@Ay}{\@venn@vgap+\@venn@radius}%
  \pgfmathsetlength{\@venn@Bx}{\@venn@hgap+3*\@venn@radius
    -\@venn@overlap}%
  \setlength{\@venn@By}{\@venn@Ay}%
  \pgfmathsetlength{\@venn@w}{2*\@venn@hgap+4*\@venn@radius
     -\@venn@overlap}%
  \pgfmathsetlength{\@venn@h}{2*\@venn@vgap+2*\@venn@radius}%
  \def\fillA{\path[fill=\@venn@shade] (\@venn@Ax,\@venn@Ay)
    circle (\@venn@radius);}%
  \def\fillB{\path[fill=\@venn@shade] (\@venn@Bx,\@venn@By)
    circle (\@venn@radius);}%
  \def\fillAll{\path[fill=\@venn@shade] (0,0)
    rectangle (\@venn@w,\@venn@h);}%
  \let\fillOnlyA\@venn@fillOnlyA@twosets
  \let\fillOnlyB\@venn@fillOnlyB@twosets
  \def\fillNotA{\path[fill=\@venn@shade,even odd rule]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);}%
  \def\fillNotB{\path[fill=\@venn@shade,even odd rule]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Bx,\@venn@By) circle (\@venn@radius);}%
  \def\fillNotAorB{%
    \begin{scope}
    \path[clip]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Bx,\@venn@By) circle (\@venn@radius)
     ;
    \path[fill=\@venn@shade,even odd rule]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Ax,\@venn@Ay) circle (\@venn@radius)
    ;
    \end{scope}
   }%
  \def\fillNotAorNotB{%
    \path[fill=\@venn@shade,nonzero rule]
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Ax,\@venn@Ay) circle (\@venn@radius)
    (0,0) rectangle (\@venn@w,\@venn@h)
    (\@venn@Bx,\@venn@By) circle (\@venn@radius)
    ;
   }%
  \let\fillANotB\fillOnlyA
  \let\fillBNotA\fillOnlyB
  \def\fillACapB{%
    \begin{scope}
      \clip (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
      \path[fill=\@venn@shade]
        (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \end{scope}
  }%
  \let\fillBCapA\fillACapB
  \ifdefempty{\@venn@tikzoptions}%
  {%
    \def\@venn@dobegin{\begin{tikzpicture}}%
  }%
  {%
    \edef\@venn@dobegin{\noexpand\begin{tikzpicture}%
      [\expandonce\@venn@tikzoptions]}%
  }%
  \@venn@dobegin
  \path (0,0) coordinate (venn bottom left)
        (0,\@venn@h) coordinate (venn top left)
        (\@venn@w,\@venn@h) coordinate (venn top right)
        (\@venn@w,0) coordinate (venn bottom right);
}%
{%
    \draw (venn bottom left) rectangle (\@venn@w,\@venn@h);
    \draw (\@venn@Ax,\@venn@Ay) circle (\@venn@radius);
    \draw (\@venn@Bx,\@venn@By) circle (\@venn@radius);
    \draw (\@venn@Ax,\@venn@Ay) node[above,left] (labelOnlyA)
       {\@venn@label@OnlyA};
    \draw (\@venn@Bx,\@venn@By) node[above,right] (labelOnlyB)
       {\@venn@label@OnlyB};
    \draw (\@venn@vgap,\@venn@hgap) node (labelNotAB) {\@venn@label@NotAB};
    \draw (\@venn@Ax,\@venn@Ay+\@venn@radius)
      node[below] (labelA) {\@venn@label@A};
    \draw (\@venn@Bx,\@venn@By+\@venn@radius)
      node[below] (labelB) {\@venn@label@B};
    \draw (0.5*\@venn@w,0.5*\@venn@h) node (labelAB) {\@venn@label@AB};
    \@postvennhook
  \end{tikzpicture}
}
\newcommand*\@venn@fillOnlyA@twosets{%
    \@venn@computecircleintersects{\@venn@Ax}{\@venn@Ay}{\@venn@Bx}{\@venn@By}%
    \ifnum\@venn@intersect@n=2\relax
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Ax}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Ay}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Ax}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Ay}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathadd{\@venn@end@i@angle}{360}%
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@ii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@ii@angle\pgfmathresult
      \pgfmathadd{\@venn@start@ii@angle}{360}%
      \let\@venn@start@ii@angle\pgfmathresult
      \path[fill=\@venn@shade]
       (\@venn@intersect@i@x,\@venn@intersect@i@y)
      arc[radius=\@venn@radius,start angle=\@venn@start@i@angle,
      end angle=\@venn@end@i@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@ii@angle,
      end angle=\@venn@end@ii@angle]
       -- cycle;
    \else
       \fillOnlyA
    \fi
}%
\newcommand*\@venn@fillOnlyB@twosets{%
    \@venn@computecircleintersects{\@venn@Ax}{\@venn@Ay}{\@venn@Bx}{\@venn@By}%
    \ifnum\@venn@intersect@n=2\relax
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Bx}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@By}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@i@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@ii@x-\@venn@Ax}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@ii@y-\@venn@Ay}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@start@ii@angle\pgfmathresult
      \pgfmathsetlength{\dimen@i}{\@venn@intersect@i@x-\@venn@Ax}%
      \pgfmathsetlength{\dimen@ii}{\@venn@intersect@i@y-\@venn@Ay}%
      \ifvennoldpgf
        \pgfmathatantwo{\dimen@i}{\dimen@ii}%
      \else
        \pgfmathatantwo{\dimen@ii}{\dimen@i}%
      \fi
      \let\@venn@end@ii@angle\pgfmathresult
      \path[fill=\@venn@shade]
       (\@venn@intersect@i@x,\@venn@intersect@i@y)
      arc[radius=\@venn@radius,start angle=\@venn@start@i@angle,
      end angle=\@venn@end@i@angle]
      arc[radius=\@venn@radius,start angle=\@venn@start@ii@angle,
      end angle=\@venn@end@ii@angle]
       -- cycle;
    \else
       \fillOnlyB
    \fi
}%
\endinput
%%
%% End of file `venndiagram.sty'.
