static char *line_east(int x, int max, int y, t_zaap *z) { int i; char flag; char *tmp; char *ret; i = 0; flag = 1; ret = ft_strnew(0); while (i < max) { tmp = see_spot(z->map[y][x], max); if (flag) flag = 0; ft_strjoin_free(&ret, tmp); free(tmp); i++; y = vd(y + 1, z->y); ft_strjoin_free(&ret, ", "); } if (flag) ft_strjoin_free(&ret, ", "); return (ret); }
vec3 TerrainNoise::getNormal(float x, float y, float eps) const { float ha = getHauteur2(x,y); float g = getHauteur2(x-eps,y), d = getHauteur2(x+eps,y), b = getHauteur2(x,y+eps), h = getHauteur2(x,y-eps); vec3 vg(-eps, 0, g-ha), vd(eps, 0, d-ha), vb(0, eps, b-ha), vh(0, -eps, h-ha); float distg = length(vg), distd = length(vd), distb = length(vb), disth = length(vh); vec3 v1 = cross(vg,vh), v2 = cross(vh,vd), v3 = cross(vd,vb), v4 = cross(vb,vg); v1 = normalize(v1); v2 = normalize(v2); v3 = normalize(v3); v4 = normalize(v4); vec3 normale = v1*distg*disth + v2*disth*distd + v3*distd*distb + v4*distb*distg; return normalize(normale); }
double ConstExpressionColumn::DoGetValueDouble(const MIIterator& mit) { assert(ATI::IsNumericType(TypeName())); double val = 0; if (last_val.IsNull()) return NULL_VALUE_D; if (ATI::IsIntegerType(TypeName())) val = (double) last_val.Get64(); else if(ATI::IsFixedNumericType(TypeName())) val = ((double) last_val.Get64()) / PowOfTen(ct.GetScale()); else if(ATI::IsRealType(TypeName())) { union { double d; _int64 i;} u; u.i = last_val.Get64(); val = u.d; } else if(ATI::IsDateTimeType(TypeName())) { RCDateTime vd(last_val.Get64(), TypeName()); // 274886765314048 -> 2000-01-01 _int64 vd_conv = 0; vd.ToInt64(vd_conv); // 2000-01-01 -> 20000101 val = (double)vd_conv; } else if(ATI::IsStringType(TypeName())) { char *vs = last_val.GetStringCopy(); if(vs) val = atof(vs); delete [] vs; } else assert(0 && "conversion to double not implemented"); return val; }
void GameOverState::load_gfx(CL_GraphicContext& gc, std::string skin) { unload_gfx(); // Getting skins resources CL_VirtualFileSystem vfs(skin, true); CL_VirtualDirectory vd(vfs, "./"); CL_ResourceManager gfx("menu_gameover.xml",vd); _dialog_gameover = CL_Sprite(gc, "menu_gameover/dialog_gameover", &gfx); _dialog_highscore = CL_Sprite(gc, "menu_gameover/dialog_highscore", &gfx); _score1_x = CL_Integer_to_int("menu_gameover/score1_left", &gfx); _score1_y = CL_Integer_to_int("menu_gameover/score1_top", &gfx); _score2_x = CL_Integer_to_int("menu_gameover/score2_left", &gfx); _score2_y = CL_Integer_to_int("menu_gameover/score2_top", &gfx); _quit_choice_item.set_gfx(gc, gfx, "menu_gameover/new_game_question/yes/unselected", "menu_gameover/new_game_question/yes/selected", "menu_gameover/new_game_question/no/unselected", "menu_gameover/new_game_question/no/selected"); _quit_choice_item.set_x( CL_Integer_to_int("menu_gameover/new_game_question/yes/left", &gfx)); _quit_choice_item.set_x2( CL_Integer_to_int("menu_gameover/new_game_question/no/left", &gfx)); _quit_choice_item.set_y( CL_Integer_to_int("menu_gameover/new_game_question/yes/top", &gfx)); _quit_choice_item.set_y2( CL_Integer_to_int("menu_gameover/new_game_question/no/top", &gfx)); }
QVector<QVector3D> SurfaceItem::vertices() const { QSize size = surface()->size(); qreal w = (m_height * size.width()) / size.height(); qreal h = m_height; QVector3D pos = m_pos + m_normal * m_depthOffset; QVector2D center(pos.x(), pos.z()); QVector3D perp = QVector3D::crossProduct(QVector3D(0, 1, 0), m_normal); QVector2D delta = w * QVector2D(perp.x(), perp.z()).normalized() / 2; qreal scale = qMin(1.0, m_time.elapsed() * 0.002); qreal top = m_pos.y() + h * 0.5 * scale; qreal bottom = m_pos.y() - h * 0.5 * scale; QVector2D left = center - delta * scale; QVector2D right = center + delta * scale; QVector3D va(left.x(), top, left.y()); QVector3D vb(right.x(), top, right.y()); QVector3D vc(right.x(), bottom, right.y()); QVector3D vd(left.x(), bottom, left.y()); QVector<QVector3D> result; result << va << vb << vc << vd; return result; }
int Font::write(unsigned int dx, const std::string& text, float r, float g, float b, float a) { FontEntry& e = entries[dx]; if(e.num_vertices) { vertices.erase(vertices.begin()+e.start_dx, vertices.begin()+(e.start_dx+e.num_vertices)); } e.col[0] = r, e.col[1] = g, e.col[2] = b, e.col[3] = a; // Create vertices e.w = 0; e.start_dx = vertices.size(); float x = 0; float y = 0; for(int i = 0; i < text.size(); ++i) { char c = text[i]; stbtt_aligned_quad q; stbtt_GetBakedQuad(cdata, w, h, c-32, &x, &y, &q, 1); CharVertex va(q.x0, q.y1, q.s0, q.t1, e.col); CharVertex vb(q.x1, q.y1, q.s1, q.t1, e.col); CharVertex vc(q.x1, q.y0, q.s1, q.t0, e.col); CharVertex vd(q.x0, q.y0, q.s0, q.t0, e.col); CHAR_TRI(va, vb, vc); CHAR_TRI(va, vc, vd); if(q.x1 > e.w) { e.w = q.x1; } } e.needs_update = true; e.num_vertices = vertices.size() - e.start_dx; flagChanged(); return e.num_vertices; }
TEST_F(VecTest, ArithmeticOps) { vec4 v0(1,2,3,4); vec4 v1(10,20,30,40); vec4 v2(v0 + v1); EXPECT_EQ(v2.x, 11); EXPECT_EQ(v2.y, 22); EXPECT_EQ(v2.z, 33); EXPECT_EQ(v2.w, 44); v0 = v1 * 2; EXPECT_EQ(v0.x, 20); EXPECT_EQ(v0.y, 40); EXPECT_EQ(v0.z, 60); EXPECT_EQ(v0.w, 80); v0 = 2 * v1; EXPECT_EQ(v0.x, 20); EXPECT_EQ(v0.y, 40); EXPECT_EQ(v0.z, 60); EXPECT_EQ(v0.w, 80); tvec4<double> vd(2); v0 = v1 * vd; EXPECT_EQ(v0.x, 20); EXPECT_EQ(v0.y, 40); EXPECT_EQ(v0.z, 60); EXPECT_EQ(v0.w, 80); }
void Camera::follow(sf::Sprite& sp, float d) { Vector2D vd(0, d); vd.rotate( sp.getRotation()); setRotation(sp.getRotation()); setCenter( sp.getPosition() + vd); }
void GenerateRecursiveDelegation::operator()(Model::SymbolItem* node) { World::Environment::iterator it = globalSystem.env.find(node); if (it != globalSystem.env.end()) { // this creates the method signature using just the first of // possibly multiple rules with the same name. Model::EvolveItem *e = (*it); Model::VariableDeclarationItem *decl = e->mDeclarations; GenerateVariableDeclaration<false, true> vd(out); while(decl) { vd(decl); decl = decl->mNext; } } }
void OptimizerVariableData::unassign( VariableID vid ) { assert( isAssigned( vid ) ); VarData & vd( get( vid ) ); vd.v->unassign(); setUnassigned( vid ); }
int main() { /// INPUT START freopen("input.txt", "r", stdin); freopen("debug.txt", "w", stderr); int n; int m; //cout << "input conditions:\n"; cin >> n >> m; vvd a(m, vd(n)); vd b(m); vc type(m); vc sign(n); for (int i = 0; i < m; ++i) { cin >> type[i]; for (int j = 0; j < n; ++j) cin >> a[i][j]; cin >> b[i]; } for (int i = 0; i < n; ++i) { cin >> sign[i]; } vd c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; } /// INPUT END vvd dual_a; vd dual_b; vd dual_c; getCanonicalMatrix(a, b, c, sign, type); printTask(a, b, c); getDualProblem(a, b, c, dual_a, dual_b, dual_c); printTask(dual_a, dual_b, dual_c, "dual_task.txt"); cout << "Simplex\n"; printResult(linearProgramming::simplex(a, b, c), sign); cout << "\nAll vertexes\n"; printResult(linearProgramming::allVertexesCheck(a, b, c), sign); cout << "\nDual problem simplex\n"; printResult(linearProgramming::simplex(dual_a, dual_b, dual_c), sign, false); return 0; }
Skin::Skin(std::string filename, CL_GraphicContext& gc) { _filename = filename; _element = 3; // We load the logo sprite in the gfx ressources file CL_VirtualFileSystem vfs(filename, true); CL_VirtualDirectory vd(vfs, "./"); CL_ResourceManager gfx("general.xml", vd); _logo = CL_Image(gc, "logo", &gfx); }
void Interface :: onMouseDown(){ vd().clickray = vd().ray; mouse.click = mouse.pos; mouse.isDown = 1; mouse.newClick = 1; //tdx = tdy = 0; // //Setting a State? // if (mMode & Mode::Transform){ // disable( Mode::Rotate | Mode::Grab | Mode::Scale | Mode::Transform ); //Stay in Edit Mode // } // // //Selecting a State? // if (mMode & Mode::Select){ // //graph().clickTest( glv.mouse.xRel(), scene().height() - glv.mouse.yRel() ); // //break; // } }
/** * Methode permettant de valider un document * (redirige vers la page de recherche) */ void NewDocumentWindow::validate(){ int ret = QMessageBox::question(this,trUtf8("Valider le document ?"),trUtf8("La validation d'un document empeche toutes modification ultérieure.<br/>Voulez-vous vraiment valider le document?"),QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes){ save(); Document d(idDocument); ValidDocument vd(d); vd.save(); QStatusBar *statBar = parent->statusBar(); statBar->showMessage(trUtf8("Informations du document sauvegardé et valider"), 4000); parent->setCentralWidget(new SearchWindow(parent)); } }
void OptimizerVariableData::assign( VariableID vid, const Numeric & val ) { VarData & vd( get( vid ) ); bool wasUnassigned( isUnassigned( vid ) ); if ( wasUnassigned ) { vd.assignmentIndex = m_numAssigned; setAssigned( vid ); } // assign the variable vd.v->assign( val ); }
char *see_east(int x, int y, t_zaap *z, int lvl) { char *tmp; char *tmp2; char *keep; int max; max = 1; tmp2 = ft_strnew(0); while (lvl >= 0) { tmp = line_east(x, max, y, z); keep = ft_strjoin(tmp2, tmp); free(tmp); free(tmp2); tmp2 = keep; lvl--; y = vd(y - 1, z->y); x = vd(x + 1, z->x); max += 2; } return (tmp2); }
EvtComplex EvtMassAmp::amplitude(const EvtPoint1D& p) const { // Modified vertex double m = p.value(); // keep things from crashing.. if ( m< (_vd.mA()+_vd.mB()) ) return EvtComplex(0.,0.); EvtTwoBodyKine vd(_vd.mA(),_vd.mB(),m); // Compute mass-dependent width for relativistic propagator EvtPropBreitWignerRel bw(_prop.m0(),_prop.g0()*_vd.widthFactor(vd)); EvtComplex amp = bw.evaluate(m); // Birth vertex factors if(_useBirthFact) { assert(_vb); if ( (m+_vb->mB()) < _vb->mAB() ) { EvtTwoBodyKine vb(m,_vb->mB(),_vb->mAB()); amp *= _vb->phaseSpaceFactor(vb,EvtTwoBodyKine::AB); amp *= sqrt((vb.p() / _vb->pD())); if(_useBirthFactFF) { assert(_vb); amp *= _vb->formFactor(vb); } } else{ if ( _vb->L() != 0 ) amp=0.; } } // Decay vertex factors if(_useDeathFact) { amp *= _vd.phaseSpaceFactor(vd,EvtTwoBodyKine::AB); amp *= sqrt((vd.p() / _vd.pD())); } if(_useDeathFactFF) amp *= _vd.formFactor(vd); return amp; }
static void TestView() { typedef Simd::View<Simd::Allocator> View; View vs(6, 6, View::Bgra32); View vd(6, 6, View::Gray8); Simd::Convert(vs, vd); View sv; sv = vs; #ifdef SIMD_OPENCV_ENABLE cv::Mat cm; sv = cm; cm = sv; #endif }
ProbabilityDistribution* GaussianProcess::prediction(const vectord &query) { const double kq = computeSelfCorrelation(query); const vectord kn = computeCrossCorrelation(query); vectord vd(kn); inplace_solve(mL,vd,ublas::lower_tag()); double basisPred = mMean.muTimesFeat(query); double yPred = basisPred + ublas::inner_prod(vd,mAlphaV); double sPred = sqrt(mSigma*(kq - ublas::inner_prod(vd,vd))); d_->setMeanAndStd(yPred,sPred); return d_; }
template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType) { typedef Matrix<float, SizeAtCompileType, SizeAtCompileType> Mat_f; typedef Matrix<double, SizeAtCompileType, SizeAtCompileType> Mat_d; typedef Matrix<std::complex<float>, SizeAtCompileType, SizeAtCompileType> Mat_cf; typedef Matrix<std::complex<double>, SizeAtCompileType, SizeAtCompileType> Mat_cd; typedef Matrix<float, SizeAtCompileType, 1> Vec_f; typedef Matrix<double, SizeAtCompileType, 1> Vec_d; typedef Matrix<std::complex<float>, SizeAtCompileType, 1> Vec_cf; typedef Matrix<std::complex<double>, SizeAtCompileType, 1> Vec_cd; Mat_f mf(size,size); Mat_d md(size,size); Mat_cf mcf(size,size); Mat_cd mcd(size,size); Vec_f vf(size,1); Vec_d vd(size,1); Vec_cf vcf(size,1); Vec_cd vcd(size,1); mf+mf; VERIFY_RAISES_ASSERT(mf+md); VERIFY_RAISES_ASSERT(mf+mcf); VERIFY_RAISES_ASSERT(vf=vd); VERIFY_RAISES_ASSERT(vf+=vd); VERIFY_RAISES_ASSERT(mcd=md); mf*mf; md*mcd; mcd*md; mf*vcf; mcf*vf; mcf *= mf; vcd = md*vcd; vcf = mcf*vf; #if 0 // these are know generating hard build errors in eigen3 VERIFY_RAISES_ASSERT(mf*md); VERIFY_RAISES_ASSERT(mcf*mcd); VERIFY_RAISES_ASSERT(mcf*vcd); VERIFY_RAISES_ASSERT(vcf = mf*vf); vf.eigen2_dot(vf); VERIFY_RAISES_ASSERT(vd.eigen2_dot(vf)); VERIFY_RAISES_ASSERT(vcf.eigen2_dot(vf)); // yeah eventually we should allow this but i'm too lazy to make that change now in Dot.h // especially as that might be rewritten as cwise product .sum() which would make that automatic. #endif }
TEST_F(VecTest, ArithmeticFunc) { vec3 east(1, 0, 0); vec3 north(0, 1, 0); vec3 up( cross(east, north) ); EXPECT_EQ(up, vec3(0,0,1)); EXPECT_EQ(dot(east, north), 0); EXPECT_EQ(length(east), 1); EXPECT_EQ(distance(east, north), sqrtf(2)); vec3 v0(1,2,3); vec3 vn(normalize(v0)); EXPECT_FLOAT_EQ(1, length(vn)); EXPECT_FLOAT_EQ(length(v0), dot(v0, vn)); tvec3<double> vd(east); EXPECT_EQ(length(vd), 1); }
void generate_cpp_variant( const std::string& filename, std::ostream& os, Dependency& dependency, const typeset_type& types, const atomset_type& atoms, const Value& v ) { std::string headername = filename; for( std::string::iterator i = headername.begin() ; i != headername.end() ; ++i ) { if( !std::isalpha( *i ) ) { *i = '_'; } else { *i = std::toupper( *i ); } } os << "#ifndef " << headername << "\n"; os << "#define " << headername << "\n\n"; os << "#include <vector>\n" << "#include <boost/variant.hpp>\n\n"; os << "////////////////////////////////////////////////////////////////\n" << "// forward declarations\n"; ForwardDeclarator fd( os ); boost::apply_visitor( fd, v.data ); os << std::endl; os << "////////////////////////////////////////////////////////////////\n" << "// variant declarations\n"; VariantDeclarator vd( os ); boost::apply_visitor( vd, v.data ); os << std::endl; os << "////////////////////////////////////////////////////////////////\n" << "// struct declarations\n"; StructDeclarator::declarations_type declarations; StructDeclarator sd( declarations ); boost::apply_visitor( sd, v.data ); std::vector< Dependency::vertex_type > c; boost::topological_sort( dependency.g, std::back_inserter( c ) ); for( std::vector< Dependency::vertex_type >::const_iterator i = c.begin() ; i != c.end() ; ++i ) { os << declarations[ dependency.r[*i] ]; } os << "#endif // " << headername << "\n"; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector<cvf::Vec3f> RivWellFracturePartMgr::transformToFractureDisplayCoords(const std::vector<cvf::Vec3f>& coordinatesVector, cvf::Mat4d m, const caf::DisplayCoordTransform& displayCoordTransform) { std::vector<cvf::Vec3f> polygonInDisplayCoords; polygonInDisplayCoords.reserve(coordinatesVector.size()); for (const cvf::Vec3f& v : coordinatesVector) { cvf::Vec3d vd(v); vd.transformPoint(m); cvf::Vec3d displayCoordsDouble = displayCoordTransform.transformToDisplayCoord(vd); polygonInDisplayCoords.push_back(cvf::Vec3f(displayCoordsDouble)); } return polygonInDisplayCoords; }
// --------------------------------------------------------------------------- /// Takes an array with markers and keeps only markers inside of the bounded region. // --------------------------------------------------------------------------- static int box_filter (marker_t *p, int N, box_t *b) { for (marker_t *end = p + N ; p < end ; ++p) { vec3d_t diff = vd_sub (vd (p->x, p->y, p->z), b->center); // Distance between particle and center. if (fabs (vd_dot (b->dir1, diff)) > 1 || // Removes particles outside of the box. fabs (vd_dot (b->dir2, diff)) > 1 || fabs (vd_dot (b->dir3, diff)) > 1) { *p = *(--end); // Replaces deleted particles by untested one. --p; // Unrolls counter to test the new marker. --N; } } return N; }
int main(int argc, char ** argv) { bool running = true; ModelDriver md(&running); ViewDriver vd(&md); ControllerDriver cd(&running, &md, &vd); if (argc != 5) { md.setSelectedWindow(FIRSTWINDOW); while (running) { md.updateFirstRun(); cd.getInputFirstRun(); vd.drawFirstRun(); usleep(DELAY); } return 0; } md.setUsername(argv[1]); md.setPassword(argv[2]); md.setHost(argv[3]); md.setPort(atoi(argv[4])); while (running) { md.update(); cd.getInput(); vd.draw(); usleep(DELAY); } if (strcmp(md.selectedRoom, "")) { char response[MAX_RESPONSE]; char leaveRoom[100]; sprintf(leaveRoom, "%s leaves the room.", md.selectedRoom); md.sendCommand("SEND-MESSAGE", leaveRoom, response); md.sendCommand("LEAVE-ROOM", md.selectedRoom, response); } return 0; }
void getDualProblem(const vvd& a, vd& b, vd& c, vvd& dual_a, vd& dual_b, vd& dual_c) { for (auto x : b) { dual_c.push_back(-x); } for (auto x : c) { dual_b.push_back(-x); } dual_a.assign(a[0].size(), vd()); for (size_t i = 0; i < a.size(); ++i) { for (size_t j = 0; j < a[i].size(); ++j) { dual_a[j].push_back(-a[i][j]); } } }
TEST_F(VecTest, Constructors) { vec4 v0; EXPECT_EQ(v0.x, 0); EXPECT_EQ(v0.y, 0); EXPECT_EQ(v0.z, 0); EXPECT_EQ(v0.w, 0); vec4 v1(1); EXPECT_EQ(v1.x, 1); EXPECT_EQ(v1.y, 1); EXPECT_EQ(v1.z, 1); EXPECT_EQ(v1.w, 1); vec4 v2(1,2,3,4); EXPECT_EQ(v2.x, 1); EXPECT_EQ(v2.y, 2); EXPECT_EQ(v2.z, 3); EXPECT_EQ(v2.w, 4); vec4 v3(v2); EXPECT_EQ(v3.x, 1); EXPECT_EQ(v3.y, 2); EXPECT_EQ(v3.z, 3); EXPECT_EQ(v3.w, 4); vec4 v4(v3.xyz, 42); EXPECT_EQ(v4.x, 1); EXPECT_EQ(v4.y, 2); EXPECT_EQ(v4.z, 3); EXPECT_EQ(v4.w, 42); vec4 v5(vec3(v2.xy, 42), 24); EXPECT_EQ(v5.x, 1); EXPECT_EQ(v5.y, 2); EXPECT_EQ(v5.z, 42); EXPECT_EQ(v5.w, 24); tvec4<double> vd(2); EXPECT_EQ(vd.x, 2); EXPECT_EQ(vd.y, 2); EXPECT_EQ(vd.z, 2); EXPECT_EQ(vd.w, 2); }
FrameDB *FrameDB::load_from_file(const string& filename) { ifstream vd(filename.c_str()); if (vd.fail()) { return NULL; } auto_ptr<FrameDB> db(new FrameDB()); // if we found the viewer data file build up the map. string line; while (getline(vd, line)) { if (line.find("=>") != string::npos) { db->add_alias(line); } else { db->add_info(line); } } return db.release(); }
int VideoPOS_Transfer::recvMessageSlot(RMessage *msg) { if( 1 == msg->msgType ) { spPOSData pd(new pi::POS_Data); pd->fromStream(msg->data); pushPOS_Data(pd); } else if ( 2 == msg->msgType ) { spVideoData vd(new VideoData); vd->fromStream(msg->data); pushVideoData(vd); } else if( 9 == msg->msgType ) { dbg_pt("received stop command!"); exit(0); } // free the message delete msg; return 0; }
void VoxelSceneNode::RemoveBrush(irr::core::vector3df Position) { float radius = 6.f; double len; double value; double dx,dy,dz; for(int x = (int)Position.X - (int) radius; x <= (int)Position.X + (int)radius; x++) { for(int y = (int)Position.Y - (int) radius; y <= (int)Position.Y + (int)radius; y++) { for(int z = (int)Position.Z - (int) radius; z <= (int)Position.Z + (int)radius; z++) { dx = x - Position.X; dy = y - Position.Y; dz = z - Position.Z; len = sqrt( (double) dx * (double) dx + (double) dy * (double) dy + (double) dz * (double) dz ); value = (radius - len)/radius; if (value < 0) value = 0; if (value > 1) value = 1; VoxelData vd(irr::core::vector3d<int>(x,y,z), value, 1); //printf("Changing point (%i,%i,%i), %f\n", x,y,z, value); UpdateVoxel(vd, true); } } } dirty = true; }