/* MapLine::needsTexture * Returns a flag set of any parts of the line that require a texture *******************************************************************/ int MapLine::needsTexture() { // Check line is valid if (!frontSector()) return 0; // If line is 1-sided, it only needs front middle if (!backSector()) return TEX_FRONT_MIDDLE; // Get sector planes plane_t floor_front = frontSector()->getFloorPlane(); plane_t ceiling_front = frontSector()->getCeilingPlane(); plane_t floor_back = backSector()->getFloorPlane(); plane_t ceiling_back = backSector()->getCeilingPlane(); double front_height, back_height; int tex = 0; // Check the floor front_height = floor_front.height_at(x1(), y1()); back_height = floor_back.height_at(x1(), y1()); if (front_height - back_height > EPSILON) tex |= TEX_BACK_LOWER; if (back_height - front_height > EPSILON) tex |= TEX_FRONT_LOWER; front_height = floor_front.height_at(x2(), y2()); back_height = floor_back.height_at(x2(), y2()); if (front_height - back_height > EPSILON) tex |= TEX_BACK_LOWER; if (back_height - front_height > EPSILON) tex |= TEX_FRONT_LOWER; // Check the ceiling front_height = ceiling_front.height_at(x1(), y1()); back_height = ceiling_back.height_at(x1(), y1()); if (back_height - front_height > EPSILON) tex |= TEX_BACK_UPPER; if (front_height - back_height > EPSILON) tex |= TEX_FRONT_UPPER; front_height = ceiling_front.height_at(x2(), y2()); back_height = ceiling_back.height_at(x2(), y2()); if (back_height - front_height > EPSILON) tex |= TEX_BACK_UPPER; if (front_height - back_height > EPSILON) tex |= TEX_FRONT_UPPER; return tex; }
void Quad::set_range(double nx1, double nx2, double ny1, double ny2) { *x1() = nx1; *x2() = nx2; *y1() = ny1; *y2() = ny2; *x_mid() = ( *x1() + *x2() )*0.5f; *y_mid() = ( *y1() + *y2() )*0.5f; }
inline cv::Rect getBorder(const cv::Rect_<t > &original, cv::Rect_<t > & limited) { cv::Rect_<t > res; res.x = limited.x - original.x; res.y = limited.y - original.y; res.width = x2(original) - x2(limited); res.height = y2(original) - y2(limited); assert(res.x >= 0 && res.y >= 0 && res.width >= 0 && res.height >= 0); return res; }
bool SimpleRegion::intersects(SimpleRegion obstacle) { return ( ( (x1() <= obstacle.x1() && obstacle.x1() <= x2()) || (x1() <= obstacle.x2() && obstacle.x2() <= x2()) ) && ( (y1() <= obstacle.y1() && obstacle.y1() <= y2()) || (y1() <= obstacle.y2() && obstacle.y2() <= y2()) ) ); }
void Quad::split() { if(is_split()) return; quads[0][0] = new Quad(V); quads[0][1] = new Quad(V); quads[1][0] = new Quad(V); quads[1][1] = new Quad(V); quads[0][0]->set_range( *x1(), *x_mid(), *y1(), *y_mid() ); quads[0][1]->set_range( *x_mid(), *x2(), *y1(), *y_mid() ); quads[1][0]->set_range( *x1(), *x_mid(), *y_mid(), *y2() ); quads[1][1]->set_range( *x_mid(), *x2(), *y_mid(), *y2() ); }
void Terrain::split() { if(is_split()) return; quads[0][0] = new Terrain(V); quads[0][1] = new Terrain(V); quads[1][0] = new Terrain(V); quads[1][1] = new Terrain(V); quads[0][0]->set_range(*x1(), *x_mid(), *y1(), *y_mid()); quads[0][1]->set_range(*x_mid(), *x2(), *y1(), *y_mid()); quads[1][0]->set_range(*x1(), *x_mid(), *y_mid(), *y2()); quads[1][1]->set_range(*x_mid(), *x2(), *y_mid(), *y2()); }
/** * returns the spherical Bessel function of the second kind * needed for continuum states \param l = order of the function (orbital angular momentum) \param rho = independent variable (rho = k * r) */ double sphericalB::y(int l, double rho) { switch (l) { case 0: return y0(rho); case 1: return y1(rho); case 2: return y2(rho); case 3: return y3(rho); case 4: return y4(rho); case 5: return y5(rho); case 6: return y6(rho); case 7: return y7(rho); default: cout << "no l>6 programed in sphericalB" << endl; return 0.; } }
// Interpolation of natural splines static CubicSpline InterpolateCubicSplineFromCurvePoints(const CurvePoints& curve) { std::vector<float> y2(curve.size()); // second derivatives std::vector<float> u(curve.size()); y2[0] = 0; for (size_t i = 1; i < curve.size() - 1; ++i) { float sig = (curve[i].first - curve[i - 1].first) / (curve[i + 1].first - curve[i - 1].first); float p = sig * y2[i - 1] + 2.0f; y2[i] = (sig - 1.0f) / p; u[i] = (curve[i+1].second - curve[i].second)/(curve[i+1].first - curve[i].first) - (curve[i].second - curve[i-1].second)/(curve[i].first - curve[i-1].first); u[i] = (6.0f * u[i] / (curve[i+1].first - curve[i-1].first) - sig*u[i-1]) / p; } y2[curve.size() - 1] = 0; for (int i = (int)curve.size() - 2; i >= 0; --i) { y2[i] = y2[i] * y2[i + 1] + u[i]; } CubicSpline spline(curve, std::move(y2)); return spline; }
std::vector< std::vector<Real> > ElectroIonicModel::getJac (const std::vector<Real>& v, Real h) { std::vector< std::vector<Real> > J ( M_numberOfEquations, std::vector<Real> (M_numberOfEquations, 0.0) ); std::vector<Real> f1 (M_numberOfEquations, 0.0); std::vector<Real> f2 (M_numberOfEquations, 0.0); std::vector<Real> y1 (M_numberOfEquations, 0.0); std::vector<Real> y2 (M_numberOfEquations, 0.0); for (int i = 0; i < M_numberOfEquations; i++) { for (int j = 0; j < M_numberOfEquations; j++) { y1[j] = v[j] + ( (double) (i == j) ) * h; y2[j] = v[j] - ( (double) (i == j) ) * h; } this->computeRhs (y1, f1); f1[0] += M_appliedCurrent; this->computeRhs (y2, f2); f2[0] += M_appliedCurrent; for (int j = 0; j < M_numberOfEquations; j++) { J[j][i] = (f1[j] - f2[j]) / (2.0 * h); } } return J; }
void StringTest::testCompareShort() { cxxtools::String s(L"abcd"); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcd") , 0); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abc") , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcxyz") , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abd") , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abb") , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("ab") , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcd", 4) , 0); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcxyz", 3) , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abcxyz", 4) , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abd", 3) , -1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("abb", 3) , 1); CXXTOOLS_UNIT_ASSERT_EQUALS(s.compare("ab", 2) , 1); cxxtools::String x1(L"abc"); CXXTOOLS_UNIT_ASSERT(x1 == "abc"); cxxtools::String y1(L""); cxxtools::String y2(""); CXXTOOLS_UNIT_ASSERT(y1 == y2); CXXTOOLS_UNIT_ASSERT(y1 == ""); CXXTOOLS_UNIT_ASSERT(y2 == ""); }
void CompOutput::setWorkArea (const CompRect &workarea) { mWorkArea = workarea; if (workarea.x () < static_cast <int> (x1 ())) mWorkArea.setX (x1 ()); if (workarea.y () < static_cast <int> (y1 ())) mWorkArea.setY (y1 ()); if (workarea.x2 () > static_cast <int> (x2 ())) mWorkArea.setWidth (x2 () - mWorkArea.x ()); if (workarea.y2 () > static_cast <int> (y2 ())) mWorkArea.setHeight (y2 () - mWorkArea.y ()); }
void foo(const pair &x, const pair2 &x2) { pair y(x); pair2 y2(x2); pair2 y2m(static_cast<pair2&&>(y2)); y2 = x2; y2m = static_cast<pair2&&>(y2); }
void CompOutput::setWorkArea (const CompRect& workarea) { mWorkArea = workarea; if (workarea.x () < (int) x1 ()) mWorkArea.setX (x1 ()); if (workarea.y () < (int) y1 ()) mWorkArea.setY (y1 ()); if (workarea.x2 () > (int) x2 ()) mWorkArea.setWidth (x2 () - mWorkArea.x ()); if (workarea.y2 () > (int) y2 ()) mWorkArea.setHeight (y2 () - mWorkArea.y ()); }
void test_rat2( void ) { NUPrecRational x1(10.0), y1(10.0), x2(20.0), y2(20.0), y(15.0), c; double n,d; c = x1 + (y-y1)*(x2-x1)/(y2-y1); c.Dump(&n,&d); printf( "%f/%f\n", n, d ); }
line2 line2::interpolate(line2 const& l, double fraction) const { return line2( denormalize(fraction, x1(), l.x1()), denormalize(fraction, y1(), l.y1()), denormalize(fraction, x2(), l.x2()), denormalize(fraction, y2(), l.y2()) ); }
ExecStatus MultPlusDom<VA,VB,VC>::propagate(Space& home, const ModEventDelta& med) { if (VA::me(med) != ME_INT_DOM) { GECODE_ES_CHECK((prop_mult_plus_bnd<VA,VB,VC>(home,*this,x0,x1,x2))); return home.ES_FIX_PARTIAL(*this,VA::med(ME_INT_DOM)); } IntView y0(x0.varimp()), y1(x1.varimp()), y2(x2.varimp()); return prop_mult_dom<IntView>(home,*this,y0,y1,y2); }
variant rect::write() const { std::vector<variant> v; v.reserve(4); v.push_back(variant(x())); v.push_back(variant(y())); v.push_back(variant(x2()-1)); v.push_back(variant(y2()-1)); return variant(&v); }
dvector spline(const dvector &_x,const dvector&_y,double yp1,double ypn) { dvector& x=(dvector&) _x; dvector& y=(dvector&) _y; int orig_min=x.indexmin(); x.shift(1); y.shift(1); // need to check that x is monotone increasing; if ( x.indexmax() != y.indexmax() ) { cerr << " Incompatible bounds in input to spline" << endl; } int n=x.indexmax(); dvector y2(1,n); int i,k; double p,qn,sig,un; dvector u(1,n-1); if (yp1 > 0.99e30) { y2[1]=u[1]=0.0; } else { y2[1] = -0.5; u[1]=(3.0/(x[2]-x[1]))*((y[2]-y[1])/(x[2]-x[1])-yp1); } for (i=2;i<=n-1;i++) { sig=(x[i]-x[i-1])/(x[i+1]-x[i-1]); p=sig*y2[i-1]+2.0; y2[i]=(sig-1.0)/p; u[i]=(y[i+1]-y[i])/(x[i+1]-x[i]) - (y[i]-y[i-1])/(x[i]-x[i-1]); u[i]=(6.0*u[i]/(x[i+1]-x[i-1])-sig*u[i-1])/p; } if (ypn > 0.99e30) { qn=un=0.0; } else { qn=0.5; un=(3.0/(x[n]-x[n-1]))*(ypn-(y[n]-y[n-1])/(x[n]-x[n-1])); } y2[n]=(un-qn*u[n-1])/(qn*y2[n-1]+1.0); for (k=n-1;k>=1;k--) { y2[k]=y2[k]*y2[k+1]+u[k]; } x.shift(orig_min); y.shift(orig_min); y2.shift(orig_min); return y2; }
void TestMatrixExtras::test_mult_Hv() { size_t n = 10; Matrix x = MatrixFactory::MakeRandomMatrix(n, 1, 0.0, 1.0); Matrix A = MatrixFactory::MakeRandomMatrix(n, n, 0.0, 1.0, Matrix::MATRIX_SYMMETRIC); Matrix y = A*x; Matrix y2(n, 1); Matrix::mult(y2, 1.0, A, x, 0.0); _ASSERT_EQ(y2, y); }
void scrollable_widget_rep::scroll_event_hor (SI& x, SI& bef, SI& af) { abs_round (x); if ((x + x1() - ox) < ex1) x = ex1 - x1() + ox; if ((x + x2() - ox) > ex2) x = ex2 - x2() + ox; if (attached ()) { int dx= max (-w, min (w, x- scx)); if ((dx>-w) && (dx<w) && (dx!=0)) { win->translate (x1(), y1(), x2(), y2(), -dx, 0); } if (dx>0) this << emit_invalidate (x2()-ox-dx, y1()-oy, x2()-ox, y2()-oy); if (dx<0) this << emit_invalidate (x1()-ox, y1()-oy, x1()-ox-dx, y2()-oy); } scx = x; bef = ox- x1(); af = x2()- ox; a[0]->ox = ox- scx; }
CppAD::ADFun<Base>* generate_tape(Func f, vector<double> x_){ std::cout << "Generating tape\n"; int n=x_.size(); vector<AD<Base> > x(n); for(int i=0;i<n;i++)x[i]=AD<Base>(x_[i]); CppAD::Independent(x); vector<AD<Base> > y=f(x); vector<AD<Base> > y2(y.size()); for(int i=0;i<y.size();i++)y2[i]=y[i]; CppAD::ADFun<Base>* padf=new CppAD::ADFun<Base>(x,y2); return padf; }
int main() { // Note that if class X does not define a constructor then ther is no constructor initializer // (SgConstructorInitializer) built in the AST. X<int> x1; Y<int> functionPrototype(); Y<int> y1; Y<int> y2(1); return 0; }
/*! \file \brief To display non Fary drawings */ void DrawPolrec(QPainter *p,pigalePaint *paint) {TopologicalGraph G(paint->GCP); Prop1<tstring> title(G.Set(),PROP_TITRE); Prop1<Tpoint> pmin(G.Set(),PROP_POINT_MIN); Prop<Tpoint> p1(G.Set(tvertex()),PROP_DRAW_POINT_1); Prop<Tpoint> p2(G.Set(tvertex()),PROP_DRAW_POINT_2); Prop<double> x1(G.Set(tedge()),PROP_DRAW_DBLE_1 ); Prop<double> x2(G.Set(tedge()),PROP_DRAW_DBLE_2 ); Prop<double> y1(G.Set(tedge()),PROP_DRAW_DBLE_3 ); Prop<double> y2(G.Set(tedge()),PROP_DRAW_DBLE_4); Prop<double> y(G.Set(tedge()),PROP_DRAW_DBLE_5); Prop<short> ecolor(G.Set(tedge()),PROP_COLOR); Prop<short> vcolor(G.Set(tvertex()),PROP_COLOR); Prop<bool> isTree(G.Set(tedge()),PROP_ISTREE); Prop<int> elabel(G.Set(tedge()),PROP_LABEL); Prop<int> ewidth(G.Set(tedge()),PROP_WIDTH); bool drawTextEdges = (G.ne() < 100); QString stitle(~title()); if(drawTextEdges)paint->DrawText(p,pmin().x(),pmin().y(),stitle); // draw vertices for(tvertex v = 1;v <= G.nv();v++) {double dx = (p2[v].x() - p1[v].x()) ; double x = p1[v].x() ; double y = p1[v].y(); paint->DrawText(p,x,y, dx,1.,v,vcolor[v]); } // draw edges Tpoint e1,e2,e3,e4; for(tedge e = 1;e <= G.ne();e++) {if(isTree[e]) {e1 = Tpoint(x1[e],y1[e]); e2 = Tpoint(x1[e],y2[e]); paint->DrawSeg(p,e1,e2,ecolor[e],ewidth[e]); } else // cotree edges (x1,y1) -> (x1,y) -> (x2,y) -> (x2,y2) {e1 = Tpoint(x1[e],y1[e]); e2 = Tpoint(x1[e],y[e]); e3 = Tpoint(x2[e],y[e]); e4 = Tpoint(x2[e],y2[e]); paint->DrawSeg(p,e1,e2,ecolor[e],ewidth[e]); paint->DrawSeg(p,e2,e3,ecolor[e],ewidth[e]); paint->DrawSeg(p,e3,e4,ecolor[e],ewidth[e]); if(drawTextEdges) {QString label=QString("%1").arg(elabel[e]); // text is drawn at position of lower edge occu paint->DrawText(p,x1[e],y[e],label); } } } }
// ====================================================================== MultiVector Redistribute(const MultiVector& y, const int NumEquations) { StackPush(); if (y.GetMyLength() % NumEquations) ML_THROW("NumEquations does not divide MyLength()", -1); if (y.GetNumVectors() != 1) ML_THROW("Redistribute() works with single vectors only", -1); Space NewSpace(y.GetMyLength() / NumEquations); MultiVector y2(NewSpace, NumEquations); for (int i = 0 ; i < y2.GetMyLength() ; ++i) for (int j = 0 ; j < NumEquations ; ++j) y2(i, j) = y(j + NumEquations * i); StackPop(); return(y2); }
void TestExprDiff::apply_mul01() { Variable x,y; Function f(x,y,x,"f"); Variable x3,y3; Function g(x3,y3,y3,"g"); Variable x2("x"),y2("y"); Function h(x2,y2,f(x2,y2)*g(x2,y2)); Function dh(h,Function::DIFF); CPPUNIT_ASSERT(sameExpr(dh.expr(),"(y,x)")); // CPPUNIT_ASSERT(sameExpr(dh.expr(),"(((df(x,y)[0]*g(x,y))+(dg(x,y)[0]*f(x,y))),((df(x,y)[1]*g(x,y))+(dg(x,y)[1]*f(x,y))))")); }
int runOperatorTests(Epetra_Operator & A, bool verbose) { int ierr = 0; double residual; EPETRA_CHK_ERR(EpetraExt::OperatorToMatrixMarketFile("Test_A1.mm", A, "Official EpetraExt test operator", "This is the official EpetraExt test operator generated by the EpetraExt regression tests")); EPETRA_CHK_ERR(EpetraExt::OperatorToMatlabFile("Test_A1.dat", A)); A.OperatorRangeMap().Comm().Barrier(); A.OperatorRangeMap().Comm().Barrier(); Epetra_CrsMatrix * A1; Epetra_CrsMatrix * A2; EPETRA_CHK_ERR(EpetraExt::MatrixMarketFileToCrsMatrix("Test_A1.mm", A.OperatorRangeMap(), A1)); EPETRA_CHK_ERR(EpetraExt::MatlabFileToCrsMatrix("Test_A1.dat", A.OperatorRangeMap().Comm(), A2)); residual = A.NormInf(); double rAInf = residual; if (verbose) std::cout << "Inf Norm of Operator A = " << residual << std::endl; residual = A1->NormInf(); double rA1Inf = residual; if (verbose) std::cout << "Inf Norm of Matrix A1 = " << residual << std::endl; ierr += checkValues(rA1Inf,rAInf,"Inf Norm of A", verbose); Epetra_Vector x(A.OperatorDomainMap()); x.Random(); Epetra_Vector y1(A.OperatorRangeMap()); Epetra_Vector y2(A.OperatorRangeMap()); Epetra_Vector y3(A.OperatorRangeMap()); A.Apply(x,y1); A1->Multiply(false, x, y2); A2->Multiply(false, x, y3); y1.Norm2(&residual); double rAx1 = residual; if (verbose) std::cout << "Norm of A*x = " << residual << std::endl; y2.Norm2(&residual); double rAx2 = residual; if (verbose) std::cout << "Norm of A1*x = " << residual << std::endl; ierr += checkValues(rAx1,rAx2,"Norm of A1*x", verbose); y3.Norm2(&residual); double rAx3 = residual; if (verbose) std::cout << "Norm of A2*x = " << residual << std::endl; ierr += checkValues(rAx1,rAx3,"Norm of A2*x", verbose); delete A1; delete A2; return(ierr); }
extern "C" SEXP mypnorm(SEXP xx) { Rcpp::NumericVector x(xx); int n = x.size(); Rcpp::NumericVector y1(n), y2(n), y3(n); for (int i=0; i<n; i++) { y1[i] = ::Rf_pnorm5(x[i], 0.0, 1.0, 1, 0); y2[i] = R::pnorm(x[i], 0.0, 1.0, 1, 0); } y3 = Rcpp::pnorm(x); return Rcpp::DataFrame::create(Rcpp::Named("Rf_") = y1, Rcpp::Named("R") = y2, Rcpp::Named("sugar") = y3); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->graphicsView->setScene(&scene); QPoint x1(0,100); QPoint x2(0,-100); QLine x(x1,x2); scene.addLine(x); QPoint y1(100,0); QPoint y2(-100,0); QLine y(y1,y2); scene.addLine(y); }
void fwd_test() { test::test_type1<int> x1(3); test::test_type1<std::string> y1("Black"); test::test_type2<int> x2(25, 16); test::test_type2<std::string> y2("White", "Green"); std::vector<int> empty; std::vector<std::string> empty2; test::test_type3<int> x3(empty.begin(), empty.end()); test::test_type3<std::string> y3(empty2.begin(), empty2.end()); // Prevent gcc warnings: unused(x1); unused(x2); unused(x3); unused(y1); unused(y2); unused(y3); }
/* MapLine::dirTabPoint * Calculates and returns the end point of the 'direction tab' for * the line (used as a front side indicator for 2d map display) *******************************************************************/ fpoint2_t MapLine::dirTabPoint(double tablen) { // Calculate midpoint fpoint2_t mid(x1() + ((x2() - x1()) * 0.5), y1() + ((y2() - y1()) * 0.5)); // Calculate tab length if (tablen == 0) { tablen = getLength() * 0.1; if (tablen > 16) tablen = 16; if (tablen < 2) tablen = 2; } // Calculate tab endpoint if (front_vec.x == 0 && front_vec.y == 0) frontVector(); return fpoint2_t(mid.x - front_vec.x*tablen, mid.y - front_vec.y*tablen); }