my ( $last_x, $last_y ) = ( 0,0 );
our @path;
+sub reset_path { @path = () }
sub curve {
- return unless $#path > 4;
- my $curve = Math::CatmullRom->new( splice @path, 0, $#path + $#path / 2 );
+ if ( $#path < ( 4 * 2 - 1 ) ) { # less than 4 points
+ warn "path too short ", dump @path;
+ reset_path;
+ return;
+ }
+
+ my $curve = Math::CatmullRom->new( @path );
my @curve = $curve->curve( $mouse_trashold * 10 );
debug 'curve' => @curve;
my $i = 0;
- while ( $i < $#curve ) {
+ while ( $i < $#curve - 4 ) {
my $from_x = int($curve[$i++]);
my $from_y = int($curve[$i++]);
my $to_x = int($curve[$i++]);
);
}
$app->sync;
+ reset_path;
}
sub handle_events {
if ( $key eq 's' ) { # XXX draw curve
curve;
} elsif ( $key eq 'backspace' ) { # XXX clean screen
- @path = ();
+ reset_path;
my $rect = SDL::Rect->new( -x => 0, -y => 0, -w => $w, -h => $h );
$app->fill( $rect, $black );
$app->update( $rect );