Code cleanup using lookup tables

There were parts of the code that seemed to make more sense as a lookup table instead of a long list of if/else statements.  Changing it to this form seemed to cut down (just slightly) the execution time and memory usage.

Also added some comments and helper functions to make it easier to understand (and hopefully improve) the algorithm.

@tlycken I was actually planning on adding the initial tests as a pull request too, but I forgot that I put them in the master branch. Do you mind looking over that as well?  Sorry about that.
I think we could refactor this into two methods: one that figures out the next vertex location (the if-clauses currently on lines 114-126) and one that adds it to the list of vertices (the `push!`/`unshift!` stuff). At least the latter should be trivial to move outside - and then maybe the `if edge ...` clauses are simple enough to be inlined in the while loop?