From 9a906bc936d578931df9d81b76139efaf50bbe99 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Wed, 1 May 2024 17:21:23 +1000 Subject: [PATCH] GUI: Improved value checks for bd clone with reduced resolutions --- lib/Biodiverse/GUI/Manager/BaseDatas.pm | 34 ++++++++++--------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/Biodiverse/GUI/Manager/BaseDatas.pm b/lib/Biodiverse/GUI/Manager/BaseDatas.pm index 651c14fa5..25ac668ea 100644 --- a/lib/Biodiverse/GUI/Manager/BaseDatas.pm +++ b/lib/Biodiverse/GUI/Manager/BaseDatas.pm @@ -777,19 +777,11 @@ sub get_resolution_table_widget { $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); + if (fmod ($self->round_to_precision_aa ($val / $cellsize_array[$j], 1e11), 1)) { + my $remainder = fmod ($val, $cellsize_array[$j]); + if (abs ($remainder) > 1e-12) { + $widget->set_value($val - $remainder); + } } return; } @@ -932,13 +924,15 @@ sub get_origin_table_widget { $widget->signal_connect ( 'value-changed' => sub { my $val = $widget->get_value; - my $fmod = fmod ( - ($val - $origins_array[$j]), - $cellsize_array[$j], - ); - if ($fmod) { - $val -= $fmod; - $widget->set_value ($val); + my $val_in_cell_units + = $self->round_to_precision_aa (($val - $origins_array[$j]) / $cellsize_array[$j], 1e11); + + if (fmod ($val_in_cell_units, 1)) { + my $remainder = fmod ($val - $origins_array[$j], $cellsize_array[$j]); + say join ' ', $val, $val_in_cell_units, $remainder; + if (abs ($remainder) > 1e-12) { + $widget->set_value($val - $remainder); + } } return; }