Depending how you spawn those lines, you can use their IID (first instance is 0 and goes on) to determine which one was first, then IID 2 would be the opposite corner, then you proceed in two steps :
Pick instance 0 to spawn the rectangle, pick instance 2, check the distance with the spawned rectangle and change its dimensions accordingly