I cannot manage to compute and to draw the box (that is, the lower left corner and the upper right corner) that would exactly encompass the green rectangle node and the red point (whose exact coordinates and dimensions can vary).
I tried this code, which does not work:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newdimen\XCoord
\newdimen\YCoord
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoord}{\YCoord};}%
\begin{document}
\begin{tikzpicture}
\clip (-2,-2) rectangle (10,8);
\node[inner sep=2cm, fill=green] (rect) at (3,4) {Bla Bla};
\node[inner sep=1pt, outer sep=0, circle, fill=red] (point) at (-1,1) {};
\ExtractCoordinate{point.center}
\edef\xone{\XCoord}
\edef\yone{\YCoord}
\ExtractCoordinate{rect.south west}
\edef\xtwo{\XCoord}
\edef\ytwo{\YCoord}
\pgfmathparse{min(\xone,\xtwo)}
\coordinate (x) at (\pgfmathresult,0);
\pgfmathparse{min(\yone,\ytwo)}
\coordinate (y) at (0,\pgfmathresult);
\ExtractCoordinate{rect.north east}
\edef\xtwo{\XCoord}
\edef\ytwo{\YCoord}
\pgfmathparse{max(\xone,\xtwo)}
\coordinate (xx) at (\pgfmathresult,0);
\pgfmathparse{max(\yone,\ytwo)}
\coordinate (yy) at (0,\pgfmathresult);
\draw ($(x) + (y)$) rectangle (0, 0);
\draw ($(xx) + (yy)$) rectangle (1, 0);
\draw ($(x) + (y)$) rectangle ($(xx) + (yy)$);
%% The expected result should be equivalent to drawing
% \draw[orange, dashed] (\xone,\yone) rectangle (\xtwo, \ytwo);
\end{tikzpicture}
\end{document}
I first extract the X and Y coordinates of the point and of the south west and north east anchors of the rectangle, then call the min and max functions. However, I guess at this stage: \coordinate (x) at (\pgfmathresult,0);
something goes wrong, so I get incorrect values.
The expected result can be seen after uncommenting the last line in tikzpicture.
fit
library you can just do\node[fit=(rect)(point), inner sep=+0pt,draw] {};
to achieve a rectangle that encompasses(rect)
and(point)
. From your code, you are missing at least a fewpt
after the\pgfmathresult
s in the coordinate specification ofx
,y
and so on.