Skip to content

Commit

Permalink
protect against div/0
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Oct 3, 2023
1 parent 1c0448e commit ad3e174
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Prima/Drawable/Gradient.pm
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,14 @@ sub calculate_single
$d1 += ($_ - $l) * ($_ - $l);
$d2 += ($r - $l) * ($r - $l);
}
$fp = int(sqrt($d1) / sqrt($d2) * 64 );
$c1 = ( $l[0] << 16 ) | ( $l[1] << 8 ) | $l[2];
$c2 = ( $r[0] << 16 ) | ( $r[1] << 8 ) | $r[2];
if ( $d2 > 0 ) {
$fp = int(sqrt($d1 / $d2) * 64 );
$c1 = ( $l[0] << 16 ) | ( $l[1] << 8 ) | $l[2];
$c2 = ( $r[0] << 16 ) | ( $r[1] << 8 ) | $r[2];
} else {
$c1 = $c2 = ( $l[0] << 16 ) | ( $l[1] << 8 ) | $l[2];
$fp = 0;
}
}
my $new_stripe = 1;
if ( @ret ) {
Expand Down

0 comments on commit ad3e174

Please sign in to comment.