Change SizeWidth to snap to nearest shape

Hello,
I have rectangle 1 and vertical line right to rectangle
I need code to change SizeWidth of rectangle to snap to line. So become rectangle 2.
Greetings!