Allow limiting of generations in the 'descendants' and 'ancestors' methods.

(Suggested by Robert Kern.  Reworking of PR #1.)