Skip to content

Commit

Permalink
Comment on some of the algorithms.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Apr 9, 2015
1 parent d2c7b38 commit c7601ec
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Genealogy/Chart/SVG.pm
Expand Up @@ -168,21 +168,38 @@ sub gen {
}

# Calculate the y-position for a given person number.
# Not entirely sure how I did this, to be honest. Need to reverse engineer
# it and document it!
# This is a decimal fraction of how far down the chart the person
# should appear.
#
# The 1st generation appears 1/2 down the page.
# The 2nd generation appears 1/4 and 3/4 down the page.
# The 3rd generation appears 1/8, 3/8, 5/8 and 7/8 down the page.
# etc ...

sub y_pos {
die unless @_;

# TODO: int?
return num( $_[0] ) / den( $_[0] );
}

# No idea how this works. But it does.
sub num {
my $num = shift;

return 2 * ( $num - den($num) / 2 ) + 1;
}

# The denominator of the calculation of how far down the chart the given
# person should appear.
# For the 1st generation, it is 2.
# For the 2nd generation, it is 4.
# For the 3rd generation, it is 8.
# etc ...
#
# So convert the persons number to a generation number, and calculate
# 2 ** the generation number.

sub den {
my $num = shift;

Expand Down

0 comments on commit c7601ec

Please sign in to comment.