def fold_dimension(x, w, f):
    """
	Takes a coordinate, x, on a single dimension of length w. Returns a tuple
	(new_x, fold) where new_x is the coordinate after the dimension has been
	folded into f pieces and fold is the fold number it is on.
	
	Input::
		
		 ______ w _____
		|              |
		-----+----------
		     |
		     x
		
		      | |
		     \\| |/
		      \\./
		
		new_x ___\\__.\\    f = 3
		          \\/| \\
		            |
		          fold
	"""
    fold_width = (w + (f - 1)) // f
    new_x = x % fold_width
    fold = x // fold_width
    if fold % 2:
        if fold == f - 1:
            new_x = fold_width - (fold_width * f - w) - new_x - 1
        else:
            new_x = fold_width - new_x - 1
    return new_x, fold
