IsInside method fix for extremal cases