diff --git a/Source/Ember/Iterator.h b/Source/Ember/Iterator.h index b02ff46..1d104ef 100644 --- a/Source/Ember/Iterator.h +++ b/Source/Ember/Iterator.h @@ -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; diff --git a/Source/Fractorium/FractoriumCommon.h b/Source/Fractorium/FractoriumCommon.h index 04e2f05..f149544 100644 --- a/Source/Fractorium/FractoriumCommon.h +++ b/Source/Fractorium/FractoriumCommon.h @@ -65,6 +65,19 @@ static QWidget* SetTabOrder(QWidget* p, QWidget* w1, QWidget* w2) return w2; } +/// +/// Truncates the precision of the value to the specified number of digits +/// after the decimal place. +/// +/// The value to truncate +/// The number of digits to leave after the decimal place +/// The truncated value +static double TruncPrecision(double val, uint digits) +{ + double mult = std::pow(10, digits); + return std::round(mult * val) / mult; +} + /// /// Wrapper around QLocale::system().toDouble(). /// diff --git a/Source/Fractorium/FractoriumXaos.cpp b/Source/Fractorium/FractoriumXaos.cpp index d930fae..abd8326 100644 --- a/Source/Fractorium/FractoriumXaos.cpp +++ b/Source/Fractorium/FractoriumXaos.cpp @@ -1,26 +1,24 @@ #include "FractoriumPch.h" #include "Fractorium.h" +#define XAOS_PREC 6 + /// /// Initialize the xforms xaos UI. /// 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::MakeXaosNameString(uint i) { Xform* 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::MakeXaosNameString(uint i) // // name = name + " (" + QString::fromStdString(xform->m_Name) + ")"; // } //} - return name; } @@ -94,9 +90,11 @@ QString FractoriumEmberController::MakeXaosNameString(uint i) template void FractoriumEmberController::XaosChanged(int x, int y, double val) { - if (Xform* xform = m_Ember.GetXform(x)) - if (!IsClose(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(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(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); } @@ -144,7 +139,7 @@ void Fractorium::FillXaosTable() SetTabOrder(this, ui.ClearXaosButton, ui.RandomXaosButton); m_Controller->FillXaos(); ui.XaosTableView->blockSignals(false); - + if (oldModel) delete oldModel; @@ -192,7 +187,6 @@ void FractoriumEmberController::RandomXaos() } } }); - FillXaos(); } @@ -225,5 +219,5 @@ void Fractorium::OnXaosColDoubleClicked(int logicalIndex) template class FractoriumEmberController; #ifdef DO_DOUBLE - template class FractoriumEmberController; +template class FractoriumEmberController; #endif