void PICAPI ps_path_arc_to(ps_path* path, float rx, float ry, float a, ps_bool large, ps_bool cw, const ps_point* ep) { if (!picasso::is_valid_system_device()) { global_status = STATUS_DEVICE_ERROR; return; } if (!path || !ep || rx <= 0.0 || ry <= 0.0) { global_status = STATUS_INVALID_ARGUMENT; return; } scalar x1 = path->path.last_x(); scalar y1 = path->path.last_y(); picasso::bezier_arc_svg arc(x1, y1, FLT_TO_SCALAR(rx), FLT_TO_SCALAR(ry), FLT_TO_SCALAR(a), (large ? true : false), (cw ? true : false), FLT_TO_SCALAR(ep->x), FLT_TO_SCALAR(ep->y)); picasso::conv_curve cr(arc); if (picasso::_is_closed_path(path->path)) path->path.concat_path(cr, 0); else path->path.join_path(cr, 0); global_status = STATUS_SUCCEED; }
void BackgroundRow::paintEvent(QPaintEvent *e) { Painter p(this); bool radial = false; float64 radialOpacity = 0; if (_radial.animating()) { _radial.step(getms()); radial = _radial.animating(); radialOpacity = _radial.opacity(); } if (radial) { auto backThumb = App::main() ? App::main()->newBackgroundThumb() : ImagePtr(); if (backThumb->isNull()) { p.drawPixmap(0, 0, _background); } else { const QPixmap &pix = App::main()->newBackgroundThumb()->pixBlurred(st::settingsBackgroundSize); p.drawPixmap(0, 0, st::settingsBackgroundSize, st::settingsBackgroundSize, pix, 0, (pix.height() - st::settingsBackgroundSize) / 2, st::settingsBackgroundSize, st::settingsBackgroundSize); } auto outer = radialRect(); QRect inner(QPoint(outer.x() + (outer.width() - st::radialSize.width()) / 2, outer.y() + (outer.height() - st::radialSize.height()) / 2), st::radialSize); p.setPen(Qt::NoPen); p.setBrush(st::black); p.setOpacity(radialOpacity * st::radialBgOpacity); p.setRenderHint(QPainter::HighQualityAntialiasing); p.drawEllipse(inner); p.setRenderHint(QPainter::HighQualityAntialiasing, false); p.setOpacity(1); QRect arc(inner.marginsRemoved(QMargins(st::radialLine, st::radialLine, st::radialLine, st::radialLine))); _radial.draw(p, arc, st::radialLine, st::white); } else { p.drawPixmap(0, 0, _background); } }
void EJPath::arcTo(float x1, float y1, float x2, float y2, float radius) { // Lifted from http://code.google.com/p/fxcanvas/ // I have no idea what this code is doing, but it seems to work. // get untransformed currentPos EJVector2 cp = EJVector2ApplyTransform(currentPos, CGAffineTransformInvert(transform)); float a1 = cp.y - y1; float b1 = cp.x - x1; float a2 = y2 - y1; float b2 = x2 - x1; float mm = fabsf(a1 * b2 - b1 * a2); if( mm < 1.0e-8 || radius == 0 ) { lineTo(x1, y1); } else { float dd = a1 * a1 + b1 * b1; float cc = a2 * a2 + b2 * b2; float tt = a1 * a2 + b1 * b2; float k1 = radius * sqrtf(dd) / mm; float k2 = radius * sqrtf(cc) / mm; float j1 = k1 * tt / dd; float j2 = k2 * tt / cc; float cx = k1 * b2 + k2 * b1; float cy = k1 * a2 + k2 * a1; float px = b1 * (k2 + j1); float py = a1 * (k2 + j1); float qx = b2 * (k1 + j2); float qy = a2 * (k1 + j2); float startAngle = atan2f(py - cy, px - cx); float endAngle = atan2f(qy - cy, qx - cx); arc(cx + x1, cy + y1, radius, startAngle, endAngle, (b1 * a2 > b2 * a1)); } }
bool ToolTip::Load( const u8* balloonAshData, u32 balloonAshSize ) { DELETE( obj ); DELETE( layout ); DELETE( brlan ); tbox = NULL; loaded = false; if( !balloonAshData || !balloonAshSize ) { return false; } U8Archive arc( balloonAshData, balloonAshSize ); if( !( layout = LoadLayout( arc, "my_IplTopBalloon_a" ) ) ) { return false; } if( !(tbox = layout->FindTextbox( "T_Balloon" ) ) ) { return false; } if( !(brlan = LoadAnimation( arc, "my_IplTopBalloon_a_balloonInOut" ) ) ) { return false; } //tbox->SetText( NULL ); obj = new Object; obj->AddAnimation( brlan ); obj->BindPane( layout->FindPane( "RootPane" )); obj->SetAnimation( "my_IplTopBalloon_a_balloonInOut", 0, -1, -1, true, true ); obj->Start(); loaded = true; return true; }
void loading() { int i,j,x,y; setbkcolor(6); x=getmaxx()/2; y=getmaxy()/2; for(j=30;j<200;j++) { delay(10); setcolor(j/20); arc(x,y,0,180,j-10); } settextstyle(3,0,6); outtextxy(150,250,"!..DOGDE IT..!"); settextstyle(4,0,4); outtextxy(250,340,"LOADING"); for(i=100; i<600; i++) { bar(i,380,i,400); delay(10); } }
void M2MFstAligner::_conditional_max( bool y_given_x ){ /* Compute the conditional distribution, P(Y|X) using the WFST paradigm. This is bassed on the approach from Shu and Hetherington 2002. It is assumed that all WFSTs and operations use the Log semiring. Given: FST1 = P(X,Y) Compute: FST2 = P(X) := Map_inv(Det(RmEps(Proj_i(FST1)))) FST3 = P(Y|X) := Compose(FST2,FST1) Proj_i: project on input labels RmEps: epsilon removal Det: determinize Map_inv: invert weights Notes: An analogous process may be used to compute P(X|Y). In this case one would project on OUTPUT labels - Proj_o, and reverse the composition order to Compose(FST1,FST2). Future work: What we are doing here in terms of *generating* the JOINT fst each time is really just a dumb hack. We *should* encode the model in an FST and encode the individual lattices, rather than doing the hacky manual label encoding that we currently rely on. */ //Joint distribution that we start with VectorFst<LogArc>* joint = new VectorFst<LogArc>(); SymbolTable* misyms = new SymbolTable("misyms"); SymbolTable* mosyms = new SymbolTable("mosyms"); joint->AddState(); joint->AddState(); joint->SetStart(0); joint->SetFinal(1,LogArc::Weight::One()); map<LogArc::Label,LogWeight>::iterator it; for( it=prev_alignment_model.begin(); it != prev_alignment_model.end(); it++ ){ string isym = isyms->Find((*it).first); vector<string> io = tokenize_utf8_string( &isym, &s1s2_sep ); LogArc arc( misyms->AddSymbol(io[0]), mosyms->AddSymbol(io[1]), (*it).second, 1 ); joint->AddArc( 0, arc ); } //VectorFst<LogArc>* joint = new VectorFst<LogArc>(); //Push<LogArc,REWEIGHT_TO_FINAL>(*_joint, joint, kPushWeights); //joint->SetFinal(1,LogWeight::One()); joint->Write("m2mjoint.fst"); //BEGIN COMPUTE MARGINAL P(X) VectorFst<LogArc>* dmarg; if( y_given_x ) dmarg = new VectorFst<LogArc>(ProjectFst<LogArc>(*joint, PROJECT_INPUT)); else dmarg = new VectorFst<LogArc>(ProjectFst<LogArc>(*joint, PROJECT_OUTPUT)); RmEpsilon(dmarg); VectorFst<LogArc>* marg = new VectorFst<LogArc>(); Determinize(*dmarg, marg); ArcMap(marg, InvertWeightMapper<LogArc>()); if( y_given_x ) ArcSort(marg, OLabelCompare<LogArc>()); else ArcSort(marg, ILabelCompare<LogArc>()); //END COMPUTE MARGINAL P(X) marg->Write("marg.fst"); //CONDITIONAL P(Y|X) VectorFst<LogArc>* cond = new VectorFst<LogArc>(); if( y_given_x ) Compose(*marg, *joint, cond); else Compose(*joint, *marg, cond); //cond now contains the conditional distribution P(Y|X) cond->Write("cond.fst"); //Now update the model with the new values for( MutableArcIterator<VectorFst<LogArc> > aiter(cond, 0); !aiter.Done(); aiter.Next() ){ LogArc arc = aiter.Value(); string lab = misyms->Find(arc.ilabel)+"}"+mosyms->Find(arc.olabel); int labi = isyms->Find(lab); alignment_model[labi] = arc.weight; prev_alignment_model[labi] = LogWeight::Zero(); } delete joint, marg, cond, dmarg; delete misyms, mosyms; return; }
void CPsfRarArchive::ReadFileContents(const char* fileName, void* buffer, unsigned int bufferLength) { Archive* arc(ConvertArchive(m_archive)); if(!arc->IsOpened()) { throw std::runtime_error("Archive isn't opened."); } std::string fixedFileName(fileName); boost::replace_all(fixedFileName, "/", "\\"); arc->Seek(0, SEEK_SET); ComprDataIO dataIo; dataIo.Init(); Unpack unpack(&dataIo); while(arc->ReadHeader() > 0) { if(arc->ShortBlock.HeaderType == HEAD_FILE) { if(!arc->IsArcDir()) { bool isGoodFile = !stricmp(fixedFileName.c_str(), string_cast<std::string>(arc->FileHead.FileName).c_str()); dataIo.SetFiles(arc, NULL); dataIo.SetPackedSizeToRead(arc->FileHead.PackSize); dataIo.CurUnpRead = 0; dataIo.CurUnpWrite = 0; dataIo.UnpHash.Init(arc->FileHead.FileHash.Type, 1); dataIo.PackedDataHash.Init(arc->FileHead.FileHash.Type, 1); dataIo.SetTestMode(!isGoodFile); if(isGoodFile) { dataIo.SetUnpackToMemory(reinterpret_cast<byte*>(buffer), bufferLength); } unpack.Init(arc->FileHead.WinSize, arc->FileHead.Solid); unpack.SetDestSize(arc->FileHead.UnpSize); if(arc->FileHead.Method == 0x30) { std::vector<byte> unstoreBuffer; unstoreBuffer.resize(0x10000); uint toReadSize = arc->FileHead.UnpSize; while(1) { uint code = dataIo.UnpRead(&unstoreBuffer[0], unstoreBuffer.size()); if(code == 0 || code == -1) break; code = code < toReadSize ? code : toReadSize; dataIo.UnpWrite(&unstoreBuffer[0], code); if(toReadSize >= 0) { toReadSize -= code; } } } else { unpack.DoUnpack(arc->FileHead.UnpVer, arc->FileHead.Solid); } if(!dataIo.UnpHash.Cmp(&arc->FileHead.FileHash, arc->FileHead.UseHashKey ? arc->FileHead.HashKey : nullptr)) { throw std::runtime_error("CRC check error."); } if(isGoodFile) { return; } } } arc->SeekToNext(); } throw std::runtime_error("Couldn't read file from archive."); }
//---------------------------------------------------------- void ofPath::circle(float x, float y, float z, float radius){ arc(x,y,z,radius,radius,0,360); }
//---------------------------------------------------------- void ofPath::rectRounded(float x, float y, float z, float w, float h, float topLeftRadius, float topRightRadius, float bottomRightRadius, float bottomLeftRadius){ // since we support w / h < 0, canonicalize the rectangle for easier drawing if(w < 0.0f) { x += w; w *= -1.0f; } if(h < 0.0f) { y += h; h *= -1.0f; } // keep radii in check float maxRadius = MIN(w / 2.0f, h / 2.0f); topLeftRadius = MIN(topLeftRadius, maxRadius); topRightRadius = MIN(topRightRadius, maxRadius); bottomRightRadius = MIN(bottomRightRadius, maxRadius); bottomLeftRadius = MIN(bottomLeftRadius, maxRadius); // if all radii are ~= 0.0f, then render as a normal rectangle if((fabs(topLeftRadius) < FLT_EPSILON) && (fabs(topRightRadius) < FLT_EPSILON) && (fabs(bottomRightRadius) < FLT_EPSILON) && (fabs(bottomLeftRadius) < FLT_EPSILON)) { // rect mode respect happens in ofRect rectangle(x, y, z, w, h); } else { float left = x; float right = x + w; float top = y; float bottom = y + h; moveTo(left + topLeftRadius, top, z); // top right if(fabs(topRightRadius) >= FLT_EPSILON) { arc(right - topRightRadius, top + topRightRadius, z, topRightRadius, topRightRadius, 270, 360); } else { lineTo(right, top, z); } lineTo(right, bottom - bottomRightRadius); // bottom right if(fabs(bottomRightRadius) >= FLT_EPSILON) { arc(right - bottomRightRadius, bottom - bottomRightRadius, z, bottomRightRadius, bottomRightRadius, 0, 90); } lineTo(left + bottomLeftRadius, bottom, z); // bottom left if(fabs(bottomLeftRadius) >= FLT_EPSILON) { arc(left + bottomLeftRadius, bottom - bottomLeftRadius, z, bottomLeftRadius, bottomLeftRadius, 90, 180); } lineTo(left, top + topLeftRadius, z); // top left if(fabs(topLeftRadius) >= FLT_EPSILON) { arc(left + topLeftRadius, top + topLeftRadius, z, topLeftRadius, topLeftRadius, 180, 270); } close(); } }
// setter int define::update(string& data) { const char* header = getHeader().c_str(); // get the text vector<string> lines = BZWParser::getSectionsByHeader(header, data.c_str(), "enddef"); if(lines[0] == BZW_NOT_FOUND) return 0; if(lines.size() > 1) { printf("define::update(): Error! Defined \"define\" %d times!\n", (int)lines.size()); return 0; } // get the name vector<string> names = BZWParser::getValuesByKey("define", header, lines[0].c_str()); if(!hasOnlyOne(names, header)) return 0; // get the data string::size_type sectionStart = lines[0].find("\n") + 1; string::size_type sectionLength = lines[0].find( "enddef", sectionStart ) - sectionStart; lines[0] = lines[0].substr( sectionStart, sectionLength ); const char* defineData = lines[0].c_str(); // get the chunks vector<string> chunks = BZWParser::getSections( defineData ); // get all the supported objects from the lines, but don't commit them yet // arc vector<string> arcs = BZWParser::findSections("arc", chunks); vector<arc> arcData; if(arcs[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = arcs.begin(); i != arcs.end(); i++) { arc tmp = arc(); if(!tmp.update(*i)) return 0; arcData.push_back( tmp ); } } // base vector<string> bases = BZWParser::findSections("base", chunks); vector<base> baseData; if(bases[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = bases.begin(); i != bases.end(); i++) { base tmp = base(); if(!tmp.update(*i)) return 0; baseData.push_back( tmp ); } } // box vector<string> boxes = BZWParser::findSections("box", chunks); vector<box> boxData; if(boxes[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = boxes.begin(); i != boxes.end(); i++) { box tmp = box(); if(!tmp.update(*i)) return 0; boxData.push_back( tmp ); } } // cone vector<string> cones = BZWParser::findSections("cone", chunks); vector<cone> coneData; if(cones[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = cones.begin(); i != cones.end(); i++) { cone tmp = cone(); if(!tmp.update(*i)) return 0; coneData.push_back( tmp ); } } // group vector<string> groups = BZWParser::findSections("group", chunks); vector<group> groupData; if(groups[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = groups.begin(); i != groups.end(); i++) { group tmp = group(); if(!tmp.update(*i)) return 0; groupData.push_back( tmp ); } } // mesh vector<string> meshes = BZWParser::findSections("mesh", chunks); vector<mesh> meshData; if(meshes[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = meshes.begin(); i != meshes.end(); i++) { mesh tmp = mesh(); if(!tmp.update(*i)) return 0; meshData.push_back( tmp ); } } // meshbox vector<string> meshboxes = BZWParser::findSections("meshbox", chunks); vector<meshbox> meshboxData; if(meshboxes[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = meshboxes.begin(); i != meshboxes.end(); i++) { meshbox tmp = meshbox(); if(!tmp.update(*i)) return 0; meshboxData.push_back( tmp ); } } // meshpyr vector<string> meshpyrs = BZWParser::findSections("meshpyr", chunks); vector<meshpyr> meshpyrData; if(meshpyrs[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = meshpyrs.begin(); i != meshpyrs.end(); i++) { meshpyr tmp = meshpyr(); if(!tmp.update(*i)) return 0; meshpyrData.push_back( tmp ); } } // pyramid vector<string> pyramids = BZWParser::findSections("pyramid", chunks); vector<pyramid> pyramidData; if(pyramids[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = pyramids.begin(); i != pyramids.end(); i++) { pyramid tmp = pyramid(); if(!tmp.update(*i)) return 0; pyramidData.push_back( tmp ); } } // sphere vector<string> spheres = BZWParser::findSections("sphere", chunks); vector<sphere> sphereData; if(spheres[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = spheres.begin(); i != spheres.end(); i++) { sphere tmp = sphere(); if(!tmp.update(*i)) return 0; sphereData.push_back( tmp ); } } // teleporter vector<string> teleporters = BZWParser::findSections("teleporter", chunks); vector<teleporter> teleporterData; if(teleporters[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = teleporters.begin(); i != teleporters.end(); i++) { teleporter tmp = teleporter(); if(!tmp.update(*i)) return 0; teleporterData.push_back( tmp ); } } // tetra vector<string> tetras = BZWParser::findSections("tetra", chunks); vector<tetra> tetraData; if(tetras[0] != BZW_NOT_FOUND) { for(vector<string>::iterator i = tetras.begin(); i != tetras.end(); i++) { tetra tmp = tetra(); if(!tmp.update(*i)) return 0; tetraData.push_back( tmp ); } } // base-class update (must be done BEFORE commiting new objects) if(!DataEntry::update(data)) { return 0; } // commit name name = names[0]; // free previous objects objects.clear(); // commit arcs if(arcData.size() > 0) { for(vector<arc>::iterator i = arcData.begin(); i != arcData.end(); i++) { objects.push_back( new arc(*i) ); } } // commit bases if(baseData.size() > 0) { for(vector<base>::iterator i = baseData.begin(); i != baseData.end(); i++) { objects.push_back( new base(*i) ); } } // commit boxes if(boxData.size() > 0) { for(vector<box>::iterator i = boxData.begin(); i != boxData.end(); i++) { objects.push_back( new box(*i) ); } } // commit cones if(coneData.size() > 0) { for(vector<cone>::iterator i = coneData.begin(); i != coneData.end(); i++) { objects.push_back( new cone(*i) ); } } // commit groups if(groupData.size() > 0) { for(vector<group>::iterator i = groupData.begin(); i != groupData.end(); i++) { objects.push_back( new group(*i) ); } } // commit meshes if(meshData.size() > 0) { for(vector<mesh>::iterator i = meshData.begin(); i != meshData.end(); i++) { objects.push_back( new mesh(*i) ); } } // commit meshboxes if(meshboxData.size() > 0) { for(vector<meshbox>::iterator i = meshboxData.begin(); i != meshboxData.end(); i++) { objects.push_back( new meshbox(*i) ); } } // commit meshpyrs if(meshpyrData.size() > 0) { for(vector<meshpyr>::iterator i = meshpyrData.begin(); i != meshpyrData.end(); i++) { objects.push_back( new meshpyr(*i) ); } } // commit pyramids if(pyramidData.size() > 0) { for(vector<pyramid>::iterator i = pyramidData.begin(); i != pyramidData.end(); i++) { objects.push_back( new pyramid(*i) ); } } // commit spheres if(sphereData.size() > 0) { for(vector<sphere>::iterator i = sphereData.begin(); i != sphereData.end(); i++) { objects.push_back( new sphere(*i) ); } } // commit teleporters if(teleporterData.size() > 0) { for(vector<teleporter>::iterator i = teleporterData.begin(); i != teleporterData.end(); i++) { objects.push_back( new teleporter(*i) ); } } // commit tetras if(tetraData.size() > 0) { for(vector<tetra>::iterator i = tetraData.begin(); i != tetraData.end(); i++) { objects.push_back( new tetra(*i) ); } } return 1; }
void FSavegameManager::ReadSaveStrings() { if (SaveGames.Size() == 0) { void *filefirst; findstate_t c_file; FString filter; LastSaved = LastAccessed = -1; quickSaveSlot = nullptr; filter = G_BuildSaveName("*." SAVEGAME_EXT, -1); filefirst = I_FindFirst(filter.GetChars(), &c_file); if (filefirst != ((void *)(-1))) { do { // I_FindName only returns the file's name and not its full path FString filepath = G_BuildSaveName(I_FindName(&c_file), -1); FResourceFile *savegame = FResourceFile::OpenResourceFile(filepath, true, true); if (savegame != nullptr) { bool oldVer = false; bool missing = false; FResourceLump *info = savegame->FindLump("info.json"); if (info == nullptr) { // savegame info not found. This is not a savegame so leave it alone. delete savegame; continue; } void *data = info->CacheLump(); FSerializer arc(nullptr); if (arc.OpenReader((const char *)data, info->LumpSize)) { int savever = 0; arc("Save Version", savever); FString engine = arc.GetString("Engine"); FString iwad = arc.GetString("Game WAD"); FString title = arc.GetString("Title"); if (engine.Compare(GAMESIG) != 0 || savever > SAVEVER) { // different engine or newer version: // not our business. Leave it alone. delete savegame; continue; } if (savever < MINSAVEVER) { // old, incompatible savegame. List as not usable. oldVer = true; } else if (iwad.CompareNoCase(Wads.GetWadName(Wads.GetIwadNum())) == 0) { missing = !G_CheckSaveGameWads(arc, false); } else { // different game. Skip this. delete savegame; continue; } FSaveGameNode *node = new FSaveGameNode; node->Filename = filepath; node->bOldVersion = oldVer; node->bMissingWads = missing; node->SaveTitle = title; InsertSaveNode(node); delete savegame; } } else // check for old formats. { FileReader file; if (file.OpenFile(filepath)) { PNGHandle *png; char sig[16]; char title[OLDSAVESTRINGSIZE + 1]; bool oldVer = true; bool addIt = false; bool missing = false; // ZDoom 1.23 betas 21-33 have the savesig first. // Earlier versions have the savesig second. // Later versions have the savegame encapsulated inside a PNG. // // Old savegame versions are always added to the menu so // the user can easily delete them if desired. title[OLDSAVESTRINGSIZE] = 0; if (nullptr != (png = M_VerifyPNG(file))) { char *ver = M_GetPNGText(png, "ZDoom Save Version"); if (ver != nullptr) { // An old version if (!M_GetPNGText(png, "Title", title, OLDSAVESTRINGSIZE)) { strncpy(title, I_FindName(&c_file), OLDSAVESTRINGSIZE); } addIt = true; delete[] ver; } delete png; } else { file.Seek(0, FileReader::SeekSet); if (file.Read(sig, 16) == 16) { if (strncmp(sig, "ZDOOMSAVE", 9) == 0) { if (file.Read(title, OLDSAVESTRINGSIZE) == OLDSAVESTRINGSIZE) { addIt = true; } } else { memcpy(title, sig, 16); if (file.Read(title + 16, OLDSAVESTRINGSIZE - 16) == OLDSAVESTRINGSIZE - 16 && file.Read(sig, 16) == 16 && strncmp(sig, "ZDOOMSAVE", 9) == 0) { addIt = true; } } } } if (addIt) { FSaveGameNode *node = new FSaveGameNode; node->Filename = filepath; node->bOldVersion = true; node->bMissingWads = false; node->SaveTitle = title; InsertSaveNode(node); } } } } while (I_FindNext(filefirst, &c_file) == 0); I_FindClose(filefirst); } } }
SHAPE_LINE_CHAIN PNS_MEANDER_SHAPE::genMeanderShape( VECTOR2D aP, VECTOR2D aDir, bool aSide, PNS_MEANDER_TYPE aType, int aAmpl, int aBaselineOffset ) { const PNS_MEANDER_SETTINGS& st = Settings(); int cr = cornerRadius(); int offset = aBaselineOffset; int spc = spacing(); if( aSide ) offset *= -1; VECTOR2D dir_u_b( aDir.Resize( offset ) ); VECTOR2D dir_v_b( dir_u_b.Perpendicular() ); if( 2 * cr > aAmpl ) { cr = aAmpl / 2; } if( 2 * cr > spc ) { cr = spc / 2; } SHAPE_LINE_CHAIN lc; start( &lc, aP + dir_v_b, aDir ); switch( aType ) { case MT_EMPTY: { lc.Append( aP + dir_v_b + aDir ); break; } case MT_START: { arc( cr - offset, false ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); forward( std::min( cr - offset, cr + offset ) ); forward( std::abs( offset ) ); break; } case MT_FINISH: { start( &lc, aP - dir_u_b, aDir ); turn ( 90 ); forward( std::min( cr - offset, cr + offset ) ); forward( std::abs( offset ) ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); arc( cr - offset, false ); break; } case MT_TURN: { start( &lc, aP - dir_u_b, aDir ); turn( 90 ); forward( std::abs( offset ) ); uShape ( aAmpl - cr, cr + offset, spc - 2 * cr ); forward( std::abs( offset ) ); break; } case MT_SINGLE: { arc( cr - offset, false ); uShape( aAmpl - 2 * cr + std::abs( offset ), cr + offset, spc - 2 * cr ); arc( cr - offset, false ); lc.Append( aP + dir_v_b + aDir.Resize ( 2 * st.m_spacing ) ); break; } default: break; } if( aSide ) { SEG axis ( aP, aP + aDir ); for( int i = 0; i < lc.PointCount(); i++ ) lc.Point( i ) = reflect( lc.CPoint( i ), axis ); } return lc; }
void Context::circle( double dx, double dy, double radius ) { newSubPath(); arc( dx, dy, radius, 0, 2 * 3.14159265 ); }
FSerializer &Serialize(FSerializer &arc, const char *key, subsector_t *&ss, subsector_t **) { BYTE by; const char *str; if (arc.isWriting()) { if (hasglnodes) { TArray<char> encoded(1 + (numsubsectors + 5) / 6); int p = 0; for (int i = 0; i < numsubsectors; i += 6) { by = 0; for (int j = 0; j < 6; j++) { if (i + j < numsubsectors && (subsectors[i + j].flags & SSECF_DRAWN)) { by |= (1 << j); } } if (by < 10) by += '0'; else if (by < 36) by += 'A' - 10; else if (by < 62) by += 'a' - 36; else if (by == 62) by = '-'; else if (by == 63) by = '+'; encoded[p++] = by; } encoded[p] = 0; str = &encoded[0]; if (arc.BeginArray(key)) { arc(nullptr, numvertexes) (nullptr, numsubsectors) .StringPtr(nullptr, str) .EndArray(); } } } else { int num_verts, num_subs; bool success = false; if (arc.BeginArray(key)) { arc(nullptr, num_verts) (nullptr, num_subs) .StringPtr(nullptr, str) .EndArray(); if (num_verts == numvertexes && num_subs == numsubsectors && hasglnodes) { success = true; int sub = 0; for (int i = 0; str[i] != 0; i++) { by = str[i]; if (by >= '0' && by <= '9') by -= '0'; else if (by >= 'A' && by <= 'Z') by -= 'A' - 10; else if (by >= 'a' && by <= 'z') by -= 'a' - 36; else if (by == '-') by = 62; else if (by == '+') by = 63; else { success = false; break; } for (int s = 0; s < 6; s++) { if (sub + s < numsubsectors && (by & (1 << s))) { subsectors[sub + s].flags |= SSECF_DRAWN; } } sub += 6; } } if (hasglnodes && !success) { RecalculateDrawnSubsectors(); } } } return arc; }
FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t *def) { // save the Scroll data here because it's a lot easier to handle a default. // Just writing out the full array can massively inflate the archive for no gain. DVector2 scroll = { 0,0 }, nul = { 0,0 }; if (arc.isWriting() && level.Scrolls.Size() > 0) scroll = level.Scrolls[p.sectornum]; if (arc.BeginObject(key)) { arc("floorplane", p.floorplane, def->floorplane) ("ceilingplane", p.ceilingplane, def->ceilingplane) ("lightlevel", p.lightlevel, def->lightlevel) ("special", p.special, def->special) ("seqtype", p.seqType, def->seqType) ("seqname", p.SeqName, def->SeqName) ("friction", p.friction, def->friction) ("movefactor", p.movefactor, def->movefactor) ("stairlock", p.stairlock, def->stairlock) ("prevsec", p.prevsec, def->prevsec) ("nextsec", p.nextsec, def->nextsec) .Array("planes", p.planes, def->planes, 2, true) // These cannot change during play. //("heightsec", p.heightsec) //("bottommap", p.bottommap) //("midmap", p.midmap) //("topmap", p.topmap) ("damageamount", p.damageamount, def->damageamount) ("damageinterval", p.damageinterval, def->damageinterval) ("leakydamage", p.leakydamage, def->leakydamage) ("damagetype", p.damagetype, def->damagetype) ("sky", p.sky, def->sky) ("moreflags", p.MoreFlags, def->MoreFlags) ("flags", p.Flags, def->Flags) .Array("portals", p.Portals, def->Portals, 2, true) ("zonenumber", p.ZoneNumber, def->ZoneNumber) .Array("interpolations", p.interpolations, 4, true) ("soundtarget", p.SoundTarget) ("secacttarget", p.SecActTarget) ("floordata", p.floordata) ("ceilingdata", p.ceilingdata) ("lightingdata", p.lightingdata) ("fakefloor_sectors", p.e->FakeFloor.Sectors) ("midtexf_lines", p.e->Midtex.Floor.AttachedLines) ("midtexf_sectors", p.e->Midtex.Floor.AttachedSectors) ("midtexc_lines", p.e->Midtex.Ceiling.AttachedLines) ("midtexc_sectors", p.e->Midtex.Ceiling.AttachedSectors) ("linked_floor", p.e->Linked.Floor.Sectors) ("linked_ceiling", p.e->Linked.Ceiling.Sectors) ("colormap", p.ColorMap, def->ColorMap) .Terrain("floorterrain", p.terrainnum[0], &def->terrainnum[0]) .Terrain("ceilingterrain", p.terrainnum[1], &def->terrainnum[1]) ("scrolls", scroll, nul) .EndObject(); if (arc.isReading() && !scroll.isZero()) { if (level.Scrolls.Size() == 0) { level.Scrolls.Resize(numsectors); memset(&level.Scrolls[0], 0, sizeof(level.Scrolls[0])*level.Scrolls.Size()); level.Scrolls[p.sectornum] = scroll; } } } return arc; }
unsigned FSavegameManager::ExtractSaveData(int index) { FResourceFile *resf; FSaveGameNode *node; if (index == -1) { if (SaveGames.Size() > 0 && SaveGames[0]->bNoDelete) { index = LastSaved + 1; } else { index = LastAccessed < 0? 0 : LastAccessed; } } UnloadSaveData(); if ((unsigned)index < SaveGames.Size() && (node = SaveGames[index]) && !node->Filename.IsEmpty() && !node->bOldVersion && (resf = FResourceFile::OpenResourceFile(node->Filename.GetChars(), true)) != nullptr) { FResourceLump *info = resf->FindLump("info.json"); if (info == nullptr) { // this should not happen because the file has already been verified. return index; } void *data = info->CacheLump(); FSerializer arc(nullptr); if (arc.OpenReader((const char *)data, info->LumpSize)) { FString comment; FString time = arc.GetString("Creation Time"); FString pcomment = arc.GetString("Comment"); comment = time; if (time.Len() > 0) comment += "\n"; comment += pcomment; SaveCommentString = comment; // Extract pic FResourceLump *pic = resf->FindLump("savepic.png"); if (pic != nullptr) { FileReader picreader; picreader.OpenMemoryArray([=](TArray<uint8_t> &array) { auto cache = pic->CacheLump(); array.Resize(pic->LumpSize); memcpy(&array[0], cache, pic->LumpSize); pic->ReleaseCache(); return true; }); PNGHandle *png = M_VerifyPNG(picreader); if (png != nullptr) { SavePic = PNGTexture_CreateFromFile(png, node->Filename); delete png; if (SavePic && SavePic->GetDisplayWidth() == 1 && SavePic->GetDisplayHeight() == 1) { delete SavePic; SavePic = nullptr; SavePicData.Clear(); } } } } delete resf; } return index; }
void M2MFstAligner::Sequences2FST( VectorFst<LogArc>* fst, vector<string>* seq1, vector<string>* seq2 ){ /* Build an FST that represents all possible alignments between seq1 and seq2, given the parameter values input by the user. Here we encode the input and output labels, in fact creating a WFSA. This simplifies the training process, but means that we can only easily compute a joint maximization. In practice joint maximization seems to give the best results anyway, so it probably doesn't matter. Note: this also performs the initizization routine. It performs a UNIFORM initialization meaning that every non-null alignment sequence is eventually initialized to 1/Num(unique_alignments). It might be more appropriate to consider subsequence length here, but for now we stick to the m2m-aligner approach. TODO: Add an FST version and support for conditional maximization. May be useful for languages like Japanese where there is a distinct imbalance in the seq1->seq2 length correspondences. */ int istate=0; int ostate=0; for( unsigned int i=0; i<=seq1->size(); i++ ){ for( unsigned int j=0; j<=seq2->size(); j++ ){ fst->AddState(); istate = i*(seq2->size()+1)+j; //Epsilon arcs for seq1 if( seq1_del==true ) for( unsigned int l=1; l<=seq2_max; l++ ){ if( j+l<=seq2->size() ){ vector<string> subseq2( seq2->begin()+j, seq2->begin()+j+l ); int is = isyms->AddSymbol(skip+s1s2_sep+vec2str(subseq2, seq2_sep)); ostate = i*(seq2->size()+1) + (j+l); LogArc arc( is, is, 99, ostate ); fst->AddArc( istate, arc ); /* if( prev_alignment_model.find(arc.ilabel)==prev_alignment_model.end() ){ prev_alignment_model.insert( pair<LogArc::Label,LogWeight>(arc.ilabel,arc.weight) ); _compute_penalties( arc.ilabel, 1, l, true, false ); }else{ prev_alignment_model[arc.ilabel] = Plus(prev_alignment_model[arc.ilabel],arc.weight); } total = Plus( total, arc.weight ); */ } } //Epsilon arcs for seq2 if( seq2_del==true ) for( unsigned int k=1; k<=seq1_max; k++ ){ if( i+k<=seq1->size() ){ vector<string> subseq1( seq1->begin()+i, seq1->begin()+i+k ); int is = isyms->AddSymbol(vec2str(subseq1, seq1_sep)+s1s2_sep+skip); ostate = (i+k)*(seq2->size()+1) + j; LogArc arc( is, is, 99, ostate ); fst->AddArc( istate, arc ); /* if( prev_alignment_model.find(arc.ilabel)==prev_alignment_model.end() ){ prev_alignment_model.insert( pair<LogArc::Label,LogWeight>(arc.ilabel,arc.weight) ); _compute_penalties( arc.ilabel, k, 1, false, true ); }else{ prev_alignment_model[arc.ilabel] = Plus(prev_alignment_model[arc.ilabel],arc.weight); } total = Plus(total, arc.weight); */ } } //All the other arcs for( unsigned int k=1; k<=seq1_max; k++ ){ for( unsigned int l=1; l<=seq2_max; l++ ){ if( i+k<=seq1->size() && j+l<=seq2->size() ){ vector<string> subseq1( seq1->begin()+i, seq1->begin()+i+k ); string s1 = vec2str(subseq1, seq1_sep); vector<string> subseq2( seq2->begin()+j, seq2->begin()+j+l ); string s2 = vec2str(subseq2, seq2_sep); //This says only 1-M and N-1 allowed, no M-N links! if( restrict==true && l>1 && k>1) continue; int is = isyms->AddSymbol(s1+s1s2_sep+s2); ostate = (i+k)*(seq2->size()+1) + (j+l); LogArc arc( is, is, LogWeight::One().Value()*(k+l), ostate ); fst->AddArc( istate, arc ); //During the initialization phase, just count non-eps transitions //We currently initialize to uniform probability so there is also // no need to tally anything here. /* if( prev_alignment_model.find(arc.ilabel)==prev_alignment_model.end() ){ prev_alignment_model.insert( pair<LogArc::Label,LogWeight>(arc.ilabel, arc.weight) ); _compute_penalties( arc.ilabel, k, l, false, false ); }else{ prev_alignment_model[arc.ilabel] = Plus(prev_alignment_model[arc.ilabel],arc.weight); } total = Plus( total, arc.weight ); */ } } } } } fst->SetStart(0); fst->SetFinal( ((seq1->size()+1)*(seq2->size()+1))-1, LogWeight::One() ); //Unless seq1_del==true && seq2_del==true we will have unconnected states // thus we need to run connect to clean out these states if( seq1_del==false || seq2_del==false ) Connect(fst); //Only add arcs that are in the FINAL fst to the model for( StateIterator<VectorFst<LogArc> > siter(*fst); !siter.Done(); siter.Next() ){ LogArc::StateId q = siter.Value(); for( ArcIterator<VectorFst<LogArc> > aiter(*fst, q); !aiter.Done(); aiter.Next() ){ const LogArc& arc = aiter.Value(); if( prev_alignment_model.find(arc.ilabel)==prev_alignment_model.end() ){ prev_alignment_model.insert( pair<LogArc::Label,LogWeight>(arc.ilabel, arc.weight) ); string sym = isyms->Find(arc.ilabel); size_t del = sym.find("}"); size_t ski = sym.find("_"); size_t chu = sym.find("|"); int k=1; int l=1; bool xd = false; bool yd = false; if( chu!=string::npos ){ if( chu<del ) k += 1; else l += 1; } if( ski!=string::npos ){ if( ski<del ) xd = true; else yd = true; } _compute_penalties( arc.ilabel, k, l, false, false ); }else{ prev_alignment_model[arc.ilabel] = Plus(prev_alignment_model[arc.ilabel],arc.weight); } total = Plus( total, arc.weight ); } } return; }
int Context2D::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: changed((*reinterpret_cast< const QImage(*)>(_a[1]))); break; case 1: save(); break; case 2: restore(); break; case 3: scale((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2]))); break; case 4: rotate((*reinterpret_cast< qreal(*)>(_a[1]))); break; case 5: translate((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2]))); break; case 6: transform((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5])),(*reinterpret_cast< qreal(*)>(_a[6]))); break; case 7: setTransform((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5])),(*reinterpret_cast< qreal(*)>(_a[6]))); break; case 8: { CanvasGradient _r = createLinearGradient((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4]))); if (_a[0]) *reinterpret_cast< CanvasGradient*>(_a[0]) = _r; } break; case 9: { CanvasGradient _r = createRadialGradient((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5])),(*reinterpret_cast< qreal(*)>(_a[6]))); if (_a[0]) *reinterpret_cast< CanvasGradient*>(_a[0]) = _r; } break; case 10: clearRect((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4]))); break; case 11: fillRect((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4]))); break; case 12: strokeRect((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4]))); break; case 13: beginPath(); break; case 14: closePath(); break; case 15: moveTo((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2]))); break; case 16: lineTo((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2]))); break; case 17: quadraticCurveTo((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4]))); break; case 18: bezierCurveTo((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5])),(*reinterpret_cast< qreal(*)>(_a[6]))); break; case 19: arcTo((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5]))); break; case 20: rect((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4]))); break; case 21: arc((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5])),(*reinterpret_cast< bool(*)>(_a[6]))); break; case 22: fill(); break; case 23: stroke(); break; case 24: clip(); break; case 25: { bool _r = isPointInPath((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 26: drawImage((*reinterpret_cast< DomImage*(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3]))); break; case 27: drawImage((*reinterpret_cast< DomImage*(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5]))); break; case 28: drawImage((*reinterpret_cast< DomImage*(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4])),(*reinterpret_cast< qreal(*)>(_a[5])),(*reinterpret_cast< qreal(*)>(_a[6])),(*reinterpret_cast< qreal(*)>(_a[7])),(*reinterpret_cast< qreal(*)>(_a[8])),(*reinterpret_cast< qreal(*)>(_a[9]))); break; case 29: { ImageData _r = getImageData((*reinterpret_cast< qreal(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3])),(*reinterpret_cast< qreal(*)>(_a[4]))); if (_a[0]) *reinterpret_cast< ImageData*>(_a[0]) = _r; } break; case 30: putImageData((*reinterpret_cast< ImageData(*)>(_a[1])),(*reinterpret_cast< qreal(*)>(_a[2])),(*reinterpret_cast< qreal(*)>(_a[3]))); break; default: ; } _id -= 31; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< qreal*>(_v) = globalAlpha(); break; case 1: *reinterpret_cast< QString*>(_v) = globalCompositeOperation(); break; case 2: *reinterpret_cast< QVariant*>(_v) = strokeStyle(); break; case 3: *reinterpret_cast< QVariant*>(_v) = fillStyle(); break; case 4: *reinterpret_cast< qreal*>(_v) = lineWidth(); break; case 5: *reinterpret_cast< QString*>(_v) = lineCap(); break; case 6: *reinterpret_cast< QString*>(_v) = lineJoin(); break; case 7: *reinterpret_cast< qreal*>(_v) = miterLimit(); break; case 8: *reinterpret_cast< qreal*>(_v) = shadowOffsetX(); break; case 9: *reinterpret_cast< qreal*>(_v) = shadowOffsetY(); break; case 10: *reinterpret_cast< qreal*>(_v) = shadowBlur(); break; case 11: *reinterpret_cast< QString*>(_v) = shadowColor(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setGlobalAlpha(*reinterpret_cast< qreal*>(_v)); break; case 1: setGlobalCompositeOperation(*reinterpret_cast< QString*>(_v)); break; case 2: setStrokeStyle(*reinterpret_cast< QVariant*>(_v)); break; case 3: setFillStyle(*reinterpret_cast< QVariant*>(_v)); break; case 4: setLineWidth(*reinterpret_cast< qreal*>(_v)); break; case 5: setLineCap(*reinterpret_cast< QString*>(_v)); break; case 6: setLineJoin(*reinterpret_cast< QString*>(_v)); break; case 7: setMiterLimit(*reinterpret_cast< qreal*>(_v)); break; case 8: setShadowOffsetX(*reinterpret_cast< qreal*>(_v)); break; case 9: setShadowOffsetY(*reinterpret_cast< qreal*>(_v)); break; case 10: setShadowBlur(*reinterpret_cast< qreal*>(_v)); break; case 11: setShadowColor(*reinterpret_cast< QString*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }
void M2MFstAligner::Sequences2FSTNoInit( VectorFst<LogArc>* fst, vector<string>* seq1, vector<string>* seq2 ){ /* Build an FST that represents all possible alignments between seq1 and seq2, given the parameter values input by the user. Here we encode the input and output labels, in fact creating a WFSA. This simplifies the training process, but means that we can only easily compute a joint maximization. In practice joint maximization seems to give the best results anyway, so it probably doesn't matter. */ int istate=0; int ostate=0; for( unsigned int i=0; i<=seq1->size(); i++ ){ for( unsigned int j=0; j<=seq2->size(); j++ ){ fst->AddState(); istate = i*(seq2->size()+1)+j; //Epsilon arcs for seq1 if( seq1_del==true ) for( unsigned int l=1; l<=seq2_max; l++ ){ if( j+l<=seq2->size() ){ vector<string> subseq2( seq2->begin()+j, seq2->begin()+j+l ); int is = isyms->Find(skip+s1s2_sep+vec2str(subseq2, seq2_sep)); ostate = i*(seq2->size()+1) + (j+l); LogArc arc( is, is, alignment_model[is], ostate ); _compute_penalties( arc.ilabel, 1, l, true, false ); fst->AddArc( istate, arc ); } } //Epsilon arcs for seq2 if( seq2_del==true ) for( unsigned int k=1; k<=seq1_max; k++ ){ if( i+k<=seq1->size() ){ vector<string> subseq1( seq1->begin()+i, seq1->begin()+i+k ); int is = isyms->Find(vec2str(subseq1, seq1_sep)+s1s2_sep+skip); ostate = (i+k)*(seq2->size()+1) + j; LogArc arc( is, is, alignment_model[is], ostate ); _compute_penalties( arc.ilabel, k, 1, false, true ); fst->AddArc( istate, arc ); } } //All the other arcs for( unsigned int k=1; k<=seq1_max; k++ ){ for( unsigned int l=1; l<=seq2_max; l++ ){ if( i+k<=seq1->size() && j+l<=seq2->size() ){ vector<string> subseq1( seq1->begin()+i, seq1->begin()+i+k ); string s1 = vec2str(subseq1, seq1_sep); vector<string> subseq2( seq2->begin()+j, seq2->begin()+j+l ); string s2 = vec2str(subseq2, seq2_sep); if( restrict==true && l>1 && k>1) continue; int is = isyms->Find(s1+s1s2_sep+s2); ostate = (i+k)*(seq2->size()+1) + (j+l); LogArc arc( is, is, alignment_model[is], ostate ); _compute_penalties( arc.ilabel, k, l, false, false ); fst->AddArc( istate, arc ); } } } } } fst->SetStart(0); fst->SetFinal( ((seq1->size()+1)*(seq2->size()+1))-1, LogWeight::One() ); //Unless seq1_del==true && seq2_del==true we will have unconnected states // thus we need to run connect to clean out these states if( seq1_del==false || seq2_del==false ) Connect(fst); return; }
/** draw circle as a 2 pi arc */ void RS_Circle::draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset) { RS_Arc arc(getParent(), RS_ArcData(getCenter(),getRadius(),0.,2.*M_PI, false)); arc.setSelected(isSelected()); arc.setPen(getPen()); arc.draw(painter,view,patternOffset); }
shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, double endAngle, int isSlice) { static int allocated_size=100; shapeObj *shape = (shapeObj*)calloc(1,sizeof(shapeObj)); MS_CHECK_ALLOC(shape, sizeof(shapeObj), NULL); mapserver::arc arc ( x0, y0,radius,radius, startAngle*MS_DEG_TO_RAD, endAngle*MS_DEG_TO_RAD,true ); arc.approximation_scale ( 1 ); arc.rewind(1); msInitShape(shape); lineObj *line = (lineObj*)calloc(1,sizeof(lineObj)); if (!line) { msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , __FILE__, __LINE__, sizeof(lineObj)); free(shape); return NULL; } shape->line = line; shape->numlines = 1; line->point = (pointObj*)calloc(allocated_size,sizeof(pointObj)); if (!line->point) { msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , __FILE__, __LINE__, allocated_size*sizeof(pointObj)); free(line); free(shape); return NULL; } line->numpoints = 0; double x,y; //first segment from center to first point of arc if(isSlice) { line->point[0].x = x0; line->point[0].y = y0; line->numpoints = 1; } while(arc.vertex(&x,&y) != mapserver::path_cmd_stop) { if(line->numpoints == allocated_size) { allocated_size *= 2; line->point = (pointObj*)realloc(line->point, allocated_size * sizeof(pointObj)); if (!line->point) { msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , __FILE__, __LINE__, allocated_size * sizeof(pointObj)); free(line); free(shape); return NULL; } } line->point[line->numpoints].x = x; line->point[line->numpoints].y = y; line->numpoints++; } //make sure the shape is closed if we're doing a full circle if(!isSlice && !(endAngle-startAngle)%360) { if(line->point[line->numpoints-1].x != line->point[0].x || line->point[line->numpoints-1].y != line->point[0].y) { if(line->numpoints == allocated_size) { allocated_size *= 2; line->point = (pointObj*)realloc(line->point, allocated_size * sizeof(pointObj)); if (!line->point) { msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , __FILE__, __LINE__, allocated_size * sizeof(pointObj)); free(line); free(shape); return NULL; } } line->point[line->numpoints].x = line->point[0].x; line->point[line->numpoints].y = line->point[0].y; line->numpoints++; } } if(isSlice) { if(line->numpoints == allocated_size) { allocated_size *= 2; line->point = (pointObj*)realloc(line->point, allocated_size * sizeof(pointObj)); if (!line->point) { msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", "msRasterizeArc()" , __FILE__, __LINE__, allocated_size * sizeof(pointObj)); free(line); free(shape); return NULL; } } line->point[line->numpoints].x = x0; line->point[line->numpoints].y = y0; line->numpoints++; } return shape; }
void erase(void) { setcolor(16); arc(350,400,pstang,penang,10); }
//---------------------------------------------------------- void ofPath::arc(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd){ arc(ofPoint(x,y,z),radiusX,radiusY,angleBegin,angleEnd); }
void draw(void) { setcolor(15); arc(350,400,stang,enang,10); }
//---------------------------------------------------------- void ofPath::ellipse(float x, float y, float z, float width, float height){ arc(x,y,z,width*.5,height*.5,0,360); }
void CategorizedListViewPainter::drawCategory(const QModelIndex &index, int /*sortRole*/, const QStyleOption &option, QPainter *painter) const { painter->setRenderHint(QPainter::Antialiasing); const QString category = index.model()->data(index, CategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); const QRect optRect = option.rect; QFont font(QApplication::font()); font.setBold(true); const QFontMetrics fontMetrics = QFontMetrics(font); QColor outlineColor = option.palette.text().color(); outlineColor.setAlphaF(0.35); //BEGIN: top left corner { painter->save(); painter->setPen(outlineColor); const QPointF topLeft(optRect.topLeft()); QRectF arc(topLeft, QSizeF(4, 4)); arc.translate(0.5, 0.5); painter->drawArc(arc, 1440, 1440); painter->restore(); } //END: top left corner //BEGIN: left vertical line { QPoint start(optRect.topLeft()); start.ry() += 3; QPoint verticalGradBottom(optRect.topLeft()); verticalGradBottom.ry() += fontMetrics.height() + 5; QLinearGradient gradient(start, verticalGradBottom); gradient.setColorAt(0, outlineColor); gradient.setColorAt(1, Qt::transparent); painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient); } //END: left vertical line //BEGIN: horizontal line { QPoint start(optRect.topLeft()); start.rx() += 3; QPoint horizontalGradTop(optRect.topLeft()); horizontalGradTop.rx() += optRect.width() - 6; painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor); } //END: horizontal line //BEGIN: top right corner { painter->save(); painter->setPen(outlineColor); QPointF topRight(optRect.topRight()); topRight.rx() -= 4; QRectF arc(topRight, QSizeF(4, 4)); arc.translate(0.5, 0.5); painter->drawArc(arc, 0, 1440); painter->restore(); } //END: top right corner //BEGIN: right vertical line { QPoint start(optRect.topRight()); start.ry() += 3; QPoint verticalGradBottom(optRect.topRight()); verticalGradBottom.ry() += fontMetrics.height() + 5; QLinearGradient gradient(start, verticalGradBottom); gradient.setColorAt(0, outlineColor); gradient.setColorAt(1, Qt::transparent); painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient); } //END: right vertical line //BEGIN: text { QRect textRect(option.rect); textRect.setTop(textRect.top() + 7); textRect.setLeft(textRect.left() + 7); textRect.setHeight(fontMetrics.height()); textRect.setRight(textRect.right() - 7); painter->save(); painter->setFont(font); QColor penColor(option.palette.text().color()); penColor.setAlphaF(0.6); painter->setPen(penColor); painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, category); painter->restore(); } //END: text }
/** * Read the input buffer and find any recognized commands. One G or M command per line. */ void processCommand() { // blank lines if(buffer[0]==';') return; long cmd; // is there a line number? cmd=parsenumber('N',-1); if(cmd!=-1 && buffer[0]=='N') { // line number must appear first on the line if( cmd != line_number ) { // wrong line number error Serial.print(F("BADLINENUM ")); Serial.println(line_number); return; } // is there a checksum? if(strchr(buffer,'*')!=0) { // yes. is it valid? char checksum=0; int c=0; while(buffer[c]!='*') checksum ^= buffer[c++]; c++; // skip * int against = strtod(buffer+c,NULL); if( checksum != against ) { Serial.print(F("BADCHECKSUM ")); Serial.println(line_number); return; } } else { Serial.print(F("NOCHECKSUM ")); Serial.println(line_number); return; } line_number++; } cmd = parsenumber('G',-1); switch(cmd) { case 0: case 1: { // line feedrate(parsenumber('F',fr)); line( parsenumber('X',(mode_abs?px:0)) + (mode_abs?0:px), parsenumber('Y',(mode_abs?py:0)) + (mode_abs?0:py) ); break; } case 2: case 3: { // arc feedrate(parsenumber('F',fr)); arc(parsenumber('I',(mode_abs?px:0)) + (mode_abs?0:px), parsenumber('J',(mode_abs?py:0)) + (mode_abs?0:py), parsenumber('X',(mode_abs?px:0)) + (mode_abs?0:px), parsenumber('Y',(mode_abs?py:0)) + (mode_abs?0:py), (cmd==2) ? -1 : 1); break; } case 4: pause(parsenumber('S',0) + parsenumber('P',0)*1000.0f); break; // dwell case 90: mode_abs=1; break; // absolute mode case 91: mode_abs=0; break; // relative mode case 92: // set logical position position( parsenumber('X',0), parsenumber('Y',0) ); break; default: break; } cmd = parsenumber('M',-1); switch(cmd) { case 18: // disable motors release(); break; case 100: help(); break; case 110: line_number = parsenumber('N',line_number); break; case 114: where(); break; default: break; } }
blargg_err_t Zip_Extractor::open_v() { if ( arc().size() < end_entry_size ) return blargg_err_file_type; isZIP64 = false; if (arc().size() > 0xffffffff) isZIP64 = true; // Read final end_read_size bytes of file //BOOST::uint64_t file_pos = max( (BOOST::uint64_t) 0, arc().size() - end_read_size ); BOOST::int64_t file_pos = max( (BOOST::int64_t) 0, (BOOST::int64_t) arc().size() - end_read_size ); file_pos -= file_pos % disk_block_size; RETURN_ERR( catalog.resize( (size_t)(arc().size() - file_pos) ) ); RETURN_ERR( arc().seek( file_pos ) ); RETURN_ERR( arc().read( catalog.begin(), catalog.size() ) ); BOOST::int64_t end_pos = 0; if (!isZIP64) { // Find end-of-catalog entry end_pos = catalog.size() - end_entry_size; while (end_pos >= 0 && memcmp(&catalog[(size_t)end_pos], "PK\5\6", 4)) end_pos--; if (end_pos < 0) return blargg_err_file_type; end_entry_t const& end_entry = (end_entry_t&)catalog[(size_t)end_pos]; catalog_begin = get_le32(end_entry.dir_offset); } if (isZIP64) { // Find end64-of-catalog entry end_pos = catalog.size() - end64_entry_size; while (end_pos >= 0 && memcmp(&catalog[(size_t)end_pos], "PK\6\6", 4)) end_pos--; if (end_pos < 0) return blargg_err_file_type; end64_entry_t const& end_entry = (end64_entry_t&)catalog[(size_t)end_pos]; catalog_begin = get_le64(end_entry.dir_offset); } end_pos += file_pos; // some idiotic zip compressors add data to end of zip without setting comment len // check( arc().size() == end_pos + end_entry_size + get_le16( end_entry.comment_len ) ); BOOST::int64_t catalog_size = end_pos - catalog_begin; if ( catalog_size < 0 ) return blargg_err_file_corrupt; if (isZIP64) catalog_size += end64_entry_size; else catalog_size += end_entry_size; // See if catalog is entirely contained in bytes already read BOOST::int64_t begin_offset = catalog_begin - file_pos; if ( begin_offset >= 0 ) memmove( catalog.begin(), &catalog [(size_t)begin_offset], (size_t)catalog_size ); RETURN_ERR( catalog.resize( (size_t)catalog_size ) ); if ( begin_offset < 0 ) { // Catalog begins before bytes read, so it needs to be read RETURN_ERR( arc().seek( catalog_begin ) ); RETURN_ERR( arc().read( catalog.begin(), catalog.size() ) ); } // First entry in catalog should be a file or end of archive if ( memcmp( catalog.begin(), "PK\1\2", 4 ) && memcmp( catalog.begin(), "PK\5\6", 4 ) ) return blargg_err_file_type; reorder_entry_header( 0 ); return rewind_v(); }
/** * Exports a circle with the current attributes. * The default implementation calls exportArc with a full circle arc. */ void RExporter::exportCircle(const RCircle& circle) { RArc arc(circle.center, circle.radius, 0.0, 2*M_PI, false); exportArc(arc); }
void main(void) { clrscr(); int gdriver=DETECT,gmode; initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); int x=0,y=0,r=0,b=0,color=0,midx,midy,maxx,maxy; midx=getmaxx()/2; midy=getmaxy()/2; maxx=getmaxx(); maxy=getmaxy(); rectangle(0,0,maxx,maxy); do { delay(10); setcolor(color); setbkcolor(0); arc(midx,midy,999,r,40); arc(midx,midy,999,r,42); arc(midx,midy,999,r,44); arc(midx,midy,999,r,46); arc(midx,midy,999,r,48); arc(midx,midy,999,r,50); arc(midx,midy,999,r,52); arc(midx,midy,999,r,54); arc(midx,midy,999,r,56); arc(midx,midy,500,r,70); arc(midx,midy,500,r,72); arc(midx,midy,500,r,74); arc(midx,midy,500,r,76); arc(midx,midy,500,r,78); arc(midx,midy,500,r,80); moveto(midx-20,midy); outtext("WE thank"); x++; y++; r++; color++; } while( !kbhit() ); getch(); closegraph(); }