The red dots are example points and the grey lines are the shortest paths between the two rects that the points lie on. The numbers are the points’ normalized distance along said line.

I’m pretty sure I can solve this by projecting the point onto the closest side of the inner and outer rect and getting the distance between the points, but that seems like a very heavy-handed solution.

For axis-aligned rectangles, calculating distance to a side can be done just by subtracting coordinates on the appropriate axis.

For example, if the inner rectangle stretches from x = 50 to x = 100, then the distance of point P to the closer vertical edge is

if (P.x < 50) return 50 - P.x;
if (P.x > 100) return P.x - 100;
else P is inside the inner box OR the closest side is definitely not one of the vertical ones

I ended up figuring out a good solution using sdfs.

Using this SDF function

// Equation used from https://www.ronja-tutorials.com/2018/11/10/2d-sdf-basics.html
private float GetDistanceToRect(Rect rect, Vector2 point)
{
Vector2 halfSize = rect.size / 2f;
point -= rect.center;
Vector2 cwed = new Vector2(Mathf.Abs(point.x), Mathf.Abs(point.y)) - halfSize;
float outsideDistance = new Vector2(Mathf.Max(cwed.x, 0f), Mathf.Max(cwed.y, 0f)).magnitude;
float insideDistance = Mathf.Min(0f, Mathf.Max(cwed.x, cwed.y));
return outsideDistance + insideDistance;
}

I could get the points distance to the inner and outer rect. Dividing the distance to the inner rect by the difference in distance to both rects you can get the normalized distance between the two rects.

Fair point. Now that you call my attention to it, your original diagram doesn’t match your description of the problem; for the diagonal line in the top-right of your diagram, you are not going to the closest point on the outer rectangle (for that, you should always go horizontally or vertically). Looks like you are instead projecting a ray from the closest point on the inner rectangle through the red dot.