Slice alignment question

Okay, so this boils down to a math problem I think but I just can't wrap my head around it.

What I have in place is a rect slice (r1) with another, smaller rect as a child of it (r2). r2 is set to align horizontally at center, vertically at top and anchor horizontally at center, vertically at top. This is all fine and good and means that I can resize r1 and r2 independently of one another and yet have r2 remain in the relative position I want it.

I am using r1 and r2 to generate a map wherein r1 represents the "room" and r2 represents a "wall". The problem arises in trying to correctly plot the x/y coordinates of r2 as they relate to r1. I thought using the screen positions of each (i.e. get the screen x/y of r1's top left corner and then subtract every r2 screen x/y pair from that) would do the trick but it doesn't seem to work. Looking at the plotscripting dictionary a little more closely I see that it does note that the screen position is modified by the alignment of the slice in question.

I'm guessing this will boil down to a formula using the alignment and edges but I'm just having trouble sussing it out. I want a universal case so that no matter how I align an r2 to an r1 (i.e. I could have r2's that are aligned-to-bottom and anchored-to-center or whatever) I can get every x/y pair as it relates to r1 (i.e. as though r2 were parented to r1 "normally").

I'm picturing something like this
Code:

x := slice screen x(r2)
y := slice screen y(r2)
switch(get horiz align(r2)) do
(
case(edge:left) do
(
### total guess:
x -= slice edge x(r2, edge:left)
)
### etc., etc.
)

switch(get vert align(r2)) do
(
case(edge:top) do
(
### total guess:
y += slice edge y(r2, edge:top)
)
### etc., etc.
)

Or maybe there's a function somewhere that already does this?