ScaleFactor ScalingFunction<KRPPKRP>::apply(const Position& pos) const { assert(pos.non_pawn_material(strongerSide) == RookValueMidgame); assert(pos.piece_count(strongerSide, PAWN) == 2); assert(pos.non_pawn_material(weakerSide) == RookValueMidgame); assert(pos.piece_count(weakerSide, PAWN) == 1); Square wpsq1 = pos.piece_list(strongerSide, PAWN, 0); Square wpsq2 = pos.piece_list(strongerSide, PAWN, 1); Square bksq = pos.king_square(weakerSide); // Does the stronger side have a passed pawn? if ( pos.pawn_is_passed(strongerSide, wpsq1) || pos.pawn_is_passed(strongerSide, wpsq2)) return SCALE_FACTOR_NONE; Rank r = Max(relative_rank(strongerSide, wpsq1), relative_rank(strongerSide, wpsq2)); if ( file_distance(bksq, wpsq1) <= 1 && file_distance(bksq, wpsq2) <= 1 && relative_rank(strongerSide, bksq) > r) { switch (r) { case RANK_2: return ScaleFactor(10); case RANK_3: return ScaleFactor(10); case RANK_4: return ScaleFactor(15); case RANK_5: return ScaleFactor(20); case RANK_6: return ScaleFactor(40); default: assert(false); } } return SCALE_FACTOR_NONE; }
bool TightBounds(const SkPath& path, SkRect* result) { SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune SkOpContour contour; SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour); SkOpGlobalState globalState(contourList, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr)); // turn path into list of segments SkScalar scaleFactor = ScaleFactor(path); SkPath scaledPath; const SkPath* workingPath; if (scaleFactor > SK_Scalar1) { ScalePath(path, 1.f / scaleFactor, &scaledPath); workingPath = &scaledPath; } else { workingPath = &path; } SkOpEdgeBuilder builder(*workingPath, &contour, &globalState); if (!builder.finish()) { return false; } if (!SortContourList(&contourList, false, false)) { result->setEmpty(); return true; } SkOpContour* current = contourList; SkPathOpsBounds bounds = current->bounds(); while ((current = current->next())) { bounds.add(current->bounds()); } *result = bounds; return true; }
void List::UpdateTopIndex() { itemHeight = 18.0f / ScaleFactor(); const int numDisplay = NumDisplay(); if(topIndex + numDisplay > filteredItems->size()) topIndex = std::max(0, (int)filteredItems->size() - numDisplay); }
int main(int argc, char *argv[]) { int w,h; Rect gb; HNN=MakeHashTable(); HEL=MakeHashTable(); HLI=MakeHashTable(); HVC=MakeHashTable(); CM=MakeQueueTable(); SetOptions(argc,argv); ReadFiles(argc,argv); CheckNodes(HNN,HEL,HLI,HVC); if( OpCheck ) CheckMore(HNN,HEL,HLI); InitMinMax(&gb); GetNodeMinMax(HNN,&gb); GetNodeMinMax(HVC,&gb); SetMinMax(&gb); printf("Min/Max values : %f %f %f %f\n", gb.low.x,gb.low.y,gb.high.x,gb.high.y); printf("Center values : %f %f \n", (gb.low.x+gb.high.x)/2.,(gb.low.y+gb.high.y)/2.); GbAll = GbPlo = gb; QGraphInit(); QNewPen(PlotCol); SetColors(OpCol); QWindowMaxXY(&w,&h); ResizeWindow(w,h); ScaleFactor(HVC); MakeGridMenu(); /* MouseInit(); */ QInitEvent(); LoopForInput(); QGraphClose(); WriteFiles(); return 0; }
CSize CNtMagickView::Scale(CSize sizeSrc, CSize sizeTgt) { CSize size; // Obtain the scaling factor float fScale = ScaleFactor(FALSE,sizeSrc,sizeTgt); // Calculate the size of the sized rectangle size.cx = ((float) sizeSrc.cx * fScale) + 0.5; size.cy = ((float) sizeSrc.cy * fScale) + 0.5; // Ensure roundings errors don't make scaled rectangle too large if (size.cx > sizeTgt.cx) { size.cx = sizeTgt.cx; } if (size.cy > sizeTgt.cy) { size.cy = sizeTgt.cy; } // Return dimensions of the rectangle return size; }
void DataSet::LoadFile() { TFile F(RootFilePath_); // F.ls(); TH1F *RefHistogram = (TH1F*) F.Get(ReferenceHistogramPath_); SetNumberOfGeneratedEvents( RefHistogram->GetEntries()) ; if(NumberOfGeneratedEvents()) SetScaleFactor( Luminosity() * CrossSection() / NumberOfGeneratedEvents() ); else std::cout << "ERROR : No Events/Entries in Reference Histogram with name " << ReferenceHistogramPath_ << endl; SetNumberOfScaledEvents( NumberOfGeneratedEvents() * ScaleFactor() ); F.Close(); }
std::vector<RingElem> BM_QQ(const SparsePolyRing& P, const ConstMatrixView& pts_in) { const long NumPts = NumRows(pts_in); const long dim = NumCols(pts_in); matrix pts = NewDenseMat(RingQQ(), NumPts, dim); for (long i=0; i < NumPts; ++i) for (long j=0; j < dim; ++j) { BigRat q; if (!IsRational(q, pts_in(i,j))) throw 999; SetEntry(pts,i,j, q); } // Ensure input pts have integer coords by using // scale factors for each indet. vector<BigInt> ScaleFactor(dim, BigInt(1)); for (long j=0; j < dim; ++j) for (long i=0; i < NumPts; ++i) ScaleFactor[j] = lcm(ScaleFactor[j], ConvertTo<BigInt>(den(pts(i,j)))); mpz_t **points = (mpz_t**)malloc(NumPts*sizeof(mpz_t*)); for (long i=0; i < NumPts; ++i) { points[i] = (mpz_t*)malloc(dim*sizeof(mpz_t)); for (long j=0; j < dim; ++j) mpz_init(points[i][j]); for (long j=0; j < dim; ++j) { mpz_set(points[i][j], mpzref(ConvertTo<BigInt>(ScaleFactor[j]*pts(i,j)))); } } BMGB char0; // these will be "filled in" by BM_affine below BM modp; // pp_cmp_PPM = &PPM(P); // not threadsafe! BM_affine(&char0, &modp, dim, NumPts, points, pp_cmp); // THIS CALL DOES THE REAL WORK!!! pp_cmp_PPM = NULL; for (long i=NumPts-1; i >=0 ; --i) { for (long j=0; j < dim; ++j) mpz_clear(points[i][j]); free(points[i]); } free(points); if (modp == NULL) { if (char0 != NULL) BMGB_dtor(char0); CoCoA_ERROR("Something went wrong", "BM_QQ"); } // Now extract the answer... const int GBsize = char0->GBsize; std::vector<RingElem> GB(GBsize); const long NumVars = dim; vector<long> expv(NumVars); // buffer for creating monomials for (int i=0; i < GBsize; ++i) { BigInt denom(1); // scale factor needed to make GB elem monic. for (int var = 0; var < NumVars; ++var) { expv[var] = modp->pp[modp->GB[i]][var]; denom *= power(ScaleFactor[var], expv[var]); } RingElem GBelem = monomial(P, 1, expv); for (int j=0; j < NumPts; ++j) { if (mpq_sgn(char0->GB[i][j])==0) continue; BigRat c(char0->GB[i][j]); for (int var = 0; var < NumVars; ++var) { expv[var] = modp->pp[modp->sep[j]][var]; c *= power(ScaleFactor[var], expv[var]); } GBelem += monomial(P, c/denom, expv); } GB[i] = GBelem; } BMGB_dtor(char0); BM_dtor(modp); return GB; // ignoring separators for the moment }
void WriteScaleFactor(ostream& stream) { stream << " scaleFactors[\"" << m_sr << "\"] = " << ScaleFactor() << "; // (" << m_data << " - " << m_nonqcd << ")/" << m_smear << endl; stream << " cout << \"scaleFactor for " << m_sr << " is \" << scaleFactors[\"" << m_sr << "\"] << endl;" << endl; stream << " scaleFactors[\"" << m_cr << "\"] = " << ScaleFactor() << "; // (" << m_data << " - " << m_nonqcd << ")/" << m_smear << endl; stream << " cout << \"scaleFactor for " << m_cr << " is \" << scaleFactors[\"" << m_cr << "\"] << endl;" << endl; }
void GuiderOneStar::OnLClick(wxMouseEvent &mevent) { try { if (mevent.GetModifiers() == wxMOD_CONTROL) { double const scaleFactor = ScaleFactor(); wxRealPoint pt((double) mevent.m_x / scaleFactor, (double) mevent.m_y / scaleFactor); ToggleBookmark(pt); m_showBookmarks = true; pFrame->bookmarks_menu->Check(MENU_BOOKMARKS_SHOW, GetBookmarksShown()); Refresh(); Update(); return; } if (GetState() > STATE_SELECTED) { mevent.Skip(); throw THROW_INFO("Skipping event because state > STATE_SELECTED"); } if (mevent.GetModifiers() == wxMOD_SHIFT) { // Deselect guide star InvalidateCurrentPosition(true); } else { if ((mevent.m_x <= m_searchRegion) || (mevent.m_x + m_searchRegion >= XWinSize) || (mevent.m_y <= m_searchRegion) || (mevent.m_y + m_searchRegion >= YWinSize)) { mevent.Skip(); throw THROW_INFO("Skipping event because click outside of search region"); } usImage *pImage = CurrentImage(); if (pImage->NPixels == 0) { mevent.Skip(); throw ERROR_INFO("Skipping event m_pCurrentImage->NPixels == 0"); } double scaleFactor = ScaleFactor(); double StarX = (double) mevent.m_x / scaleFactor; double StarY = (double) mevent.m_y / scaleFactor; SetCurrentPosition(pImage, PHD_Point(StarX, StarY)); if (!m_star.IsValid()) { pFrame->SetStatusText(wxString::Format(_("No star found"))); } else { SetLockPosition(m_star); pFrame->SetStatusText(wxString::Format(_("Selected star at (%.1f, %.1f)"), m_star.X, m_star.Y), 1); pFrame->SetStatusText(wxString::Format(_T("m=%.0f SNR=%.1f"), m_star.Mass, m_star.SNR)); EvtServer.NotifyStarSelected(CurrentPosition()); SetState(STATE_SELECTED); pFrame->UpdateButtonsStatus(); pFrame->pProfile->UpdateData(pImage, m_star.X, m_star.Y); } Refresh(); Update(); } } catch (wxString Msg) { POSSIBLY_UNUSED(Msg); } }
void List::DrawSelf() { const float opacity = Opacity(); font->Begin(); float hf = font->GetSize() / ScaleFactor(); font->SetTextColor(1,1,0.4f,opacity); int nCurIndex = 0; // The item we're on int nDrawOffset = 0; // The offset to the first draw item GuiElement b; b.SetPos(pos[0] + borderSpacing, pos[1] + size[1] - borderSpacing - itemHeight); b.SetSize(size[0] - 2.0f * borderSpacing - ((scrollbar.GetSize()[0] < 0) ? 0 : (itemHeight + itemSpacing)), itemHeight); // Get list started up here std::vector<std::string>::iterator ii = filteredItems->begin(); // Skip to current selection - 3; ie: scroll UpdateTopIndex(); while (nCurIndex < topIndex) { ++ii; nCurIndex++; } const int numDisplay = NumDisplay(); font->SetTextColor(1.0f, 1.0f, 1.0f, opacity); //default font->SetOutlineColor(0.0f, 0.0f, 0.0f, opacity); glLineWidth(1.0f); float sbX = b.GetPos()[0]; float sbY1 = b.GetPos()[1] + (itemHeight + itemSpacing); for (/*ii = items.begin()*/; ii != filteredItems->end() && nDrawOffset < numDisplay; ++ii) { glColor4f(1,1,1,opacity/4.f); b.DrawBox(GL_LINE_LOOP); if (nCurIndex == place) { glBlendFunc(GL_ONE, GL_ONE); // additive blending glColor4f(0.2f,0,0,opacity); b.DrawBox(GL_QUADS); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,0,0,opacity/2.f); glLineWidth(1.49f); b.DrawBox(GL_LINE_LOOP); glLineWidth(1.0f); } else if (b.MouseOver(mx, my)) { glBlendFunc(GL_ONE, GL_ONE); // additive blending glColor4f(0,0,0.2f,opacity); b.DrawBox(GL_QUADS); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,opacity/2.f); glLineWidth(1.49f); b.DrawBox(GL_LINE_LOOP); glLineWidth(1.0f); } font->glPrint(pos[0]+borderSpacing + 0.002f, b.GetMidY() - hf * 0.15f, itemFontScale, FONT_BASELINE | FONT_SHADOW | FONT_SCALE | FONT_NORM, *ii); // Up our index's nCurIndex++; nDrawOffset++; b.Move(0.0, - (itemHeight + itemSpacing)); } //scrollbar if(nDrawOffset < filteredItems->size()) { float sbY2 = b.GetPos()[1] + (itemHeight + itemSpacing); float sbHeight = sbY1 - sbY2; float sbSize = ((float)nDrawOffset / (float)filteredItems->size()) * sbHeight; if(activeScrollbar) { topIndex = std::max(0, std::min((int)(((float)filteredItems->size() * ((sbY1 - sbSize) - (my - std::min(scrollbarGrabPos, sbSize))) / sbHeight) + 0.5f), (int)filteredItems->size() - numDisplay)); } scrollbar.SetPos(sbX + (size[0] - 2.0f * borderSpacing) - (itemHeight + itemSpacing), sbY1 - sbSize - ((float)topIndex / (float)filteredItems->size()) * sbHeight); scrollbar.SetSize((itemHeight + itemSpacing) , sbSize); b.SetPos(scrollbar.GetPos()[0], sbY2); b.SetSize(itemHeight + itemSpacing, sbHeight); glColor4f(1,1,1,opacity/4.f); b.DrawBox(GL_LINE_LOOP); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(0.8f,0.8f,0.8f,opacity); scrollbar.DrawBox(GL_QUADS); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1,1,1,opacity/2.f); glLineWidth(1.49f); scrollbar.DrawBox(GL_LINE_LOOP); glLineWidth(1.0f); } else scrollbar.SetSize(-1,-1); /************** * End insert * **************/ font->End(); }
ScaleFactor ScalingFunction<KRPKR>::apply(const Position& pos) const { assert(pos.non_pawn_material(strongerSide) == RookValueMidgame); assert(pos.piece_count(strongerSide, PAWN) == 1); assert(pos.non_pawn_material(weakerSide) == RookValueMidgame); assert(pos.piece_count(weakerSide, PAWN) == 0); Square wksq = pos.king_square(strongerSide); Square wrsq = pos.piece_list(strongerSide, ROOK, 0); Square wpsq = pos.piece_list(strongerSide, PAWN, 0); Square bksq = pos.king_square(weakerSide); Square brsq = pos.piece_list(weakerSide, ROOK, 0); // Orient the board in such a way that the stronger side is white, and the // pawn is on the left half of the board. if (strongerSide == BLACK) { wksq = flip_square(wksq); wrsq = flip_square(wrsq); wpsq = flip_square(wpsq); bksq = flip_square(bksq); brsq = flip_square(brsq); } if (square_file(wpsq) > FILE_D) { wksq = flop_square(wksq); wrsq = flop_square(wrsq); wpsq = flop_square(wpsq); bksq = flop_square(bksq); brsq = flop_square(brsq); } File f = square_file(wpsq); Rank r = square_rank(wpsq); Square queeningSq = make_square(f, RANK_8); int tempo = (pos.side_to_move() == strongerSide); // If the pawn is not too far advanced and the defending king defends the // queening square, use the third-rank defence. if ( r <= RANK_5 && square_distance(bksq, queeningSq) <= 1 && wksq <= SQ_H5 && (square_rank(brsq) == RANK_6 || (r <= RANK_3 && square_rank(wrsq) != RANK_6))) return SCALE_FACTOR_ZERO; // The defending side saves a draw by checking from behind in case the pawn // has advanced to the 6th rank with the king behind. if ( r == RANK_6 && square_distance(bksq, queeningSq) <= 1 && square_rank(wksq) + tempo <= RANK_6 && (square_rank(brsq) == RANK_1 || (!tempo && abs(square_file(brsq) - f) >= 3))) return SCALE_FACTOR_ZERO; if ( r >= RANK_6 && bksq == queeningSq && square_rank(brsq) == RANK_1 && (!tempo || square_distance(wksq, wpsq) >= 2)) return SCALE_FACTOR_ZERO; // White pawn on a7 and rook on a8 is a draw if black's king is on g7 or h7 // and the black rook is behind the pawn. if ( wpsq == SQ_A7 && wrsq == SQ_A8 && (bksq == SQ_H7 || bksq == SQ_G7) && square_file(brsq) == FILE_A && (square_rank(brsq) <= RANK_3 || square_file(wksq) >= FILE_D || square_rank(wksq) <= RANK_5)) return SCALE_FACTOR_ZERO; // If the defending king blocks the pawn and the attacking king is too far // away, it's a draw. if ( r <= RANK_5 && bksq == wpsq + DELTA_N && square_distance(wksq, wpsq) - tempo >= 2 && square_distance(wksq, brsq) - tempo >= 2) return SCALE_FACTOR_ZERO; // Pawn on the 7th rank supported by the rook from behind usually wins if the // attacking king is closer to the queening square than the defending king, // and the defending king cannot gain tempi by threatening the attacking rook. if ( r == RANK_7 && f != FILE_A && square_file(wrsq) == f && wrsq != queeningSq && (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo) && (square_distance(wksq, queeningSq) < square_distance(bksq, wrsq) + tempo)) return ScaleFactor(SCALE_FACTOR_MAX - 2 * square_distance(wksq, queeningSq)); // Similar to the above, but with the pawn further back if ( f != FILE_A && square_file(wrsq) == f && wrsq < wpsq && (square_distance(wksq, queeningSq) < square_distance(bksq, queeningSq) - 2 + tempo) && (square_distance(wksq, wpsq + DELTA_N) < square_distance(bksq, wpsq + DELTA_N) - 2 + tempo) && ( square_distance(bksq, wrsq) + tempo >= 3 || ( square_distance(wksq, queeningSq) < square_distance(bksq, wrsq) + tempo && (square_distance(wksq, wpsq + DELTA_N) < square_distance(bksq, wrsq) + tempo)))) return ScaleFactor( SCALE_FACTOR_MAX - 8 * square_distance(wpsq, queeningSq) - 2 * square_distance(wksq, queeningSq)); // If the pawn is not far advanced, and the defending king is somewhere in // the pawn's path, it's probably a draw. if (r <= RANK_4 && bksq > wpsq) { if (square_file(bksq) == square_file(wpsq)) return ScaleFactor(10); if ( abs(square_file(bksq) - square_file(wpsq)) == 1 && square_distance(wksq, bksq) > 2) return ScaleFactor(24 - 2 * square_distance(wksq, bksq)); } return SCALE_FACTOR_NONE; }