We've found ourselves having to solve this peculiar problem for a plastic part that we are machining. I'll spare you the details.
Given an arbitrary point $P = (x, y)$ on the cartesian plane, and "rings" of regular hexagons spaced around the origin (with two of the sides parallel to the x axis), determine the side length of the hexagon that $P$ lies on.
I'd like to implement this function in a computer program so that, given the arbitrary point $(x,y)$, the output of the function $L$ is the side length of the relevant hexagon i.e. $f(P) = L$.
Because all hexagons form concentric layers around the origin, and are all orientated the same way ("growing" outwards), the answer is exact i.e. there is only one exact hexagon orientated this way that any arbitrary point on the plane could possibly lie on.
I'd like to stress that the point is completely arbitrary i.e. it is most certainly not a vertex of the hexagon, but it may be.
I've added a visual diagram of two examples of specific points and the hexagons which they lie on, as well as their function values, for visualization purposes.

Start by taking the absolute values of each of $x$ and $y$. This obviously doesn't change which hexagon your point lies on, but you now know it will be either on its top side, or the upper right side.
The line through the origin formed by the upper right corners of all the possible hexagons has slope $\sqrt3$, so if $y \ge \sqrt3\cdot x$ you know the point is on a top side. Then the side length is $\frac{2y}{\sqrt3}$.
Otherwise it is on the sloping side, whose slope is $-\sqrt3$. Continuing along that side until the $x$-intercept gives us $x+y/\sqrt3$.
All in all, $$ f(x) = \begin{cases} 2|y|/\sqrt3 & \text{if } |y| \ge\sqrt3|x| \\ |x| + |y|/\sqrt3 & \text{otherwise} \end{cases} $$