--Bug fixes

-Changes in the xaos grid were not always being processed due to rounding.
This commit is contained in:
mfeemster 2016-01-16 11:51:29 -08:00
parent 19385c28b9
commit 0b05f1a394
3 changed files with 28 additions and 24 deletions

View File

@ -159,16 +159,13 @@ public:
}
}
#ifdef _DEBUG
//Ensure every element of the distribution was populated.
if (j < CHOOSE_XFORM_GRAIN)
throw "Not all distribution elements set, undefined behavior.";
#endif
//If probability was zero, then nothing was filled in, so make all zero.
//If it was non zero but for some reason didn't fill all elements, then just make the remaining
//elements have the index of the last xform.
byte val = j ? byte(i - 1) : 0;
for (; j < CHOOSE_XFORM_GRAIN; j++)//Make absolutely sure they are set to a valid value.
m_XformDistributions[(distrib * CHOOSE_XFORM_GRAIN) + j] = byte(i - 1);
m_XformDistributions[(distrib * CHOOSE_XFORM_GRAIN) + j] = val;
//Flam3 did this, which gives the same result.
//T t = xforms[0].m_Weight;

View File

@ -65,6 +65,19 @@ static QWidget* SetTabOrder(QWidget* p, QWidget* w1, QWidget* w2)
return w2;
}
/// <summary>
/// Truncates the precision of the value to the specified number of digits
/// after the decimal place.
/// </summary>
/// <param name="val">The value to truncate</param>
/// <param name="digits">The number of digits to leave after the decimal place</param>
/// <returns>The truncated value</returns>
static double TruncPrecision(double val, uint digits)
{
double mult = std::pow(10, digits);
return std::round(mult * val) / mult;
}
/// <summary>
/// Wrapper around QLocale::system().toDouble().
/// </summary>

View File

@ -1,26 +1,24 @@
#include "FractoriumPch.h"
#include "Fractorium.h"
#define XAOS_PREC 6
/// <summary>
/// Initialize the xforms xaos UI.
/// </summary>
void Fractorium::InitXaosUI()
{
int spinHeight = 20;
ui.XaosTableView->verticalHeader()->setSectionsClickable(true);
ui.XaosTableView->horizontalHeader()->setSectionsClickable(true);
m_XaosSpinBox = new DoubleSpinBox(nullptr, spinHeight, 0.1);
m_XaosSpinBox->DoubleClick(true);
m_XaosSpinBox->DoubleClickZero(1);
m_XaosSpinBox->DoubleClickNonZero(0);
m_XaosSpinBox->setDecimals(6);
m_XaosSpinBox->setDecimals(XAOS_PREC);
m_XaosSpinBox->setObjectName("XaosSpinBox");
m_XaosTableModel = nullptr;
m_XaosTableItemDelegate = new DoubleSpinBoxTableItemDelegate(m_XaosSpinBox, this);
connect(m_XaosSpinBox, SIGNAL(valueChanged(double)), this, SLOT(OnXaosChanged(double)), Qt::QueuedConnection);
connect(ui.ClearXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnClearXaosButtonClicked(bool)), Qt::QueuedConnection);
connect(ui.RandomXaosButton, SIGNAL(clicked(bool)), this, SLOT(OnRandomXaosButtonClicked(bool)), Qt::QueuedConnection);
@ -60,7 +58,6 @@ QString FractoriumEmberController<T>::MakeXaosNameString(uint i)
{
Xform<T>* xform = m_Ember.GetXform(i);
QString name;
//if (xform)
//{
// int indexPlus1 = m_Ember.GetXformIndex(xform) + 1;//GUI is 1 indexed to avoid confusing the user.
@ -77,7 +74,6 @@ QString FractoriumEmberController<T>::MakeXaosNameString(uint i)
// // name = name + " (" + QString::fromStdString(xform->m_Name) + ")";
// }
//}
return name;
}
@ -94,9 +90,11 @@ QString FractoriumEmberController<T>::MakeXaosNameString(uint i)
template <typename T>
void FractoriumEmberController<T>::XaosChanged(int x, int y, double val)
{
if (Xform<T>* xform = m_Ember.GetXform(x))
if (!IsClose<T>(val, xform->Xaos(y), 1e-10))//Ensure it actually changed.
Update([&] { xform->SetXaos(y, val); });
auto newVal = TruncPrecision(val, XAOS_PREC);//Sometimes 0 comes in as a very small number, so round.
if (auto xform = m_Ember.GetXform(x))
if (!IsClose<T>(newVal, xform->Xaos(y), 1e-7))
Update([&] { xform->SetXaos(y, newVal); });
}
void Fractorium::OnXaosChanged(double d)
@ -104,7 +102,6 @@ void Fractorium::OnXaosChanged(double d)
if (auto* senderSpinBox = qobject_cast<DoubleSpinBox*>(this->sender()))
{
auto p = senderSpinBox->property("tableindex").toPoint();
m_Controller->XaosChanged(p.x(), p.y(), d);
}
}
@ -122,7 +119,6 @@ void Fractorium::FillXaosTable()
int count = int(m_Controller->XformCount());
QStringList hl, vl;
auto oldModel = m_XaosTableModel;
hl.reserve(count);
vl.reserve(count);
m_XaosTableModel = new QStandardItemModel(count, count, this);
@ -132,7 +128,6 @@ void Fractorium::FillXaosTable()
for (int i = 0; i < count; i++)
{
auto s = QString::number(i + 1);
hl.push_back("F" + s);
vl.push_back("T" + s);
}
@ -192,7 +187,6 @@ void FractoriumEmberController<T>::RandomXaos()
}
}
});
FillXaos();
}
@ -225,5 +219,5 @@ void Fractorium::OnXaosColDoubleClicked(int logicalIndex)
template class FractoriumEmberController<float>;
#ifdef DO_DOUBLE
template class FractoriumEmberController<double>;
template class FractoriumEmberController<double>;
#endif