void pB() { switch (ch) { case 'b': pb(); pB(); break; case 'c': pc(); pC(); break; default : error(); } }
void pA() { switch (ch) { case 'a': pa(); pA(); break; case 'b': pb(); pB(); break; default: error(); } }
template<class K> Object intersection_unoptimized(const Rectangle_2<K> &a, const Rectangle_2<K> &b) { typedef K::Point_2 Point_2; typedef std::vector<Point_2> Container; typedef Polygon_2<K, Container> Polygon_2; typedef Polygon_with_holes_2<K,Container> Polygon_with_holes_2; if(a.is_degenerate() || b.is_degenerate()) return Object(); Container pa(a.center()ontainer(true)), pb(b.center()ontainer(true)); std::vector<Polygon_with_holes_2> res; Polygon_2 polya(pa.begin(),pa.end()), polyb(pb.begin(),pb.end()); intersection(polya,polyb,std::back_inserter(res)); return (res.empty())?Object():make_object(res.back().outer_boundary().container()); }
//----------------------------------------------------------------------- void RenderTarget::writeContentsToFile(const String& filename) { PixelFormat pf = suggestPixelFormat(); uchar *data = OGRE_ALLOC_T(uchar, mWidth * mHeight * PixelUtil::getNumElemBytes(pf), MEMCATEGORY_RENDERSYS); PixelBox pb(mWidth, mHeight, 1, pf, data); copyContentsToMemory(pb, pb); Image().loadDynamicImage(data, mWidth, mHeight, 1, pf, false, 1, 0).save(filename); OGRE_FREE(data, MEMCATEGORY_RENDERSYS); }
void pushswap(t_struct **la, t_struct **lb) { int min; while (*la) { min = find_min(*la); while ((*la)->val != min) ra(la); pb(lb, la); } while (*lb) pa(la, lb); }
void splay(int x){ int s = 1,i = x,y; tmp[1] = i; while(!isroot(i)) tmp[++s] = i = f[i]; while(s) pb(tmp[s--]); while(!isroot(x)){ y = f[x]; if (!isroot(y)){ if ((son[f[y]][0] == y) ^ (son[y][0] == x)) rotate(x); else rotate(y); } rotate(x); } up(x); }
/// the Poisson bracket of two polynomials in this algebra Polynomial ClassicalLieAlgebra::poissonBracket(const Polynomial& polA, const Polynomial& polB) const { if (!(hasElt(polA) && hasElt(polB))) throw LieAlgebraSizeMismatchError(); assert(polA.hasSameNumVars(polB)); Polynomial pb(zero()); Polynomial pbA(zero()); Polynomial pbB(zero()); for (Index d = 0; d < dof_; ++d) { pbA = (polA.diff(iQ(d)) * polB.diff(iP(d))); pbB = (polA.diff(iP(d)) * polB.diff(iQ(d))); pb += (pbA - pbB); } return pb; }
void Programmer::WriteInfoPage(const uint8_t chipID[5]) { // first parse the chipID // do an erase all // we must do this for the chip to allow an InfoPage erase EraseAll(); ProgressBar pb("Writing IP"); // send the erase page command req_erase_page_t erasePage; erasePage.page_num = 0; erasePage.length = sizeof erasePage; erasePage.request = reqErasePageIP; reqSetChecksum(erasePage); SendRequest(erasePage); pb.Refresh(0.3); // validate the response resp_simple_t resp; ReadResponse1(resp); if (resp.response != req2resp(reqErasePageIP)) throw std::string("Unexpected response from programmer while erase page in WriteInfoPage()"); // now init and send the new InfoPage req_write_flash_t writeFlash; writeFlash.length = sizeof writeFlash; writeFlash.address = 0; writeFlash.request = reqWriteInfoPage; memset(writeFlash.data, 0xff, sizeof writeFlash.data); memcpy(writeFlash.data + 0x0B, chipID, CHIP_ID_BYTES); reqSetChecksum(writeFlash); SendRequest(writeFlash); pb.Refresh(0.6); // validate ReadResponse1(resp); if (resp.response != req2resp(reqWriteInfoPage)) throw std::string("Unexpected response from programmer while writing page in WriteInfoPage()"); pb.Refresh(1); }
Usart3::Usart3( uint32_t baudRate_, uint16_t wordLength_, uint16_t parity_, uint16_t stopBits_, uint16_t flowControl_, uint16_t mode_) : UsartPeripheral(USART3,DMA1_Channel2,DMA1_Channel3,2,USART3_IRQn) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE); GpioPort pb(GPIOB); pb.initialise(GPIO_Speed_50MHz,GPIO_Mode_AF_PP,GPIO_Pin_TX); // TX pb.initialise(GPIO_Speed_50MHz,GPIO_Mode_IN_FLOATING,GPIO_Pin_RX); // RX initialisePeripheral(baudRate_,wordLength_,parity_,stopBits_,flowControl_,mode_); }
// bool publishFrame(Ogre::RenderWindow * render_object, const std::string frame_id) bool publishFrame(Ogre::RenderTexture * render_object, const std::string frame_id) { if (pub_.getTopic() == "") { return false; } if (frame_id == "") { return false; } // RenderTarget::writeContentsToFile() used as example int height = render_object->getHeight(); int width = render_object->getWidth(); // the results of pixel format have to be used to determine // image.encoding Ogre::PixelFormat pf = render_object->suggestPixelFormat(); uint pixelsize = Ogre::PixelUtil::getNumElemBytes(pf); uint datasize = width * height * pixelsize; // 1.05 multiplier is to avoid crash when the window is resized. // There should be a better solution. uchar *data = OGRE_ALLOC_T(uchar, datasize * 1.05, Ogre::MEMCATEGORY_RENDERSYS); Ogre::PixelBox pb(width, height, 1, pf, data); render_object->copyContentsToMemory(pb, Ogre::RenderTarget::FB_AUTO); sensor_msgs::Image image; image.header.stamp = ros::Time::now(); image.header.seq = image_id_++; image.header.frame_id = frame_id; image.height = height; image.width = width; image.step = pixelsize * width; if (pixelsize == 3) image.encoding = sensor_msgs::image_encodings::RGB8; // would break if pf changes else if (pixelsize == 4) image.encoding = sensor_msgs::image_encodings::RGBA8; // would break if pf changes else { ROS_ERROR_STREAM("unknown pixe format " << pixelsize << " " << pf); } image.is_bigendian = (OGRE_ENDIAN == OGRE_ENDIAN_BIG); image.data.resize(datasize); memcpy(&image.data[0], data, datasize); pub_.publish(image); OGRE_FREE(data, Ogre::MEMCATEGORY_RENDERSYS); }
void ft_algo(t_tab **op, t_swap **ba, t_swap **bb, unsigned int i) { if (i / 8) ft_algo(op, ba, bb, (i / 8)); if (i % 8 < 3) op[i % 8](ba); else if (i % 8 == 3 && *bb) pb(bb, ba); else if (i % 8 == 4 && *ba) pa(ba, bb); else if (i % 8 == 5) op[3](bb); else if (i % 8 == 6) op[4](bb); else if (i % 8 == 7) op[5](bb); }
void Partition::FindPartitionFace(SFace* Fa, SFace* Fb) { //比较两个面是否有相邻curve_edge, 如果有那么就判断两面是否是分割面 否则continue for(auto i = Fa->faceBounds_.begin(); i != Fa->faceBounds_.end(); i++) { for(auto ia = ((*i)->edgeLoop_).begin(); ia != ((*i)->edgeLoop_).end(); ia++) { size_t curveFaceAId = (*ia)->edgeCurveId_; for(auto j = Fb->faceBounds_.begin(); j != Fb->faceBounds_.end(); j++) { for(auto jb = ((*j)->edgeLoop_).begin(); jb != ((*j)->edgeLoop_).end(); jb++) { size_t curveFaceBId = (*jb)->edgeCurveId_; orientationFaceA oriA; oriA.advancedFaceOri = Fa->adFaceSameSense_; oriA.boundsOri = (*i)->boundsOri_; oriA.orientedEdgeOri = (*ia)->orientedEdgeOri_; oriA.edgeCurveOri = (*ia)->edgeCurvesameSense_; char* curveName = (*ia)->curveName_; EdgeCurveVertex curveA, curveB; curveA.cartesianStart = (*ia)->edgeStart_; curveA.cartesianEnd = (*ia)->edgeEnd_; curveA.cartesianStart = (*jb)->edgeStart_; curveA.cartesianEnd = (*jb)->edgeEnd_; CPoint3D pointA = ((CIRCLE*)(*ia))->position_.point;//圆心 if(curveFaceBId == curveFaceAId) { //判断是否是分割面 bool isPartitionFace = JudgeIntersection(Fa, Fb, curveName, oriA, curveA, curveB, pointA); if(isPartitionFace) { pair<size_t, SFace*> pa(Fa->entityID_, Fa); pair<size_t, SFace*> pb(Fb->entityID_, Fb); partitionFaceList_.insert(pa); partitionFaceList_.insert(pb); } else continue; } } } } } }
virtual void run() { python_bridge pb( "processor", "processor" ); for( int i=0; i<N; i++ ) { // check input event const eva::event& e = _inp->next(); assert( e.get_header()._id == i ); pb.exec( e.get_raw(), eva::event::size, next().get_raw(), eva::event::size ); // produce output event //next().get_header()._id = i; commit(); } }
ATOOLS::Vec4D_Vector Combine (const Cluster_Amplitude &l,int i,int j,int k,const ATOOLS::Flavour &mo) { Mass_Selector *p_ms=ampl.MS(); if (i>j) std::swap<int>(i,j); Vec4D_Vector after(ampl.Legs().size()-1); double mb2(0.0); if (i<2) { mb2=ampl.Leg(1-i)->Mom().Abs2(); double mfb2(p_ms->Mass2(ampl.Leg(1-i)->Flav())); if ((mfb2==0.0 && IsZero(mb2,1.0e-6)) || IsEqual(mb2,mfb2,1.0e-6)) mb2=mfb2; } Vec4D pi(ampl.Leg(i)->Mom()), pj(ampl.Leg(j)->Mom()); Vec4D pk(ampl.Leg(k)->Mom()), pb(i<2?ampl.Leg(1-i)->Mom():Vec4D()); double mi2=pi.Abs2(), mfi2=p_ms->Mass2(ampl.Leg(i)->Flav()); double mj2=pj.Abs2(), mfj2=p_ms->Mass2(ampl.Leg(j)->Flav()); double mk2=pk.Abs2(), mfk2=p_ms->Mass2(ampl.Leg(k)->Flav()); if ((mfi2==0.0 && IsZero(mi2,1.0e-6)) || IsEqual(mi2,mfi2,1.0e-6)) mi2=mfi2; if ((mfj2==0.0 && IsZero(mj2,1.0e-6)) || IsEqual(mj2,mfj2,1.0e-6)) mj2=mfj2; if ((mfk2==0.0 && IsZero(mk2,1.0e-6)) || IsEqual(mk2,mfk2,1.0e-6)) mk2=mfk2; double mij2=p_ms->Mass2(mo); Kin_Args lt; if (i>1) { if (k>1) lt=ClusterFFDipole(mi2,mj2,mij2,mk2,pi,pj,pk,2); else lt=ClusterFIDipole(mi2,mj2,mij2,mk2,pi,pj,-pk,2); if ((k==0 && lt.m_pk[3]<0.0) || (k==1 && lt.m_pk[3]>0.0) || lt.m_pk[0]<0.0) return Vec4D_Vector(); } else { if (k>1) { lt=ClusterIFDipole(mi2,mj2,mij2,mk2,mb2,-pi,pj,pk,-pb,2); } else lt=ClusterIIDipole(mi2,mj2,mij2,mk2,-pi,pj,-pk,2); if ((i==0 && lt.m_pi[3]<0.0) || (i==1 && lt.m_pi[3]>0.0) || lt.m_pi[0]<0.0) return Vec4D_Vector(); } if (lt.m_stat<0) return Vec4D_Vector(); for (size_t l(0), m(0);m<ampl.Legs().size();++m) { if (m==(size_t)j) continue; if (m==(size_t)i) after[l]=i>1?lt.m_pi:-lt.m_pi; else if (m==(size_t)k) after[l]=k>1?lt.m_pk:-lt.m_pk; else after[l]=lt.m_lam*ampl.Leg(m)->Mom(); ++l; } return after; }
void tri_simple(t_lst *l, t_options *options, int *tri) { while ((l->a)->length > 0) { more_effective_moving(l, find_min(&l->a), options); pb(l); if (options->v == 1) show_piles(l, "pb"); } while ((l->b)->length > 0) { pa(l); if (options->v == 1) show_piles(l, "pa"); } *tri = 2; }
void maxsmt_solver_base::commit_assignment() { expr_ref tmp(m); expr_ref_vector fmls(m); rational k(0), cost(0); vector<rational> weights; for (soft const& s : m_soft) { if (s.is_true()) { k += s.weight; } else { cost += s.weight; } weights.push_back(s.weight); fmls.push_back(s.s); } pb_util pb(m); tmp = pb.mk_ge(weights.size(), weights.c_ptr(), fmls.c_ptr(), k); TRACE("opt", tout << "cost: " << cost << "\n" << tmp << "\n";);
int main(int , char **) { std::cout << "Tests on gfa library" << std::endl; std::cout << "Create Point3D and assign to other Point3D" << std::endl; GFA::Point3D pa(1,2,3); GFA::Point3D pb(4,5,6); std::cout << pa.x << " " << pa.y << " " << pa.z << std::endl; std::cout << pb.x << " " << pb.y << " " << pb.z << std::endl; pa = pb; std::cout << pa.x << " " << pa.y << " " << pa.z << std::endl; GFA::Point3D pd(pb); std::cout << pd.x << " " << pd.y << " " << pd.z << std::endl; // This should give an error //GFA::Point3D pe(pc); return 0; }
int MediaMemoryAllocator<memorytype>::GetMediaBuffer(sp<IMediaBuffer>& Sample) { AutolockEx _l(m_lock); if(m_availablememory.size()) { Sample.clear(); sp<IMediaBufferAllocator> p(this); sp<IMemory> pb((m_availablememory.begin())->get()); Sample = new CMediaBuffer(p,pb); m_availablememory.erase(m_availablememory.begin()); return OK; } LOGI("[VTMAL]MediaMemoryAllocator<%d> GetMediaBuffer fail,m_samplenums=%d,m_samplesize=%d",\ memorytype,m_samplenums,m_samplesize); return NO_MEMORY; }
unsigned LAVar::setBound( const Real & v, bool upper ) { unsigned i = getBoundByValue( v, upper ); if( i != 0 ) return i; Delta * bound = NULL; Delta::deltaType bound_type = ( upper ? Delta::UPPER : Delta::LOWER ); bound = new Delta( v ); assert( bound ); LAVarBound pb( bound, NULL, ( bound_type == Delta::UPPER ), false ); addBoundAndUpdateSorting( pb ); return getBoundByValue( v, upper ); }
void IcoCreatorView::on_button_save() { CL_SaveFileDialog dlg(this); dlg.add_filter("ICO files", "*.ico", true); dlg.add_filter("All files", "*.*"); dlg.set_initial_directory(CL_System::get_exe_path()); if(dlg.show()) { CL_String filename = dlg.get_filename(); try { CL_IconSet icon_set; int count = 0; for(int i = 0; i < 11; ++i) { if(lineedit_selected_file[i]->get_text().empty() == false) { CL_PixelBuffer pb(lineedit_selected_file[i]->get_text()); icon_set.add_image(pb); count++; } } CL_DataBuffer databuffer = icon_set.create_win32_icon(); CL_File ico_file(filename, CL_File::create_always, CL_File::access_write); ico_file.write(databuffer.get_data(), databuffer.get_size()); ico_file.close(); label_result->set_text(cl_format("Saved %1 images into ico file: %2", count, filename)); } catch(CL_Exception error) { label_result->set_text(cl_format("Save error: %1", error.message)); } } }
BOOL CCarlaLanguage::open(LPCTSTR lpszPathName) { CString sPath(lpszPathName); // this isn't needed since the calling methods make sure it is here if(!theApp.askUserToFindFileIfNotFound(sPath, CLangModelsDoc::getRegFileTypeID())) return FALSE; CSimpleProgressBar pb(_T("")); pb.SetTextEx(_T("Loading"), getName(), _T(" Lang File...")); USES_CONVERSION_U8; SFMFile *pFile = new SFMFile(T2CA(sPath), getCommentChar()); if(!pFile->ensureOpen(_T("Language Document"))) return FALSE; m_mfs.m_sCtrlFilesDirectory = getDirectory(sPath); // rename? if(::_tcsicmp(m_mfs.m_sCtrlFilesDirectory.Right(14), _T("Control Files\\"))) { int len = m_mfs.m_sCtrlFilesDirectory.GetLength(); CString sOldDirName = m_mfs.m_sCtrlFilesDirectory.Left(len-1); CString sNewDirName = m_mfs.m_sCtrlFilesDirectory.Left(1+len-_tcslen(_T("Files\\"))) + CONTROL_FOLDER_SUFFIX; if(-1 == _taccess(sNewDirName, 00)) // directory not found { CString s; s.Format(_T("This version of CarlaStudio uses a new name for the folder that contains control files.\n\nThe folder named %s will now be renamed to %s"), (LPCTSTR)sOldDirName, (LPCTSTR)sNewDirName); AfxMessageBox(s, MB_ICONINFORMATION ); if(0 == _taccess(m_mfs.m_sCtrlFilesDirectory, 00)) // is the dir of the old name there? { // rename it TRY { CFile::Rename( sOldDirName, sNewDirName ); } CATCH( CFileException, e ) { ::checkForFileError(m_mfs.m_sCtrlFilesDirectory); }
virtual std::vector<csce::point<T>> compute_hull(std::vector<csce::point<T>>& points) { if(points.size() <= 3){ return points; } std::size_t index = this->pivot_index(points); if(index != 0){ std::swap(points[0], points[index]); } //sort the points by angle around the pivot point (points[0]) std::sort(points.begin() + 1, points.end(), [&points](csce::point<T>& a, csce::point<T>& b) { csce::vector2d<T> pa(points[0], a); csce::vector2d<T> pb(points[0], b); return pa.ccw(pb); }); std::vector<csce::point<T>> s; s.reserve(points.size() + 1); s.push_back(points[points.size() - 1]); s.push_back(points[0]); s.push_back(points[1]); int x=2; while(x < points.size()){ std::size_t y = s.size() - 1; csce::vector2d<T> a(s[y-1], s[y]); csce::vector2d<T> b(s[y-1], points[x]); if(a.ccw(b)){ s.push_back(points[x++]); } else { s.pop_back(); } } if(s.front() == s.back()){ s.pop_back(); //the polygon is closed, so remove the last element to remove the duplicate point } return s; }
void big_pile_algo(void) { unsigned bigger_index; unsigned size; size = pile_size(g_pilea); while (g_pilea) { bigger_index = position_of_higher(g_pilea); if (bigger_index > size / 2) while (bigger_index++ < size) rra(); else while (bigger_index-- > 0) ra(); pb(); size--; } while (g_pileb) pa(); }
void Programmer::EraseAll() { ProgressBar pb("Erase all"); // send ERASE_ALL request req_simple_t req; req.length = sizeof req; req.request = reqEraseAll; reqSetChecksum(req); SendRequest(req); pb.Refresh(0.5); // validate response resp_simple_t resp; ReadResponse1(resp); if (resp.response != req2resp(reqEraseAll)) throw std::string("Unexpected response from programmer in EraseAll()"); pb.Refresh(1); }
void Programmer::DisableReadback(const int region) { ProgressBar pb("Disabling"); req_simple_t req; req.length = sizeof req; req.request = region == DISABLE_MB ? reqDisReadMainBlock : reqDisReadInfoPage; reqSetChecksum(req); SendRequest(req); pb.Refresh(0.5); // validate resp_simple_t resp; ReadResponse1(resp); if (resp.response != req2resp(req.request)) throw std::string("Unexpected response from programmer while disabling readback DisableReadback()"); pb.Refresh(1); }
void helix::generate(){ //float radius = 200; for (int i = 0; i < 200; i++){ float pct = i / 200.0; float r = 100 + 500 * pct; float x = r * cos( pct * TWO_PI * 2 ); float y = r * sin( pct * TWO_PI * 2 ); float z = pct * 900; ofPoint pa(x,y, z); helix0.addVertex( ofPoint(x,y,z) ); x = r * cos( pct * TWO_PI * 2 + PI ); y = r * sin( pct * TWO_PI * 2 + PI); ofPoint pb(x,y,z); if (i % 3 == 0){ line l; l.a = pa; l.b = pb; lines.push_back(l); } helix1.addVertex( ofPoint(x,y, z) ); } }
void Debugger::process() { assert(false && "Needs rewriting"); #if 0 ExecutionPaths paths; std::ofstream logfile; logfile.open(LogFile.c_str()); PathBuilder pb(&m_parser); m_parser.parse(m_fileName); pb.enumeratePaths(paths); PathBuilder::printPaths(paths, std::cout); ExecutionPaths::iterator pit; unsigned pathNum = 0; for(pit = paths.begin(); pit != paths.end(); ++pit) { if (PathId != -1) { if (pathNum != (unsigned)PathId) { continue; } } std::cout << "Analyzing path " << pathNum << '\n'; ModuleCache mc(&pb); //MemoryDebugger md(&m_binaries, &mc, &pb, logfile); //md.lookForValue(MemoryValue); ExecutionDebugger ed(&m_binaries, &mc, &pb, logfile); pb.processPath(*pit); ++pathNum; } #endif }
void Programmer::WriteMainBlock(const std::string& hexfilename) { FlashMemory flash(flashSize); flash.LoadHex(hexfilename); // read the HEX file printf("Loaded %i bytes from HEX file %s\n\n", flash.GetFlashLastByte() + 1, hexfilename.c_str()); EraseAll(); // erase the chip's MainBlock // do the flash writing ProgressBar pb("Writing MB"); // start writing the flash int address = 0; while (address < flash.GetFlashSize()) { const uint8_t* pChunk = flash.GetFlash() + address; // Check all the bytes of the chunk to see if we have any non-0xff bytes. This is // good because we don't want to waste time sending an empty block for programming. int bytes = 0, c; for (c = 0; c < PROG_CHUNK_SIZE; c++) { if (pChunk[c] != 0xff) bytes = c + 1; } // do we have a non-empty block? if (bytes) WriteChunk(false, flash, address); address += PROG_CHUNK_SIZE; // update the progress bar pb.Refresh(address / double(flash.GetFlashSize())); } }
int checker_calc(t_e *e) { char *line; while (get_next_line(0, &line) != 0) { if (ft_strcmp("sa", line) == 0) sa(e->l_a); else if (ft_strcmp("sb", line) == 0) sb(e->l_b); else if (ft_strcmp("ss", line) == 0) ss(e->l_a, e->l_b); else if (ft_strcmp("ra", line) == 0) ra(e->l_a); else if (ft_strcmp("rb", line) == 0) rb(e->l_b); else if (ft_strcmp("rr", line) == 0) rr(e->l_a, e->l_b); else if (ft_strcmp("rra", line) == 0) rra(e->l_a); else if (ft_strcmp("rrb", line) == 0) rrb(e->l_b); else if (ft_strcmp("rrr", line) == 0) rrr(e->l_a, e->l_b); else if (ft_strcmp("pa", line) == 0) pa(e->l_a, e->l_b); else if (ft_strcmp("pb", line) == 0) pb(e->l_a, e->l_b); else { ft_putendl_fd("Error", 2); ft_memdel((void **)&line); return (0); } ft_memdel((void **)&line); } return (1); }
void RFC_Pane_base::init() { // Determine whether the pane has quadratic elements if ( !_base->is_structured()) { _base->elements( _elem_conns); _elem_offsets.reserve( _elem_conns.size()); for ( std::vector<const COM::Connectivity*>::const_iterator it = _elem_conns.begin(); it != _elem_conns.end(); ++it) { _elem_offsets.push_back( (*it)->index_offset()); const int ne = (*it)->size_of_edges_pe(); const int nn = (*it)->size_of_nodes_pe(); if ( nn > ne) _quadratic = true; } } MAP::Pane_boundary pb( _base); pb.determine_border_nodes( _is_border, _is_isolated); for ( int i=0, n=_is_border.size(); i<n; ++i) { _n_border += _is_border[i]; _n_isolated += _is_isolated[i]; } }