It it strange here to redefine the variable r: before it was a rectangle, now what it is ? Also one-letters variable should be used with care.