Skip to content

Commit

Permalink
Bug fix: not setting an offset after filling a SF with zeros can caus…
Browse files Browse the repository at this point in the history
…e strange things when setting the first non-zero value later!
  • Loading branch information
dgirardeau committed Dec 8, 2024
1 parent 06936c8 commit 1dce8b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
23 changes: 6 additions & 17 deletions include/ScalarField.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(fillValue - m_offset);
}
else
{
if (m_offsetHasBeenSet)
{
fillValueF = static_cast<float>(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
Expand Down
13 changes: 2 additions & 11 deletions src/ScalarField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1dce8b9

Please sign in to comment.