From ee1d5eb44da3af595cc6da96f8c8e07ceb99cf43 Mon Sep 17 00:00:00 2001 From: Person Date: Mon, 24 Jun 2019 19:43:15 -0700 Subject: [PATCH] --Bug fixes -Fix some potential OpenCL compilation bugs on circlecrop, circlecrop2, oscilloscope2, Truchet_hex_crop. -Prevent the minus key from changing the current xform when being pressed in a textbox. --Code changes -Cleanup some casting in depth_blur, depth_blur2. --- Source/Ember/Variations01.h | 2 +- Source/Ember/Variations04.h | 4 +-- Source/Ember/Variations07.h | 32 ++++++++++--------- Source/EmberCommon/EmberCommon.h | 49 ++++++++++++++++++++++++++++++ Source/EmberTester/EmberTester.cpp | 23 ++++++++------ Source/Fractorium/Fractorium.cpp | 5 +-- 6 files changed, 87 insertions(+), 28 deletions(-) diff --git a/Source/Ember/Variations01.h b/Source/Ember/Variations01.h index a7a8119..546664b 100644 --- a/Source/Ember/Variations01.h +++ b/Source/Ember/Variations01.h @@ -5026,7 +5026,7 @@ public: << "\t\treal_t t;\n" << "\t\treal_t pt = " << perturbation << " * sin(" << tpf2 << " * vIn.y);\n" << "\n" - << "\t\tif (!" << damping << ")\n" + << "\t\tif (" << damping << " == 0)\n" << "\t\t t = fma(" << amplitude << ", cos(fma(" << tpf << ", vIn.x, pt)), " << separation << ");\n" << "\t\telse\n" << "\t\t t = fma(" << amplitude << ", exp(-fabs(vIn.x) * " << damping << ") * cos(fma(" << tpf << ", vIn.x, pt)), " << separation << ");\n" diff --git a/Source/Ember/Variations04.h b/Source/Ember/Variations04.h index e0f2141..0d79095 100644 --- a/Source/Ember/Variations04.h +++ b/Source/Ember/Variations04.h @@ -2190,7 +2190,7 @@ public: helper.Out.x = m_Weight * xi + m_X; helper.Out.y = m_Weight * yi + m_Y; } - else if (!cr0 && esc) + else if (!cr0 && esc) { helper.Out.x = m_Weight * rdc * c + m_X; helper.Out.y = m_Weight * rdc * s + m_Y; @@ -2360,7 +2360,7 @@ public: << "\n" << "\t\tif (rad > " << out << " || rad < " << in << ")\n" << "\t\t{\n" - << "\t\t if (!" << zero << ")\n" + << "\t\t if (" << zero << " == 0)\n" << "\t\t {\n" << "\t\t s = sin(ang) * " << outweight << ";\n" << "\t\t c = cos(ang) * " << outweight << ";\n" diff --git a/Source/Ember/Variations07.h b/Source/Ember/Variations07.h index dafc4e2..1b7fae4 100644 --- a/Source/Ember/Variations07.h +++ b/Source/Ember/Variations07.h @@ -1581,7 +1581,7 @@ public: << "\n" << "\t\tbool add = true;\n" << "\n" - << "\t\tif (" << seed << " == 1)\n" + << "\t\tif (" << seed << " == (real_t)(1.0))\n" << "\t\t{\n" << "\t\t if (!((int)rx & 1) && !((int)rz & 1))\n" << "\t\t add = false;\n" @@ -1861,7 +1861,7 @@ public: << "\t\treal_t y0 = sin(angle2);\n" << "\t\treal_t dist = sqrt(Sqr(FX - x0) + Sqr(FY - y0));\n" << "\n" - << "\t\tif (" << inv << ")\n" + << "\t\tif (" << inv << " != (real_t)(0.0))\n" << "\t\t{\n" << "\t\t if ((dist > " << d1precalc << ") || (dist < " << d2precalc << "))\n" << "\t\t {\n" @@ -3007,11 +3007,12 @@ public: f = f - int_angle; T x = f * m_Length; T z = std::sqrt(1 + SQR(x) - 2 * x * m_CosAlpha); + int iangle = int(int_angle); - if (!(((int)int_angle) & 1)) - int_angle = m_2piOverPower * (((int)int_angle) / 2) + std::asin(m_SinAlpha * x / Zeps(z)); + if (!(iangle & 1)) + int_angle = m_2piOverPower * (iangle / 2) + std::asin(m_SinAlpha * x / Zeps(z)); else - int_angle = m_2piOverPower * (((int)int_angle) / 2) - std::asin(m_SinAlpha * x / Zeps(z)); + int_angle = m_2piOverPower * (iangle / 2) - std::asin(m_SinAlpha * x / Zeps(z)); z *= std::sqrt(rand.Frand01()); by = std::sin(int_angle - T(M_PI_2)); @@ -3056,11 +3057,12 @@ public: << "\t\t f = f - int_angle;\n" << "\t\t real_t x = f * " << length << ";\n" << "\t\t real_t z = sqrt(1 + SQR(x) - 2 * x * " << cosalpha << ");\n" + << "\t\t int iangle = (int)int_angle;\n" << "\n" - << "\t\t if (!(((int)int_angle) & 1))\n" - << "\t\t int_angle = " << twopioverpower << " * (((int)int_angle) / 2) + asin(" << sinalpha << " * x / Zeps(z));\n" + << "\t\t if (!(iangle & 1))\n" + << "\t\t int_angle = " << twopioverpower << " * (iangle / 2) + asin(" << sinalpha << " * x / Zeps(z));\n" << "\t\t else\n" - << "\t\t int_angle = " << twopioverpower << " * (((int)int_angle) / 2) - asin(" << sinalpha << " * x / Zeps(z));\n" + << "\t\t int_angle = " << twopioverpower << " * (iangle / 2) - asin(" << sinalpha << " * x / Zeps(z));\n" << "\n" << "\t\t z *= sqrt(MwcNext01(mwc));\n" << "\t\t by = sin(int_angle - MPI2);\n" @@ -3155,11 +3157,12 @@ public: f = f - int_angle; T x = f * m_Length; T z = std::sqrt(1 + SQR(x) - 2 * x * std::cos(m_Alpha)); + int iangle = int(int_angle); - if (!(((int)int_angle) & 1)) - int_angle = m_2piOverPower * (((int)int_angle) / 2) + std::asin(std::sin(m_Alpha) * x / Zeps(z)); + if (!(iangle & 1)) + int_angle = m_2piOverPower * (iangle / 2) + std::asin(std::sin(m_Alpha) * x / Zeps(z)); else - int_angle = m_2piOverPower * (((int)int_angle) / 2) - std::asin(std::sin(m_Alpha) * x / Zeps(z)); + int_angle = m_2piOverPower * (iangle / 2) - std::asin(std::sin(m_Alpha) * x / Zeps(z)); z *= std::sqrt(rand.Frand01()); by = std::sin(int_angle - T(M_PI_2)); @@ -3209,11 +3212,12 @@ public: << "\t\t f = f - int_angle;\n" << "\t\t real_t x = f * " << length << ";\n" << "\t\t real_t z = sqrt(1 + SQR(x) - 2 * x * cos(" << alpha << "));\n" + << "\t\t int iangle = (int)int_angle;\n" << "\n" - << "\t\t if (!(((int)int_angle) & 1))\n" - << "\t\t int_angle = " << twopioverpower << " * (((int)int_angle) / 2) + asin(sin(" << alpha << ") * x / Zeps(z));\n" + << "\t\t if (!(iangle & 1))\n" + << "\t\t int_angle = " << twopioverpower << " * (iangle / 2) + asin(sin(" << alpha << ") * x / Zeps(z));\n" << "\t\t else\n" - << "\t\t int_angle = " << twopioverpower << " * (((int)int_angle) / 2) - asin(sin(" << alpha << ") * x / Zeps(z));\n" + << "\t\t int_angle = " << twopioverpower << " * (iangle / 2) - asin(sin(" << alpha << ") * x / Zeps(z));\n" << "\n" << "\t\t z *= sqrt(MwcNext01(mwc));\n" << "\t\t by = sin(int_angle - MPI2);\n" diff --git a/Source/EmberCommon/EmberCommon.h b/Source/EmberCommon/EmberCommon.h index 2eb6c1d..5673dc7 100644 --- a/Source/EmberCommon/EmberCommon.h +++ b/Source/EmberCommon/EmberCommon.h @@ -736,6 +736,38 @@ bool SearchVar(const Variation* var, const vector& stringVec, bool ma return ret; } +template +bool SearchVarWWO(const Variation* var, const vector& withVec, const vector& withoutVec) +{ + bool ret = false; + size_t i, j, k; + bool onegood = false; + auto cl = var->OpenCLFuncsString() + "\n" + var->OpenCLString(); + vector clsplits = Split(cl, '\n'); + + for (i = 0; i < clsplits.size(); i++) + { + for (j = 0; j < withVec.size(); j++) + { + if (clsplits[i].find(withVec[j]) != std::string::npos) + { + for (k = 0; k < withoutVec.size(); k++) + { + if (clsplits[i].find(withoutVec[k]) != std::string::npos) + { + return false; + } + } + + onegood = true; + } + } + } + + return onegood; + //return i == clsplits.size() && j == withVec.size() && k == withoutVec.size(); +} + /// /// Find all variations whose OpenCL string contains any of the search strings in stringVec. /// This is useful for finding variations with certain characteristics since it's not possible @@ -766,6 +798,23 @@ static vector*> FindVarsWith(const vector* return vec; } +template +static vector*> FindVarsWithWithout(const vector*>& vars, const vector& withVec, const vector& withoutVec) +{ + vector*> vec; + auto vl = VariationList::Instance(); + + for (auto& v : vars) + { + if (SearchVarWWO(v, withVec, withoutVec)) + { + vec.push_back(v); + } + } + + return vec; +} + /// /// Find all variations whose OpenCL string does not contain any of the search strings in stringVec. /// This is useful for finding variations without certain characteristics since it's not possible diff --git a/Source/EmberTester/EmberTester.cpp b/Source/EmberTester/EmberTester.cpp index d60203a..9a66dbc 100644 --- a/Source/EmberTester/EmberTester.cpp +++ b/Source/EmberTester/EmberTester.cpp @@ -1585,21 +1585,26 @@ void TestOperations() void TestArbitrary() { - vector stringVec; + vector stringVec, withoutVec; auto varList = VariationList::Instance(); auto& vars = varList->AllVars(); - stringVec.push_back(" = vIn.x - "); - stringVec.push_back(" = vIn.y - "); - stringVec.push_back("sqrt("); - stringVec.push_back("atan2("); - stringVec.push_back("sin("); - stringVec.push_back("cos("); + stringVec.push_back("if (!"); + withoutVec.push_back("="); + withoutVec.push_back("<"); + withoutVec.push_back(">"); + //stringVec.push_back(" = vIn.x - "); + //stringVec.push_back(" = vIn.y - "); + //stringVec.push_back("sqrt("); + //stringVec.push_back("atan2("); + //stringVec.push_back("sin("); + //stringVec.push_back("cos("); //stringVec.push_back("sincos("); - auto varVec = FindVarsWith(vars, stringVec, true, true); + //auto varVec = FindVarsWith(vars, stringVec, true, true); + auto varVec = FindVarsWithWithout(vars, stringVec, withoutVec); for (auto& it : varVec) { - cout << "Variation " << it->Name() << " contained the desired strings." << endl; + cout << "Variation " << it->Name() << " contained the desired w/wo strings." << endl; } } diff --git a/Source/Fractorium/Fractorium.cpp b/Source/Fractorium/Fractorium.cpp index ebf0c73..4d860da 100644 --- a/Source/Fractorium/Fractorium.cpp +++ b/Source/Fractorium/Fractorium.cpp @@ -404,10 +404,11 @@ bool Fractorium::eventFilter(QObject* o, QEvent* e) } else if (o == this) { + auto focusedctrlEdit = dynamic_cast(this->focusWidget()); auto focusedctrlSpin = dynamic_cast(this->focusWidget()); - auto focusedctrlDbSpin = dynamic_cast(this->focusWidget()); + auto focusedctrlDblSpin = dynamic_cast(this->focusWidget()); - if (!focusedctrlSpin && !focusedctrlDbSpin)//Must exclude these because otherwise, typing a minus key in any of the spinners will switch the xform. + if (!focusedctrlEdit && !focusedctrlSpin && !focusedctrlDblSpin)//Must exclude these because otherwise, typing a minus key in any of the spinners will switch the xform. { unsigned int index = combo->currentIndex();