min and max x and y calculation