Permalink
Browse files

Avoid division by zero

  • Loading branch information...
1 parent db8945a commit 85243a4003d7b2a65a9e574e9b97406819fc8f3f @jtpalmer committed Mar 29, 2011
Showing with 1 addition and 0 deletions.
  1. +1 −0 week4/lib/Games/ElectricLines.pm
View
1 week4/lib/Games/ElectricLines.pm
@@ -400,6 +400,7 @@ sub _segment_line {
sub _interpolate_x {
my ( $self, $line, $y ) = @_;
my ( $x0, $y0, $x1, $y1 ) = map {@$_} @$line;
+ return $x0 if $x0 == $x1;
my $m = ( $y1 - $y0 ) / ( $x1 - $x0 );
my $b = $y0 - $x0 * $m;
return ( $y - $b ) / $m;

0 comments on commit 85243a4

Please sign in to comment.