diff --git a/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp b/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp index ab42a67..05dca08 100755 --- a/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp +++ b/Version_Max_07_05_2018_CMake/src/LinearFunctionBlock.cpp @@ -1,106 +1,106 @@ #include "LinearFunctionBlock.h" - -//#define PRINT +#include LinearFunctionBlock::LinearFunctionBlock() { #ifdef PRINT printf(" > Linear Function Block created\n"); #endif // PRINT } LinearFunctionBlock::LinearFunctionBlock(char* name) : Module(name) { #ifdef PRINT printf(" > %s (id:%u) created\n", name, id); #endif // PRINT } LinearFunctionBlock::~LinearFunctionBlock() { LinearFunction* cur_Linear_Function; unsigned int index_cur_Linear_Function; unsigned int size_vec_Linear_Functions = vLinearFunctions.size(); for(index_cur_Linear_Function = 0; index_cur_Linear_Function < size_vec_Linear_Functions; index_cur_Linear_Function++){ cur_Linear_Function = vLinearFunctions[index_cur_Linear_Function]; delete cur_Linear_Function; } vLinearFunctions.clear(); } //NOTE: for this time being, linear functions have to be filled beginning from lowest x value bool LinearFunctionBlock::addLinearFunction(LinearFunction *linearFunction) { if (vLinearFunctions.empty()) { //printf("empty\n"); if (!(linearFunction->getDomain()->lowerBoundaryExist())) { vLinearFunctions.push_back(linearFunction); #ifdef PRINT printf(" - added function\n"); #endif // PRINT return true; } } else { //printf("nicht empty\n"); if (vLinearFunctions.back()->getDomain()->upperBoundaryExist() && linearFunction->getDomain()->lowerBoundaryExist()) { //printf("last function ub = %f, new function lb = %f\n", lLinearFunctions.back()->getDomain()->getUpperBoundary(), linearFunction->getDomain()->getLowerBoundary()); if (vLinearFunctions.back()->getDomain()->getUpperBoundary() == linearFunction->getDomain()->getLowerBoundary()) { vLinearFunctions.push_back(linearFunction); #ifdef PRINT printf(" - added function\n"); #endif // PRINT return true; } } } printf(" - couldn't add function\n"); return false; } //NOTE: Specific Function for CAH Project (DATE18) void LinearFunctionBlock::changeFunctionBlockIncr(float newBoundary) { vLinearFunctions[1]->setDomain(true, (float)0, true, newBoundary); vLinearFunctions[1]->setKandD((float)0, (float)0, newBoundary, (float)1); vLinearFunctions[2]->setDomain(true, newBoundary, false); } void LinearFunctionBlock::changeFunctionBlockDecr(float newBoundary) { vLinearFunctions[1]->setDomain(true, (float)0, true, newBoundary); vLinearFunctions[1]->setKandD((float)0, (float)1, newBoundary, (float)0); vLinearFunctions[2]->setDomain(true, newBoundary, false); } //TODO: jump discontinuity -> user must have the probability to set the value there float LinearFunctionBlock::getY(float x) { for (auto &linearFunction : vLinearFunctions) { if (linearFunction->getDomain()->lowerBoundaryExist() && linearFunction->getDomain()->upperBoundaryExist()) { if (x >= linearFunction->getDomain()->getLowerBoundary() && x <= linearFunction->getDomain()->getUpperBoundary()) { return linearFunction->getY(x); } } else if (linearFunction->getDomain()->lowerBoundaryExist()) { if (x >= linearFunction->getDomain()->getLowerBoundary()) { return linearFunction->getY(x); } } else if (linearFunction->getDomain()->upperBoundaryExist()) { if (x <= linearFunction->getDomain()->getUpperBoundary()) { return linearFunction->getY(x); } } else { return linearFunction->getY(x); } } + //the next two lines should be deleted, but if you call the function getY you have to check for NaN! printf("DEFAULT!!!!!!!!!!!\n"); getchar(); - //TODO: default return value is maybe not the best - return 0; + + return std::numeric_limits::quiet_NaN(); } vector& LinearFunctionBlock::get_all_LinearFunctions() { return vLinearFunctions; }