bool LuRatio(void) { bool ok = true; size_t n = 2; // number rows in A double ratio; // values for independent and dependent variables CPPAD_TEST_VECTOR<double> x(n*n), y(n*n+1); // pivot vectors CPPAD_TEST_VECTOR<size_t> ip(n), jp(n); // set x equal to the identity matrix x[0] = 1.; x[1] = 0; x[2] = 0.; x[3] = 1.; // create a fnction object corresponding to this value of x CppAD::ADFun<double> *FunPtr = NewFactor(n, x, ok, ip, jp); // use function object to factor matrix y = FunPtr->Forward(0, x); ratio = y[n*n]; ok &= (ratio == 1.); ok &= CheckLuFactor(n, x, y, ip, jp); // set x so that the pivot ratio will be infinite x[0] = 0. ; x[1] = 1.; x[2] = 1. ; x[3] = 0.; // try to use old function pointer to factor matrix y = FunPtr->Forward(0, x); ratio = y[n*n]; // check to see if we need to refactor matrix ok &= (ratio > 10.); if( ratio > 10. ) { delete FunPtr; // to avoid a memory leak FunPtr = NewFactor(n, x, ok, ip, jp); } // now we can use the function object to factor matrix y = FunPtr->Forward(0, x); ratio = y[n*n]; ok &= (ratio == 1.); ok &= CheckLuFactor(n, x, y, ip, jp); delete FunPtr; // avoid memory leak return ok; }
/** * @brief scrollingTime call each time when need handle scrolling. * @param x value from 0.0 to 1.0 */ void VMainGraphicsView::scrollingTime(qreal x) { Q_UNUSED(x); qreal factor = 1.0; if (_numScheduledScalings < 0) { verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5)); emit NewFactor(factor); } else { // if (verticalScrollBar()->value() > 0) // { verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5)); emit NewFactor(factor); // } } }
/** * @brief scalingTime call each time when need handle scaling. * @param x value from 0.0 to 1.0 */ void VMainGraphicsView::scalingTime(qreal x) { Q_UNUSED(x); const QPointF p0scene = mapToScene(mapFromGlobal(QCursor::pos())); qreal factor = 1.0 + static_cast<qreal>(_numScheduledScalings) / 50.0; scale(factor, factor); const QPointF p1mouse = mapFromScene(p0scene); const QPointF move = p1mouse - this->mapFromGlobal(QCursor::pos()); // The move horizontalScrollBar()->setValue(static_cast<qint32>(move.x()) + horizontalScrollBar()->value()); verticalScrollBar()->setValue(static_cast<qint32>(move.y()) + verticalScrollBar()->value()); VAbstractTool::NewSceneRect(this->scene(), this); emit NewFactor(factor); }
//--------------------------------------------------------------------------------------------------------------------- void VMainGraphicsView::ZoomOut() { scale(1.0/1.1, 1.0/1.1); VAbstractTool::NewSceneRect(this->scene(), this); emit NewFactor(1.0/1.1); }