int Euler54::compute_best_hand(Euler54::Hand _hand){ if(royal_flush(_hand)){ std::cout << "Royal Flush" << std::endl; return 10; }else if(straight_flush(_hand)){ std::cout << "Straight Flush" << std::endl; return 9; }else if(quads(_hand)){ std::cout << "Quads" << std::endl; return 8; }else if(full_house(_hand)){ std::cout << "Full House" << std::endl; return 7; }else if(flush(_hand)){ std::cout << "Flush" << std::endl; return 6; }else if(straight(_hand)){ std::cout << "Straight" << std::endl; return 5; }else if(trips(_hand)){ std::cout << "Trips" << std::endl; return 4; }else if(two_pair(_hand)){ std::cout << "Two Pair" << std::endl; return 3; }else if(pair(_hand, 0)){ std::cout << "Pair" << std::endl; return 2; }else{ set_highest_card(highest_card(_hand)); std::cout << "you have the high card " << print_card(current_highest_card) << std::endl; return 1; std::cout << " you got squat " << std::endl; } }
PassRefPtr<ClientRectList> Page::nonFastScrollableRects(const Frame* frame) { if (Document* document = m_mainFrame->document()) document->updateLayout(); Vector<IntRect> rects; if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) rects = scrollingCoordinator->computeShouldHandleScrollGestureOnMainThreadRegion(frame, IntPoint()).rects(); Vector<FloatQuad> quads(rects.size()); for (size_t i = 0; i < rects.size(); ++i) quads[i] = FloatRect(rects[i]); return ClientRectList::create(quads); }
SPtr<Texture> TextRenderer::renderToTexture(const char *text, int *textureWidth, int *textureHeight) { if (!atlas->isGenerated()) { bool generated = atlas->generate(); if (!generated) { return nullptr; } } float width, height; std::vector<GlyphQuad> quads(atlas->process(text, &width, &height)); if (textureWidth) { *textureWidth = static_cast<int>(glm::ceil(width)); } if (textureHeight) { *textureHeight = static_cast<int>(glm::ceil(height)); } const char *uProjMatrix = "uProjMatrix"; if (model.getProgram()->hasUniform(uProjMatrix)) { // stb_truetype generates the bitmap top-down, but we need it to be bottom-up, // so just flip the y values using the projection matrix model.getProgram()->setUniformValue(uProjMatrix, glm::ortho<float>(0.0f, width, height, 0.0f)); } framebuffer.init(static_cast<int>(glm::ceil(width)), static_cast<int>(glm::ceil(height))); framebuffer.use(); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_DEPTH_TEST); textureMaterial->setTexture(atlas->getTexture()); FontSpacing spacing = atlas->getFontSpacing(); for (const GlyphQuad &quad : quads) { render(quad, model, spacing.descent); } glEnable(GL_DEPTH_TEST); framebuffer.disable(); return framebuffer.getTexture(); }
int main() { std::vector<int> numbers{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; std::cout << "Numbers: " << numbers << ".\n"; std::function<bool (int)> isEven = [](int i) { return i % 2 == 0; }; auto evenCount = std::count_if(numbers.begin(), numbers.end(), isEven); std::cout << "Vector contains " << evenCount << " even numbers.\n"; std::vector<int> evenNumbers(evenCount); std::copy_if(numbers.begin(), numbers.end(), evenNumbers.begin(), isEven); std::cout << "Even numbers are: " << evenNumbers << ".\n"; std::function<int (int)> quad = [] (int x) { return x*x; }; std::vector<int> quads(numbers.size()); std::transform(numbers.begin(), numbers.end(), quads.begin(), quad); std::cout << "Quads: " << quads << ".\n"; return 0; }
std::unique_ptr<StyledMesh> TextStyleBuilder::build() { if (m_quads.empty()) { return nullptr; } if (Tangram::getDebugFlag(DebugFlags::draw_all_labels)) { m_textLabels->setLabels(m_labels); std::vector<GlyphQuad> quads(m_quads); m_textLabels->setQuads(std::move(quads), m_atlasRefs); } else { // TODO this could probably done more elegant int quadPos = 0; size_t sumQuads = 0; size_t sumLabels = 0; bool added = false; // Determine number of labels and size of final quads vector for (auto& label : m_labels) { auto* textLabel = static_cast<TextLabel*>(label.get()); auto& ranges = textLabel->textRanges(); bool active = textLabel->state() != Label::State::dead; if (ranges.back().end() != quadPos) { quadPos = ranges.back().end(); added = false; } if (!active) { continue; } sumLabels +=1; if (!added) { added = true; for (auto& textRange : ranges) { sumQuads += textRange.length; } } } size_t quadEnd = 0; size_t quadStart = 0; quadPos = 0; std::vector<std::unique_ptr<Label>> labels; labels.reserve(sumLabels); std::vector<GlyphQuad> quads; quads.reserve(sumQuads); // Add only alive labels for (auto& label : m_labels) { auto* textLabel = static_cast<TextLabel*>(label.get()); bool active = textLabel->state() != Label::State::dead; if (!active) { continue; } auto& ranges = textLabel->textRanges(); // Add the quads of line-labels only once if (ranges.back().end() != quadPos) { quadStart = quadEnd; quadPos = ranges.back().end(); for (auto& textRange : ranges) { if (textRange.length > 0) { quadEnd += textRange.length; auto it = m_quads.begin() + textRange.start; quads.insert(quads.end(), it, it + textRange.length); } } } // Update TextRange auto start = quadStart; for (auto& textRange : ranges) { textRange.start = start; start += textRange.length; } labels.push_back(std::move(label)); } m_textLabels->setLabels(labels); m_textLabels->setQuads(std::move(quads), m_atlasRefs); } m_labels.clear(); m_quads.clear(); return std::move(m_textLabels); }
void GxTextRenderer::myDrawText(float x, float y) { const int lineCount = (int)myLines.size(); const Glyph& period = myFont->GetGlyph('.'); // Count the total number of quads and the number of quads per glyph page. const int pageCount = myFont->glyphPageCount; std::vector<PageQuads> quads(pageCount); myResetPos(); int quadTotal = 0; for(int l=0; l<lineCount; ++l) { // Count the number of glyph quads. const Line& line = myLines[l]; mySkipTo(line.begin); while(myReadPos < line.end) { const Glyph& glyph = myNextChar(); if(myInRange() && NonWhitespace(glyph)) { if(glyph.page >= 0) ++quads[glyph.page].count; ++quadTotal; } } // If there are ellipsis, count three extra quads. if(line.ellipsis) { quads[period.page].count += 3; quadTotal += 3; } } if(quadTotal == 0) return; // If there is a shadow effect, each quad has an additional shadow quad. if(myColorS.a) { for(int i=0; i<pageCount; ++i) quads[i].count *= 2; quadTotal *= 2; } // Draw underlines before the rest of the glyphs are drawn. if(myHasUnderlines) myDrawUnderlines(x, y); // Assign each glyph page a portion of the allocated vertices. myResizeBuffers(quadTotal); for(int i=0, j=0; i<pageCount; ++i) { quads[i].index = j; j += quads[i].count; } // Fill in the vertex data and make a list of custom glyphs, which are rendered afterwards. myResetPos(); myCustomGlyphs.clear(); for(int l=0; l<lineCount; ++l) { const Line& line = myLines[l]; Pen pen = { 0, 0, line.spacemul }; const float ox = x + GetOffsetX(myAlignH, line.width); const float oy = y + (float)((l+1) * myFont->fontSize); mySkipTo(line.begin); while(myReadPos < line.end) { // If this is a printable character, we will emit a quad for it. const Glyph& glyph = myNextChar(); myAdvance(pen, glyph); if(myInRange() && NonWhitespace(glyph)) { if(glyph.page >= 0) myEmitQuad(glyph, quads[glyph.page].index, ox + pen.x, oy); else myCustomGlyphs.push_back(CGGxRecti(&glyph, ox + pen.x, oy)); } } // If there are ellipsis, emit quads for them. if(line.ellipsis) { pen.x += pen.advance; int& index = quads[period.page].index; for(int j=0; j<3; ++j, pen.x += period.xAdvance) myEmitQuad(period, index, ox + pen.x, oy); } } // Finally it's time to render the glyph vertices. for(int i=0, idx=0, count=0; i<pageCount; ++i) { if(count = quads[i].count*6) myRenderQuads(idx, count, myFont->glyphPages[i].texture); idx += count; } // And after that, render the custom glyphs. if(myCustomGlyphs.size() > 0) { myResizeBuffers(8); GxFontDatabaseImp* database = GxFontDatabaseImp::singleton; for(size_t i=0; i<myCustomGlyphs.size(); ++i) { int idx = 0; const CGGxRecti& r = myCustomGlyphs[i]; myEmitQuad(*myCustomGlyphs[i].glyph, idx, r.x, r.y); myRenderQuads(0, idx*6, database->GetCustomGlyphTexture(r.glyph)); } } }
STKUNIT_UNIT_TEST(UnitTestZoltanSimple, testUnit) { #ifdef STK_HAS_MPI stk::ParallelMachine comm(MPI_COMM_WORLD); #else stk::ParallelMachine comm(0); #endif unsigned spatial_dimension = 2; std::vector<std::string> rank_names = stk::mesh::fem::entity_rank_names(spatial_dimension); const stk::mesh::EntityRank constraint_rank = rank_names.size(); rank_names.push_back("Constraint"); stk::mesh::fem::FEMMetaData fem_meta; fem_meta.FEM_initialize( spatial_dimension, rank_names ); stk::mesh::MetaData & meta_data = stk::mesh::fem::FEMMetaData::get_meta_data(fem_meta); stk::mesh::BulkData bulk_data( meta_data , comm , 100 ); const stk::mesh::EntityRank element_rank = fem_meta.element_rank(); stk::mesh::fem::CellTopology quad_top(shards::getCellTopologyData<shards::Quadrilateral<4> >()); stk::mesh::Part & quad_part( fem_meta.declare_part("quad", quad_top ) ); VectorField & coord_field( fem_meta.declare_field< VectorField >( "coordinates" ) ); ScalarField & weight_field( fem_meta.declare_field< ScalarField >( "element_weights" ) ); stk::mesh::put_field( coord_field , NODE_RANK , fem_meta.universal_part() ); stk::mesh::put_field(weight_field , element_rank , fem_meta.universal_part() ); fem_meta.commit(); const unsigned p_size = bulk_data.parallel_size(); const unsigned p_rank = bulk_data.parallel_rank(); bulk_data.modification_begin(); if ( p_rank == 0 ) { std::vector<std::vector<stk::mesh::Entity*> > quads(nx); for ( unsigned ix = 0 ; ix < nx ; ++ix ) quads[ix].resize(ny); const unsigned nnx = nx + 1 ; const unsigned nny = ny + 1 ; for ( unsigned iy = 0 ; iy < ny ; ++iy ) { for ( unsigned ix = 0 ; ix < nx ; ++ix ) { stk::mesh::EntityId elem = 1 + ix + iy * nx ; stk::mesh::EntityId nodes[4] ; nodes[0] = 1 + ix + iy * nnx ; nodes[1] = 2 + ix + iy * nnx ; nodes[2] = 2 + ix + ( iy + 1 ) * nnx ; nodes[3] = 1 + ix + ( iy + 1 ) * nnx ; stk::mesh::Entity &q = stk::mesh::fem::declare_element( bulk_data , quad_part , elem , nodes ); quads[ix][iy] = &q; } } for ( unsigned iy = 0 ; iy < ny ; ++iy ) { for ( unsigned ix = 0 ; ix < nx ; ++ix ) { stk::mesh::EntityId elem = 1 + ix + iy * nx ; stk::mesh::Entity * e = bulk_data.get_entity( element_rank, elem ); double * const e_weight = stk::mesh::field_data( weight_field , *e ); *e_weight = 1.0; } } for ( unsigned iy = 0 ; iy <= ny ; ++iy ) { for ( unsigned ix = 0 ; ix <= nx ; ++ix ) { stk::mesh::EntityId nid = 1 + ix + iy * nnx ; stk::mesh::Entity * n = bulk_data.get_entity( NODE_RANK, nid ); double * const coord = stk::mesh::field_data( coord_field , *n ); coord[0] = .1*ix; coord[1] = .1*iy; coord[2] = 0; } } { const unsigned iy_left = 0; const unsigned iy_right = ny; stk::mesh::PartVector add(1, &fem_meta.locally_owned_part()); for ( unsigned ix = 0 ; ix <= nx ; ++ix ) { stk::mesh::EntityId nid_left = 1 + ix + iy_left * nnx ; stk::mesh::EntityId nid_right = 1 + ix + iy_right * nnx ; stk::mesh::Entity * n_left = bulk_data.get_entity( NODE_RANK, nid_left ); stk::mesh::Entity * n_right = bulk_data.get_entity( NODE_RANK, nid_right ); const stk::mesh::EntityId constraint_entity_id = 1 + ix + nny * nnx; stk::mesh::Entity & c = bulk_data.declare_entity( constraint_rank, constraint_entity_id, add ); bulk_data.declare_relation( c , *n_left , 0 ); bulk_data.declare_relation( c , *n_right , 1 ); } } } // Only P0 has any nodes or elements if ( p_rank == 0 ) { STKUNIT_ASSERT( ! bulk_data.buckets( NODE_RANK ).empty() ); STKUNIT_ASSERT( ! bulk_data.buckets( element_rank ).empty() ); } else { STKUNIT_ASSERT( bulk_data.buckets( NODE_RANK ).empty() ); STKUNIT_ASSERT( bulk_data.buckets( element_rank ).empty() ); } bulk_data.modification_end(); // create some sides and faces to rebalance. stk::mesh::PartVector add_parts; stk::mesh::create_adjacent_entities(bulk_data, add_parts); // Zoltan partition is specialized fomm a virtual base class, stk::rebalance::Partition. // Other specializations are possible. Teuchos::ParameterList emptyList; stk::rebalance::Zoltan zoltan_partition(comm, spatial_dimension, emptyList); { stk::mesh::Selector selector(fem_meta.universal_part()); stk::rebalance::rebalance(bulk_data, selector, &coord_field, &weight_field, zoltan_partition); } const double imbalance_threshold = stk::rebalance::check_balance(bulk_data, &weight_field, element_rank); const bool do_rebal = 1.5 < imbalance_threshold; // Check that we satisfy our threshhold STKUNIT_ASSERT( !do_rebal ); if( (2 == p_size) || (4 == p_size) ) { STKUNIT_ASSERT_NEAR(imbalance_threshold, 1.0, 1.e-8); } else { STKUNIT_ASSERT_LE(imbalance_threshold, 1.5); } // And verify that all dependent entities are on the same proc as their parent element { stk::mesh::EntityVector entities; stk::mesh::Selector selector = fem_meta.locally_owned_part(); get_selected_entities(selector, bulk_data.buckets(NODE_RANK), entities); bool result = stk::rebalance::verify_dependent_ownership(element_rank, entities); //get_selected_entities(selector, bulk_data.buckets(constraint_rank), entities); //result &= stk::rebalance::verify_dependent_ownership(element_rank, entities); STKUNIT_ASSERT( result ); } }
bool GrAAHairLinePathRenderer::createGeom(GrDrawTarget::StageBitfield stages) { int rtHeight = fTarget->getRenderTarget()->height(); GrIRect clip; if (fTarget->getClip().hasConservativeBounds()) { GrRect clipRect = fTarget->getClip().getConservativeBounds(); clipRect.roundOut(&clip); } else { clip.setLargest(); } // If none of the inputs that affect generation of path geometry have // have changed since last previous path draw then we can reuse the // previous geoemtry. if (stages == fPreviousStages && fPreviousViewMatrix == fTarget->getViewMatrix() && fPreviousTranslate == fTranslate && rtHeight == fPreviousRTHeight && fClipRect == clip) { return true; } GrVertexLayout layout = GrDrawTarget::kEdge_VertexLayoutBit; for (int s = 0; s < GrDrawTarget::kNumStages; ++s) { if ((1 << s) & stages) { layout |= GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(s); } } GrMatrix viewM = fTarget->getViewMatrix(); SkAlignedSTStorage<128, GrPoint> lineStorage; SkAlignedSTStorage<128, GrPoint> quadStorage; PtArray lines(&lineStorage); PtArray quads(&quadStorage); IntArray qSubdivs; fQuadCnt = generate_lines_and_quads(*fPath, viewM, fTranslate, clip, &lines, &quads, &qSubdivs); fLineSegmentCnt = lines.count() / 2; int vertCnt = kVertsPerLineSeg * fLineSegmentCnt + kVertsPerQuad * fQuadCnt; GrAssert(sizeof(Vertex) == GrDrawTarget::VertexSize(layout)); Vertex* verts; if (!fTarget->reserveVertexSpace(layout, vertCnt, (void**)&verts)) { return false; } Vertex* base = verts; const GrMatrix* toDevice = NULL; const GrMatrix* toSrc = NULL; GrMatrix ivm; if (viewM.hasPerspective()) { if (viewM.invert(&ivm)) { toDevice = &viewM; toSrc = &ivm; } } for (int i = 0; i < fLineSegmentCnt; ++i) { add_line(&lines[2*i], rtHeight, toSrc, &verts); } int unsubdivQuadCnt = quads.count() / 3; for (int i = 0; i < unsubdivQuadCnt; ++i) { GrAssert(qSubdivs[i] >= 0); add_quads(&quads[3*i], qSubdivs[i], toDevice, toSrc, &verts); } fPreviousStages = stages; fPreviousViewMatrix = fTarget->getViewMatrix(); fPreviousRTHeight = rtHeight; fClipRect = clip; fPreviousTranslate = fTranslate; return true; }