# When do we have $\operatorname{dist}(x, \partial E) = \sup \{ \gamma \geq 0 : B(x, \gamma) \subset E \}$ for $x \in E$?

If $E \subset \mathbb{R}^n$ and $x \in E$, we have that $\operatorname{dist}(x,\partial E) = \sup \{ \gamma \geq 0 : B(x, \gamma) \subset E \}$. What characteristics of $\mathbb{R}^n$ make this true? In other words, what restrictions would we have to impose on a general metric space (or topological space) for this to be true?

Let $X$ be a metric space and $E\subseteq X$ a subset with non-empty boundary. Let $x\in E$. Then by definition, $\operatorname{dist}(x,\partial E)=\inf\{\,\operatorname{dist}(x,y)\mid y\in\partial E\,\}$. So for any $\gamma>\operatorname{dist}(x,\partial E)$, there exists $y\in\partial E$ with $y\in B(x,\gamma)$. By definition of boundary, $B(y,\gamma-\operatorname{dist}(x,\partial E))$ contains exterior points and is $\subseteq B(x,\gamma)$. Hence $B(x,\gamma)\not\subseteq E$. However, for $\gamma<\operatorname{dist}(x,\partial E)$, we can only conclude that $B(x,\gamma)\cap \partial E=\emptyset$, while what we'd need ist $B(x,\gamma)\subseteq E$. It is possible that $B(x,\gamma)$ intersects both the interior and the exterior of $E$, but not its boundary. In that case, $B(x,\gamma)$ is not connected (as witnessed namely by the interior and exterior). Thus the important property that $\Bbb R^n$ has is that
Remark. This may somewhat remind of "locally connected" - but that is not enough. Consider $X=\Bbb R^2\setminus ([0,\infty)\times\{0\})$, which has all the connectivity you want, but for $E=\{\,(x,y)\in X\mid y>0\,\}$ and $a=(4,3)$, we have $\operatorname{dist}(a,\partial E)=5$ and $B(a,4)\not\subseteq E$. As $X$ is homeomorphic to $\Bbb R^2$, this is really a property of the metric, not just of the topology (as should be expected from the very definition)