You should also check that startCoordinate are smaller than endCoordinate, in case the user draw a rectangle from left to right or bottom to top.