Exemple #1
0
void check_sequences_defined_by(double result[2][10], Sequence::Type typeU, const char * definitionU, const char * conditionU1 = nullptr, const char * conditionU2 = nullptr, Sequence::Type typeV = Sequence::Type::Explicit, const char * definitionV = nullptr, const char * conditionV1 = nullptr, const char * conditionV2 = nullptr) {
  GlobalContext globalContext;
  SequenceStore store;
  SequenceContext sequenceContext(&globalContext, &store);

  Sequence * u = nullptr;
  Sequence * v = nullptr;
  if (definitionU) {
    u = store.addEmptyFunction();
    assert(u->name()[0] == 'u');
    u->setType(typeU);
    u->setContent(definitionU);
    if (conditionU1) {
      u->setFirstInitialConditionContent(conditionU1);
    }
    if (conditionU2) {
      u->setSecondInitialConditionContent(conditionU2);
    }
  }
  if (definitionV) {
    if (store.numberOfFunctions() == 0) {
      Sequence * tempU = store.addEmptyFunction();
      v = store.addEmptyFunction();
      store.removeFunction(tempU);
      v = store.functionAtIndex(0);
    } else {
      assert(store.numberOfFunctions() == 1);
      v = store.addEmptyFunction();
    }
    v->setType(typeV);
    v->setContent(definitionV);
    if (conditionV1) {
      v->setFirstInitialConditionContent(conditionV1);
    }
    if (conditionV2) {
      v->setSecondInitialConditionContent(conditionV2);
    }
  }
  for (int j = 0; j < 10; j++) {
    if (u && u->isDefined()) {
      double un = u->evaluateAtAbscissa((double)j, &sequenceContext);
      assert((std::isnan(un) && std::isnan(result[0][j])) || (un == result[0][j]));
    }
    if (v && v->isDefined()) {
      double vn = v->evaluateAtAbscissa((double)j, &sequenceContext);
      assert((std::isnan(vn) && std::isnan(result[1][j])) || (vn == result[1][j]));
    }
  }
}
Exemple #2
0
void GraphController::initCursorParameters() {
  double x = std::round((interactiveCurveViewRange()->xMin()+interactiveCurveViewRange()->xMax())/2.0);
  selectFunctionWithCursor(0);
  TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
  int functionIndex = 0;
  double y = 0;
  do {
    Sequence * firstFunction = m_sequenceStore->activeFunctionAtIndex(functionIndex++);
    y = firstFunction->evaluateAtAbscissa(x, myApp->localContext());
  } while (std::isnan(y) && functionIndex < m_sequenceStore->numberOfActiveFunctions());
  m_cursor->moveTo(x, y);
  m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
}
Exemple #3
0
bool GraphController::moveCursorHorizontally(int direction) {
  double xCursorPosition = std::round(m_cursor->x());
  if (direction < 0 && xCursorPosition <= 0) {
    return false;
  }
  /* The cursor moves by step of at minimum 1. If the windowRange is to large
   * compared to the resolution, the cursor takes bigger round step to cross
   * the window in approximatively resolution steps. */
  double step = std::ceil((interactiveCurveViewRange()->xMax()-interactiveCurveViewRange()->xMin())/m_view.resolution());
  step = step < 1.0 ? 1.0 : step;
  double x = direction > 0 ? xCursorPosition + step:
    xCursorPosition -  step;
  if (x < 0.0) {
    return false;
  }
  Sequence * s = m_sequenceStore->activeFunctionAtIndex(indexFunctionSelectedByCursor());
  TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
  double y = s->evaluateAtAbscissa(x, myApp->localContext());
  m_cursor->moveTo(x, y);
  m_graphRange->panToMakePointVisible(x, y, k_cursorTopMarginRatio, k_cursorRightMarginRatio, k_cursorBottomMarginRatio, k_cursorLeftMarginRatio);
  return true;
}