trees.py: fix bugs in the layout method

- Should have reset drawing state when redrawing after a modification.
- _contour was not permitted to return a negative separation
Adding methods to be used for reduction.
Adding doctests.