shawnlaffan / biodiverse

A tool for the spatial analysis of diversity
http://shawnlaffan.github.io/biodiverse/
GNU General Public License v3.0
73 stars 19 forks source link

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

Closed shawnlaffan closed 2 months ago

shawnlaffan commented 3 months ago

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.

shawnlaffan commented 3 months ago

The relevant code is at https://github.com/shawnlaffan/biodiverse/blob/ddc901f14b006c0727a881d69f88da5e32f35c3a/lib/Biodiverse/GUI/Manager/BaseDatas.pm#L775-L797

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;
            }
        );
    }