So, what is `from.x`?, is it the left side of outer rectangle?  The x coord of the center? The center of the left shape border? the inside of the left shape border?

I can't know if the math is correct without knowing what the result is supposed to be.