I would like to find the distance of a point from the sides of a rectangle.
here is various examples:

t(x,y) is a point within the rectangle (WxH). We have two angles (1-3 angle is 90 and for Fig 4, angle is theta). The main concern is in figure 1 and finding d = d1+d2.
For other figures, the radius of root(w^2+H^2) can be used as an approximation.
I tried for 4 hours but non of them worked.
I thought of changing the pivot to center of w/2, x/2 and do my calculation. then return it back to t with (w/2-x, h/2-y) or something like that.
As I mentioned, figure 4 is the best thing to describe the issue. however, I will be more happy with the solution with Figure 1.
Thanks