Rotation is (at the moment) always allowed, and the rotation algorithm first tests the piece to see if one of its edges is against one of the edges of the bucket, then rotates it, then for each side that the piece was against, moves it so that the new rotated piece edges are aligned against the same bucket edges as prior to the rotation (this includes the top of the bucket).