shawnlaffan/biodiverse

GUI: unable to change basedata cellsize when origin is non-zero

shawnlaffan opened this issue · 1 comments

The logic is faulty when the system snaps new cellsizes to multiples of the current cellsizes, when the origin is non-zero.

The code should not even be using the origin in this case.

The relevant code is at

foreach my $widget (@resolution_widgets) {
$j++;
$widget->signal_connect (
'value-changed' => sub {
my $val = $widget->get_value;
# Avoid fmod - it causes grief with 0.2 cell sizes
# prob due to floating point issues.
# Precision should be configurable...
my $offset = ($val - $origins_array[$j])
/ $cellsize_array[$j];
if ($cellsize_array[$j] < 1) {
$offset = ($offset * 10e10 + 0.5) / 10e10;
}
$offset -= int $offset;
# effectively zero given cell size constraints
if ($offset > 10e-10) {
$val -= $offset;
$widget->set_value ($val);
}
return;
}
);
}

It can be simplified to this:

    foreach my $widget (@resolution_widgets) {
        $j++;
        $widget->signal_connect (
            'value-changed' => sub {
                my $val = $widget->get_value;
                my $remainder = fmod ($val, $cellsize_array[$j]);
                if (abs ($remainder) > 10e-10) {
                    $widget->set_value ($val - $remainder);
                }
                return;
            }
        );
    }