Bijective function on a dense set

Sorry but I could not resist:

    alt text

The map is defined on $[0,1]\times[0,1]$, and can be written as $$ f(x,y) = \begin{cases} (x, (2-x)y) & \text{ if }y\leq 1/2, \\ (x, xy+1-x) & \text{ if }y> 1/2. \end{cases} $$

Just take $D$ to be the set of $(x,y)$ with rational coordinates in $(0,1)\times(0,1)$, then $f$ is bijective on $D$ (because it can be easily inverted), but it is clearly not injective on $[0,1]\times[0,1]$.


Here is another example which is easy to visualize. Let $X=[-1,1]^2$, $I$ be the segment between $(-1,0)$ and $(1,0)$ and $I_0$ its subsegment between $(-1/2,0)$ and $(1/2,0)$. There is a homeomorphism $f$ between $X\setminus I_0$ and $X\setminus \{0\}$ which sends $I\setminus I_0$ to $I\setminus\{0\}$ and extends continuously by setting $f(I_0)=0$. (Think of contracting the segment $I_0$ to the center while deforming the rest of the square continuously.) This map can be given by an explicit formula which is piecewise linear on each horizontal segment. Now define $D=X\setminus I$ and we are done.


The answer to the second question is "yes, for discrete spaces where metric is $d(x, y) = 1,$ for $x \neq y.$