glyph_metrics_t QFontEngineQPA::boundingBox(const QGlyphLayout &glyphs) { glyph_metrics_t overall; // initialize with line height, we get the same behaviour on all platforms overall.y = -ascent(); overall.height = ascent() + descent() + 1; QFixed ymax = 0; QFixed xmax = 0; for (int i = 0; i < glyphs.numGlyphs; i++) { const Glyph *g = findGlyph(glyphs.glyphs[i]); if (!g) continue; QFixed x = overall.xoff + glyphs.offsets[i].x + g->x; QFixed y = overall.yoff + glyphs.offsets[i].y + g->y; overall.x = qMin(overall.x, x); overall.y = qMin(overall.y, y); xmax = qMax(xmax, x + g->width); ymax = qMax(ymax, y + g->height); overall.xoff += g->advance; } overall.height = qMax(overall.height, ymax - overall.y); overall.width = xmax - overall.x; return overall; }
QFixed QFontEngineS60::ascent() const { // Workaround for QTBUG-8013 // Stroke based fonts may return an incorrect FontMaxAscent of 0. const QFixed ascent = m_originalFont->FontMaxAscent(); return (ascent > 0) ? ascent : QFixed::fromReal(m_originalFontSizeInPixels) - descent(); }
glyph_metrics_t QFontEngineQPF::boundingBox(const QGlyphLayout *glyphs, int numGlyphs) { #ifndef QT_NO_FREETYPE const_cast<QFontEngineQPF *>(this)->ensureGlyphsLoaded(glyphs, numGlyphs); #endif glyph_metrics_t overall; // initialize with line height, we get the same behaviour on all platforms overall.y = -ascent(); overall.height = ascent() + descent() + 1; QFixed ymax = 0; QFixed xmax = 0; for (int i = 0; i < numGlyphs; i++) { const Glyph *g = findGlyph(glyphs[i].glyph); if (!g) continue; QFixed x = overall.xoff + glyphs[i].offset.x + g->x; QFixed y = overall.yoff + glyphs[i].offset.y + g->y; overall.x = qMin(overall.x, x); overall.y = qMin(overall.y, y); xmax = qMax(xmax, x + g->width); ymax = qMax(ymax, y + g->height); overall.xoff += g->advance; } overall.height = qMax(overall.height, ymax - overall.y); overall.width = xmax - overall.x; return overall; }
glyph_metrics_t QFontEngineMac::boundingBox(const QGlyphLayout *glyphs, int numGlyphs) { QFixed w; const QGlyphLayout *end = glyphs + numGlyphs; while(end > glyphs) w += (--end)->advance.x; return glyph_metrics_t(0, -(ascent()), w, ascent()+descent(), w, 0); }
KHE_SOLN ils(KHE_SOLN soln, KHE_INSTANCE instance, Config &config) { soln = descent(soln, soln, instance, config.ilsBlMax, config); KHE_SOLN bestSoln = KheSolnCopy(soln); KHE_COST cost; int perturbationSize = config.ilsPertIni; int iters = 0; int neighborhood = 0; int pertubationChanges = 0; while (config.getRemainingTime() > 0 && pertubationChanges < config.ilsIters) { restartMoves(); for (int j = 0; j < perturbationSize; ++j) { neighborhood = rand() % 100 < 50 ? 6 : 7; generateNeighbor(soln, instance, neighborhood); } cost = KheSolnCost(soln); printf("PERTURBED Level %d Hard cost: %d Soft cost: %d\n", perturbationSize, KheHardCost(cost), KheSoftCost(cost)); soln = descent(soln, bestSoln, instance, config.ilsBlMax, config); // Houve melhora na solucao? if (isBetterSolution(soln, bestSoln)) { KheSolnDelete(bestSoln); bestSoln = KheSolnCopy(soln); perturbationSize = config.ilsPertIni; iters = 0; } else { KheSolnDelete(soln); soln = KheSolnCopy(bestSoln); iters++; } if (iters >= config.ilsMax) { iters = 0; perturbationSize = (config.ilsPertIni + 1) % (config.ilsPertMax + 1); pertubationChanges++; } } KheSolnDelete(soln); return bestSoln; }
glyph_metrics_t QFontEngineS60::boundingBox(const QGlyphLayout &glyphs) { if (glyphs.numGlyphs == 0) return glyph_metrics_t(); QFixed w = 0; for (int i = 0; i < glyphs.numGlyphs; ++i) w += glyphs.effectiveAdvance(i); return glyph_metrics_t(0, -ascent(), w, ascent()+descent()+1, w, 0); }
strategy_profile_t *run_descent(polymatrix_t *game, double delta) { int *scount = malloc(game->players * sizeof(int)); count_strategies(game, scount); //polymatrix_normalize(game, scount); strategy_profile_t *x = strategy_alloc(game->players, scount); strategy_profile_t *xp = descent(game, x, scount, delta); //double e1 = compute_eps(game, x, NULL); strategy_free(x); //strategy_print(xp); free(scount); return xp; }
void WGraph::print(FILE* file, const Interface& I) const /* Prints the graph on a file in ascii format. */ { const OrientedGraph& Y = *d_graph; int d = digits(size()-1,10); /* count number of edges */ Ulong count = 0; for (Vertex x = 0; x < size(); ++x) { const EdgeList& e = Y.edge(x); count += e.size(); } // find alignement String str(0); LFlags f = leqmask[I.rank()-1]; interface::append(str,f,I); Ulong descent_maxwidth = str.length(); fprintf(file,"%lu vertices, %lu edges\n\n",size(),count); for (Vertex x = 0; x < size(); ++x) { fprintf(file,"%*lu : ",d,x); io::reset(str); interface::append(str,descent(x),I); pad(str,descent_maxwidth ); io::print(file,str); fprintf(file," "); const EdgeList e = Y.edge(x); const CoeffList c = coeffList(x); for (Ulong j = 0; j < e.size(); ++j) { fprintf(file,"%lu(%lu)",e[j],static_cast<Ulong>(c[j])); if (j+1 < e.size()) /* there is more to come */ fprintf(file,","); } fprintf(file,"\n"); } }
/** linear regression for learning @dx: x_data @dy: y_data @w: first weight @alpha: learning rate @cnt: count for loop @m: count for data loop: O(cnt x m) return: learning weight */ f32 linear_learning(f32 *xd, f32 *yd, f32 w, f32 alpha, u32 cnt, u32 m) { f32 x, y, c, d; u32 i, j; printf("\n----------------------------------\n"); printf("Learning...\n"); for (i=0; i < cnt; i++) { d = 0.0; c = 0.0; for (j=0; j < m; j++) { x = *(xd + j); y = *(yd + j); c += cost(w, x, y); d += descent(x, y, w, alpha); } c = c / m; ///average cost(w) w = w - alpha * (d / m); ///average descent(w) printf("%4d: cost=%f, w=%f\n", i, c, w); } return w; }
float Font::floatWidthForSimpleText(const TextRun& run, GlyphBuffer* glyphBuffer, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const { WidthIterator it(this, run, fallbackFonts, glyphOverflow); it.advance(run.length(), glyphBuffer); if (glyphOverflow) { glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoundingBoxY()) - ascent()); glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(it.maxGlyphBoundingBoxY()) - descent()); glyphOverflow->left = ceilf(it.firstGlyphOverflow()); glyphOverflow->right = ceilf(it.lastGlyphOverflow()); } return it.m_runWidthSoFar; }
float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const { ComplexTextController controller(this, run, true, fallbackFonts); if (glyphOverflow) { glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-controller.minGlyphBoundingBoxY()) - ascent()); glyphOverflow->bottom = max<int>(glyphOverflow->bottom, ceilf(controller.maxGlyphBoundingBoxY()) - descent()); glyphOverflow->left = max<int>(0, ceilf(-controller.minGlyphBoundingBoxX())); glyphOverflow->right = max<int>(0, ceilf(controller.maxGlyphBoundingBoxX() - controller.totalWidth())); } return controller.totalWidth(); }