bool QCString::stripPrefix(const char *prefix) { if (prefix==0 || length()==0) return FALSE; int len = qstrlen(prefix); if (qstrncmp(prefix,data(),len)==0) { m_rep=mid(len,length()-len).m_rep; // need to make a deep copy return TRUE; } return FALSE; }
void s() { long ans=0; qsort(a,n,sizeof(long),cmp); for(int i=0; i<n; i++) { long lm=m-a[i]+1; int add=mid(0,i,lm); // printf("%d,%d\n",lm,add); ans=(ans+add)%B; } printf("%d\n",ans); }
void FibHeapBenchmark::GenerateWorsCase(int randRange) // using vector for the speed { QTime mid(0,0,0); qsrand( mid.secsTo(QTime::currentTime()) ); int randomNumber = 0; for(int i = 0; i < aloccSize; ++i) { randomNumber = (qrand() % randRange)+1; // ne zelimo kljuca ki je manjsi od ena array[i] = this->Insert(randomNumber);//new FNode(randomNumber);//this->Insert(randomNumber); } }
FVector FPoly::GetMidPoint() { FVector mid(0,0,0); for( int32 v = 0 ; v < Vertices.Num() ; ++v ) { mid += Vertices[v]; } return mid / Vertices.Num(); }
int test_mul() { int Error(0); float const Epsilon = 0.0001f; glm::mat4x4 mid(1.0f); for (int j = 0; j < 100; ++j) { // generate random rotations and translations and compare transformed by matrix and dualquats random points glm::vec3 vt1 = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f); glm::vec3 vt2 = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f); glm::mat4x4 rot1 = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f); glm::mat4x4 rot2 = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f); glm::mat4x4 m1 = glm::translate(mid, vt1) * rot1; glm::mat4x4 m2 = glm::translate(mid, vt2) * rot2; glm::mat4x4 m3 = m2 * m1; glm::mat4x4 m4 = m1 * m2; glm::quat qrot1 = glm::quat_cast(rot1); glm::quat qrot2 = glm::quat_cast(rot2); glm::dualquat dq1 = glm::dualquat(qrot1,vt1); glm::dualquat dq2 = glm::dualquat(qrot2,vt2); glm::dualquat dq3 = dq2 * dq1; glm::dualquat dq4 = dq1 * dq2; for (int i = 0; i < 100; ++i) { glm::vec4 src_pt = glm::vec4(myfrand() * 4.0f, myfrand() * 5.0f, myfrand() * 3.0f,1.0f); // test both multiplication orders glm::vec4 dst_pt_m3 = m3 * src_pt; glm::vec4 dst_pt_dq3 = dq3 * src_pt; glm::vec4 dst_pt_m3_i = glm::inverse(m3) * src_pt; glm::vec4 dst_pt_dq3_i = src_pt * dq3; glm::vec4 dst_pt_m4 = m4 * src_pt; glm::vec4 dst_pt_dq4 = dq4 * src_pt; glm::vec4 dst_pt_m4_i = glm::inverse(m4) * src_pt; glm::vec4 dst_pt_dq4_i = src_pt * dq4; Error += glm::all(glm::epsilonEqual(dst_pt_m3, dst_pt_dq3, Epsilon)) ? 0 : 1; Error += glm::all(glm::epsilonEqual(dst_pt_m4, dst_pt_dq4, Epsilon)) ? 0 : 1; Error += glm::all(glm::epsilonEqual(dst_pt_m3_i, dst_pt_dq3_i, Epsilon)) ? 0 : 1; Error += glm::all(glm::epsilonEqual(dst_pt_m4_i, dst_pt_dq4_i, Epsilon)) ? 0 : 1; } } return Error; }
//! Read uint 16 LE from buffer //! \param from //! \return uint 32 LE quint32 QOscarBA::readU32LE(const quint32 from) { if ( (quint32) length() < from + 4 ) return 0; quint32 tmp = (quint32) mid(from, 4).toHex().toUInt(0, 16); return ( (tmp % 0x100) * 0x1000000 + (tmp % 0x10000 / 0x100) * 0x10000 + (tmp % 0x1000000 / 0x10000) * 0x100 + (tmp)/0x1000000 ); }
std::wstring Utils::textEditToMessageText(QTextEdit* textEdit) { std::wstring result; QTextCursor c(textEdit->document()); auto text = textEdit->toPlainText(); size_t textStart = 0; int pos; QChar ch(65532); while ((pos = text.indexOf(ch, textStart)) != -1) { result += text.mid(textStart, pos - textStart).toStdWString(); c.setPosition(pos + 1); auto imageFormat = c.charFormat().toImageFormat(); if (imageFormat.isValid()) { auto fileName = imageFormat.name(); result += L"<img path=\"" + fileName.toStdWString() + L"\"/>"; } textStart = pos + 1; } result += text.mid(textStart).toStdWString(); return result; }
gdPoint stringAnchorFT(gdPoint point, int *brect, int anchor) { gdPoint result, target; result.x = point.x; result.y = point.y; switch (anchor) { //case 1: result.x = (point.x * 2) - brect[6]; result.y = (point.y * 2) - brect[7]; break; case 1: target.x = brect[6]; target.y = brect[7]; break; case 2: target.x = mid(brect[4], brect[6]); target.y = mid(brect[5], brect[7]); break; case 3: target.x = brect[4]; target.y = brect[5]; break; case 4: target.x = mid(brect[0], brect[6]); target.y = mid(brect[1], brect[7]); break; case 5: target.x = mid(brect[0], brect[4]); target.y = mid(brect[1], brect[5]); break; case 6: target.x = mid(brect[2], brect[4]); target.y = mid(brect[3], brect[5]); break; case 7: target.x = brect[0]; target.y = brect[1]; break; case 8: target.x = mid(brect[0], brect[2]); target.y = mid(brect[1], brect[3]); break; case 9: target.x = brect[2]; target.y = brect[3]; break; } result.x = (point.x * 2) - target.x; result.y = (point.y * 2) - target.y; return result; }
QString ModelBaker::texturePathRelativeToModel(QUrl modelURL, QUrl textureURL) { auto modelPath = modelURL.toString(QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment); auto texturePath = textureURL.toString(QUrl::RemoveFilename | QUrl::RemoveQuery | QUrl::RemoveFragment); if (texturePath.startsWith(modelPath)) { // texture path is a child of the model path, return the texture path without the model path return texturePath.mid(modelPath.length()); } else { // the texture path was not a child of the model path, return the empty string return ""; } }
String Path::name() const { if (endsWith('/')) { const int secondLastSlash = lastIndexOf('/', size() - 2); if (secondLastSlash != -1) { return mid(secondLastSlash + 1, size() - secondLastSlash - 2); } return String(); } else { return fileName(); } }
Color Material::evaluate(const Vector3d &out, const Vector3d &in, Isect &isect) const { Color color = texture_->evaluate(isect.vertex()); isect.setNormal(normalize(isect.normal())); if (type_ == kPhong) { Vector3d mid(normalize(in - out)); return color * dot(isect.normal(), in) + Vector3d(1.5) * std::pow(dot(isect.normal(), mid), pow_); } else { return color * dot(isect.normal(), in); } }
/// @brief Get frame /// @param _n /// @return /// const AegiVideoFrame FFmpegSourceVideoProvider::GetFrame(int n) { FrameNumber = mid(0, n, GetFrameCount() - 1); // decode frame const FFMS_Frame *SrcFrame = FFMS_GetFrame(VideoSource, FrameNumber, &ErrInfo); if (SrcFrame == NULL) { throw VideoDecodeError(std::string("Failed to retrieve frame:") + ErrInfo.Buffer); } CurFrame.SetTo(SrcFrame->Data[0], Width, Height, SrcFrame->Linesize[0]); return CurFrame; }
int choice(int a,int o) { if(o==3||o==5||o==7||o==8||o==10||o==12) odd(a,o); else if(o==4||o==6||o==9||o==11) even(a,o); else if(o==1||o==2) mid(a,o); else printf("Wrong Input"); return 0; }
rmatrix mid ( imatrix& A ) // Matrix of midpoints { //-------------------- int i,j; int lbi = Lb(A,1), ubi = Ub(A,1); int lbj = Lb(A,2), ubj = Ub(A,2); rmatrix B(lbi,ubi,lbj,ubj); for (i = lbi; i <= ubi; i++) for (j = lbj; j <= ubj; j++) B[i][j] = mid(A[i][j]); return B; }
void PronyMethod::setMuMatrix(){ this->mu = new rvector(RMatrixUtils::eigLR(mid(this->smp_->getTransitionMatrix()),0.000005)); this->imat = new imatrix( 0, this->states-1, 0, this->states-1 ); for(int i = Lb((*this->imat),1); i <= Ub((*this->imat),1); i++){ for(int c = Lb((*this->imat),2); c <= Ub((*this->imat),2); c++){ if(i==0) (*this->imat)[i][c] = interval(1.0,1.0); else (*this->imat)[i][c] = interval( RealUtils::rPow( (*this->mu)[c] , i ) , RealUtils::rPow( (*this->mu)[c] , i ) ); } } }
void PopupMenuEditor::paintEvent( QPaintEvent * ) { QPainter p( this ); p.save(); QRegion reg( rect() ); QRegion mid( borderSize, borderSize, rect().width() - borderSize * 2, rect().height() - borderSize * 2 ); reg -= mid; p.setClipRegion( reg ); style().drawPrimitive( QStyle::PE_PanelPopup, &p, rect(), colorGroup() ); p.restore(); drawItems( &p ); }
// --------------------------------------------------------------------------- // // ------------ void bSmoothElement::makecurve( float *xpts, float *ypts, int npts, int *cur, curve *crv, int level, float *lastx, float *lasty){ curve left,right; if(level>0){ left.startx=crv->startx; left.starty=crv->starty; mid(&left.controlx,&left.controly,crv->startx,crv->starty,crv->controlx,crv->controly); mid(&right.controlx,&right.controly,crv->controlx,crv->controly,crv->endx,crv->endy); mid(&left.endx,&left.endy,left.controlx,left.controly,right.controlx,right.controly); right.startx=left.endx; right.starty=left.endy; right.endx=crv->endx; right.endy=crv->endy; makecurve(xpts,ypts,npts,cur,&left,level-1,lastx,lasty); makecurve(xpts,ypts,npts,cur,&right,level-1,lastx,lasty); } else{ xpts[(*cur)]=crv->endx; ypts[(*cur)]=crv->endy; (*lastx)=crv->endx; (*lasty)=crv->endy; (*cur)++; } }
struct deplist *deplist_from_deprow(char *deprow){ struct deplist *d=NULL; if (strlen (deprow) > 0) { char tmp[MASSIMO]; strcpy (deprow, sed (deprow, " ", ",")); while (strlen (deprow) > 0) { if (strstr (deprow, ",")) { strcpy (tmp, strstr (deprow, ",")); strcpy (tmp, mid (deprow, 0, strlen (deprow) - strlen (tmp))); strcpy (deprow, mid (strstr (deprow, ","), 1, FINE)); } else { strcpy (tmp, deprow); strcpy (deprow, ""); } strcpy (tmp, trim (tmp)); if(strlen(trim(tmp))>0) d=add (trim(tmp), d); strcpy (deprow, trim (deprow)); } } return(d); }
struct db * parse_cvs (char *percorso){ FILE *file; struct db * p=NULL; if((file=fopen(percorso, "r"))){ char riga[255]; char prefix[255]; char collezione[255]; while (fgets (riga, 255, file)) { strcpy(riga, trim(riga)); if(strncmp(riga, "LOCAL_PATH=", 11)==0){ strcpy(prefix, mid(riga, 12, FINE)); strcpy(prefix, mid(prefix, 0, strlen(prefix)-1)); } if(strncmp(riga, "LOCAL_DIR=", 10)==0){ strcpy(collezione, mid(riga, 11, FINE)); strcpy(collezione, mid(collezione, 0, strlen(collezione)-1)); } } p=inserisci_elemento_ordinato(prefix, collezione, "", NULL, p); } return(p); }
void recoverTree(TreeNode* root) { first = second = nullptr; mid(root); for(auto itr = list.begin(); itr != prev(list.end()); ++itr){ if((*itr)->val > (*next(itr))->val){ if(first == nullptr){ first = *itr; } second = *next(itr); } } swap(first->val,second->val); }
// ------------------------------------------------ // RemoveEntryL // ------------------------------------------------ // void CMdSNotifier::RemoveEntryL( TInt aId ) { CMdSNotifier::TEntry* e = NULL; TInt low( 0 ); TInt mid( 0 ); TInt high( iEntries.Count() ); while( low < high ) { mid = (low+high)>>1; const TInt compare( aId - iEntries[mid].Id() ); if( compare == 0 ) { e = &iEntries[mid]; break; } else if( compare > 0 ) { low = mid + 1; } else { high = mid; } } if( e ) { if ( e->IsPending() ) { e->TriggerError( KErrCancel ); } if ( e->iSerializedCondition ) { delete e->iSerializedCondition; e->iSerializedCondition = NULL; } if ( e->iDataBuffer ) { delete e->iDataBuffer; e->iDataBuffer = NULL; } iEntries.Remove( mid ); } else { User::Leave( KErrNotFound ); } }
Mat SurfFeature::FeatureEvaluate(const Mat &_sumImg, float _scale) { CV_Assert( _scale >= 1 ); CV_Assert( _sumImg.type() == CV_64FC(8) ); CV_Assert( feature != Rect() ); int tx = ((int)((feature.x + 1) * _scale + 0.5) - 1); int ty = ((int)((feature.y + 1) * _scale + 0.5) - 1); int bx = (int)(feature.br().x * _scale + 0.5); int by = (int)(feature.br().y * _scale + 0.5); Rect scaleFst(Point(tx,ty),Point(bx,by)); if( scaleFst.br().x >= _sumImg.rows || scaleFst.br().y >= _sumImg.cols ) CV_Error(CV_StsOutOfRange,"Scale feature size is larger than given window size!"); #define SumType Vec<double,8> Point mid((int)(scaleFst.x + scaleFst.width * 0.5 + 0.5), (int)(scaleFst.y + scaleFst.height * 0.5 + 0.5)); Vec<double,8> res[4]; res[0] = _sumImg.at<SumType>(mid) + _sumImg.at<SumType>(scaleFst.tl()) - _sumImg.at<SumType>(mid.y, scaleFst.x) - _sumImg.at<SumType>(scaleFst.y, mid.x); res[1] = _sumImg.at<SumType>(mid.y,scaleFst.br().x) + _sumImg.at<SumType>(scaleFst.y,mid.x) - _sumImg.at<SumType>(mid) - _sumImg.at<SumType>(scaleFst.y,scaleFst.br().x); res[2] = _sumImg.at<SumType>(scaleFst.br().y,mid.x) + _sumImg.at<SumType>(mid.y,scaleFst.x) - _sumImg.at<SumType>(mid) - _sumImg.at<SumType>(scaleFst.br().y,scaleFst.x); res[3] = _sumImg.at<SumType>(scaleFst.br()) + _sumImg.at<SumType>(mid) - _sumImg.at<SumType>(mid.y,scaleFst.br().x) - _sumImg.at<SumType>(scaleFst.br().y, mid.x); double sumRes = 1e-10; Mat result(FEATURE_SIZE, 1, CV_64FC1); for(int i = 0; i < 4; i++) { for(int j = 0; j < 8; j++) { result.at<double>(i * 8 + j,0) = res[i][j]; sumRes += res[i][j]*res[i][j]; } } CV_Assert(sumRes != 0); result = result / cv::sqrt(sumRes); return result; }
void mid(const IntervalObject& v, ResultType& result) { if(v.dimension()!=result.dimension()) throw std::range_error("Unequal dimensions in function capd::vectalg::mid"); typename ResultType::iterator i = result.begin(); typename IntervalObject::const_iterator b = v.begin(), e=v.end(); while(b!=e) { *i = mid(*b); ++i; ++b; } }
void MiaoStegAlgorithm::process(unprocessedList *src, processedList *dest) { length_t nv = n(); index_t midv = mid(); while (src->size() >= nv) { MiaoG711SampleGroup staging; for (index_t i = 0; i < nv; i++) { staging.samples.push_back(src->front()); src->pop_front(); } if (staging.samples.at(midv).uninvertedSignedSample() == -7) staging.mu = 1; int mu = 0; for (index_t i = 0; i < nv; i++) { mu += staging.samples.at(i).uninvertedSignedSample(); } mu = (int)floor(((double)mu) / nv); staging.mu = mu; int tU = mu, tL = mu; for (index_t i = 0; i < nv; i++) { if (i != midv) { G711Sample s = staging.samples.at(i); int delta = mu - s.uninvertedSignedSample(); for (miaoGroup *group = groups; group->deltaLow != 0; group++) { if (delta >= group->deltaLow && delta <= group->deltaHigh) { tU += group->deltaHigh; tL += group->deltaLow; staging.bitCount.push_back( (std::abs(mu - group->deltaHigh) <= maxLambda || std::abs(mu - group->deltaLow) <= maxLambda) ? group->bitsAllowed : 0); staging.groupDelta.push_back((delta >= 0) ? group->deltaLow : group->deltaHigh); break; } } staging.deltas.push_back(delta); } } if (std::abs(tU) > maxLambda || std::abs(tL) > maxLambda) staging.bitCount.clear(); dest->push_back(staging); } }
int nary_search(const std::vector<int>& a, int const key, int const N) { std::vector<int> mid(N + 1); std::vector<locate_t> locate(N + 2); locate[0] = RIGHT; locate[N + 1] = LEFT; int lo = 0; int hi = a.size() - 1; int pos = -1; while(lo <= hi && pos == -1) { mid[0] = lo - 1; double const step = (hi - lo + 1) / (N + 1); for(int i = 1; i <= N; i++) { int const offset = step * i + (i - 1); int const lmid = mid[i] = lo + static_cast<int>(offset); if(lmid <= hi) { if(a[lmid] > key) { locate[i] = LEFT; } else if(a[lmid] < key) { locate[i] = RIGHT; } else { locate[i] = EQUAL; pos = lmid; } } else { mid[i] = hi + 1; locate[i] = LEFT; } } for(int i = 1; i <= N; i++) { if(locate[i] != locate[i-1]) { lo = mid[i - 1] + 1; hi = mid[i] - 1; } } if(locate[N] != locate[N+1]) { lo = mid[N] + 1; } } return pos; }
void Separate(char *ValueList,float results[],unsigned short numValues) { // parses a space- or tab- delimited string into an array of floats unsigned short i; unsigned short StartPos, EndPos; char *word; StartPos=FindText(ValueList,0); // find start of first value for (i=0;i<numValues;i++) { EndPos=FindSpace(ValueList,StartPos); // find end of value word=mid(ValueList, StartPos, (unsigned short)(EndPos-StartPos)); results[i] = (float) atof(word); // store value in array free(word); StartPos=FindText(ValueList,EndPos); // find start of next value } } // Separate()
static void light_vertices (const AABB& aabb_light, Vector3 points[6]) { Vector3 max(aabb_light.origin + aabb_light.extents); Vector3 min(aabb_light.origin - aabb_light.extents); Vector3 mid(aabb_light.origin); // top, bottom, tleft, tright, bright, bleft points[0] = Vector3(mid[0], mid[1], max[2]); points[1] = Vector3(mid[0], mid[1], min[2]); points[2] = Vector3(min[0], max[1], mid[2]); points[3] = Vector3(max[0], max[1], mid[2]); points[4] = Vector3(max[0], min[1], mid[2]); points[5] = Vector3(min[0], min[1], mid[2]); }
length_t MiaoStegAlgorithm::popRecoveredData(steg_t *stegData, length_t *bitLength, int *state, length_t length) { length_t size = recoveredDataReadyForPop(); if (length > size) length = size; length /= n(); for (index_t i = 0; i < length; i++) { if (!tamperedProcessed.front().bitCount.empty()) { for (index_t s = 0; s < n(); s++) { if (s != mid()) { index_t s_adj = s - (s > mid() ? 1 : 0); bitLength[i*n()+s] = tamperedProcessed.front().bitCount.at(s_adj); int groupDelta = tamperedProcessed.front().groupDelta.at(s_adj); int thisDelta = tamperedProcessed.front().deltas.at(s_adj); stegData[i*n()+s] = (thisDelta >= 0 ? thisDelta - groupDelta : groupDelta - thisDelta); stegData[i*n()+s] &= (1 << bitLength[i*n()+s]) - 1; } else { bitLength[i*n()+s] = 0; stegData[i*n()+s] = 0; } state[i*n()+s] = 0; } } else { for (index_t s = 0; s < n(); s++) { stegData[i*n()+s] = 0; bitLength[i*n()+s] = 0; state[i*n()+s] = 0; } } tamperedProcessed.pop_front(); } length *= n(); return length; }
void Model::rhs( const state_type &x, state_type &x_dot, const time_type &t, const intermediate_type &last_observed_mids, const time_type &last_observed_t, input_type &u ) { // ******* system implementation ******* intermediate_type mid; intermediates(u,x,mid,t,last_observed_mids,last_observed_t); // x0 surge_hp_x1 // x1 surge_hp_x2 // x2 surge_kin_vel // x3 surge_kin_pos // x4 surge_lp_x1 // x5 surge_lp_x2 // x6 pitch_hp_x1 // x_dot(states::surge_hp_x1)=... // x_dot(states::surge_hp_x2)=... hp_surge(mid,x,x_dot); x_dot(states::surge_kin_vel)=mid(mids::surge_kin_acc); x_dot(states::surge_kin_pos)=mid(mids::surge_kin_vel); // x_dot(states::surge_lp_x1)=... // x_dot(states::surge_lp_x2)=... lp_surge(mid,x,x_dot); // x_dot(states::pitch_hp_x1)=... hp_pitch(mid,x,x_dot); }
/** * Initiate completion when there is \c #include on a line (\c m_range * in a result of \c parseIncludeDirective() not empty -- i.e. there is some file present) * and cursor placed within that range... despite of completeness of the whole line. */ bool IncludeHelperCompletionModel::shouldStartCompletion( KTextEditor::View* view , const QString& inserted_text , bool user_insertion , const KTextEditor::Cursor& position ) { kDebug(DEBUG_AREA) << "position=" << position << ", inserted_text=" << inserted_text << ", ui=" << user_insertion; m_should_complete = false; auto* doc = view->document(); // get current document auto line = doc->line(position.line()); // get current line auto* iface = qobject_cast<KTextEditor::HighlightInterface*>(doc); // Do nothing if no highlighting interface or not suitable document or // a place within it... (we won't to complete smth in non C++ files or comments for example) if (!iface || !isSuitableDocumentAndHighlighting(doc->mimeType(), iface->highlightingModeAt(position))) return m_should_complete; // Try to parse it... auto r = parseIncludeDirective(line, false); m_should_complete = r.m_range.isValid(); if (m_should_complete) { kDebug(DEBUG_AREA) << "range=" << r.m_range; m_should_complete = position.column() >= r.m_range.start().column() && position.column() <= r.m_range.end().column(); if (m_should_complete) { m_closer = r.close_char(); kDebug(DEBUG_AREA) << "closer=" << m_closer; } } else if (position.column() == line.length()) { auto text = tryToCompleteIncludeDirective(line.mid(0, position.column()).trimmed()); m_should_complete = !text.isEmpty(); if (m_should_complete) { /// \todo Hardcoded angle bracket! Better to check what file was selected /// (from system path or session specific) and replace it accordingly... text += QLatin1String(" <"); auto start = position; start.setColumn(0); auto range = KTextEditor::Range{start, position}; view->document()->replaceText(range, text); } } return m_should_complete; }