From 1dce8b9c65ac40648f3745059f83b68ccc13bae5 Mon Sep 17 00:00:00 2001 From: Daniel Girardeau-Montaut Date: Sun, 8 Dec 2024 15:57:42 +0100 Subject: [PATCH] Bug fix: not setting an offset after filling a SF with zeros can cause strange things when setting the first non-zero value later! --- include/ScalarField.h | 23 ++++++----------------- src/ScalarField.cpp | 13 ++----------- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/include/ScalarField.h b/include/ScalarField.h index 8f311af..96ec877 100644 --- a/include/ScalarField.h +++ b/include/ScalarField.h @@ -116,27 +116,16 @@ namespace CCCoreLib float fillValueF = 0.0f; if (std::isfinite(fillValue)) { - if (fillValue == 0) + if (m_offsetHasBeenSet) { - // special case: filling with zeros - // (it doesn't really give an idea of what the optimal offset is) - resetOffset(); - - //fillValueF = 0.0f; // already set + fillValueF = static_cast(fillValue - m_offset); } else { - if (m_offsetHasBeenSet) - { - fillValueF = static_cast(fillValue - m_offset); - } - else - { - // if the offset has not been set yet, we use the first finite value by default - setOffset(fillValue); - - //fillValueF = 0.0f; // already set - } + // if the offset has not been set yet, we use the first finite value by default + setOffset(fillValue); + + //fillValueF = 0.0f; // already set } } else diff --git a/src/ScalarField.cpp b/src/ScalarField.cpp index 8637940..cb2a396 100644 --- a/src/ScalarField.cpp +++ b/src/ScalarField.cpp @@ -134,17 +134,8 @@ bool ScalarField::resizeSafe(std::size_t count, bool initNewElements/*=false*/, } else // if the offset has not been set yet... { - if (valueForNewElements == 0) - { - // special case: filling with zeros - // (it doesn't really give an idea of what the optimal offset is) - m_offset = 0.0; - } - else - { - // we use the first finite value as offset by default - setOffset(valueForNewElements); - } + // we use the first finite value as offset by default + setOffset(valueForNewElements); } } else