LIS_INT lis_solver_get_rhistory(LIS_SOLVER solver, LIS_VECTOR v) { LIS_INT i,n,maxiter; maxiter = solver->iter+1; if( solver->retcode!=LIS_SUCCESS ) { maxiter--; } n = _min(v->n,maxiter); for(i=0;i<n;i++) { v->value[i] = solver->residual[i]; } return LIS_SUCCESS; }
float _ptextheight( /*****************/ /* return height of 1 char */ text_def *text ) { int pix_width; int pix_height; float height; textdim( NULL, text, &pix_width, &pix_height ); height = (float)pix_height / Height; return( _min( height, 1.0 ) ); }
LIS_INT lis_esolver_get_rhistory(LIS_ESOLVER esolver, LIS_VECTOR v) { LIS_INT i,n,maxiter; maxiter = esolver->iter[0]+1; if( esolver->retcode!=LIS_SUCCESS ) { maxiter--; } n = _min(v->n,maxiter); for(i=0;i<n;i++) { v->value[i] = esolver->rhistory[i]; } return LIS_SUCCESS; }
float _wtextheight( /*****************/ /* return text height in window coords of text line */ text_def *text ) { int pix_width; int pix_height; float height; textdim( NULL, text, &pix_width, &pix_height ); height = (float)pix_height / Height * Win_height; return( _min( height, Win_height ) ); }
void Light::_fade() { switch(_state) { case _RISING: _rising(); break; case _MAX: _max(); break; case _FALLING: _falling(); break; case _MIN: _min(); break; } }
veValue::veValue(Type type) : USE_VE_PTR_INIT , _type(type) { } veValue::~veValue() { } veValueFixed::veValueFixed() : veValue(Type::VAL_FIXED) , _value(0.0f) { } veValueFixed::~veValueFixed() { } veReal veValueFixed::getValue(veReal x) { return _value; } veValueRandom::veValueRandom() : veValue(Type::VAL_RANDOM) , _min(0.0f) , _max(0.0f) { } veValueRandom::~veValueRandom() { } veReal veValueRandom::getValue(veReal x) { veReal t = veMath::veRandomUnitization(); return _min * t + _max * (1.0f - t); }
void MxPropSlim::apply_mesh_penalties(edge_info *info) { unsigned int i; const MxFaceList& N1 = m->neighbors(info->v1); const MxFaceList& N2 = m->neighbors(info->v2); // Set up the face marks as the check_xxx() functions expect. // for(i=0; i<(unsigned int)N2.length(); i++) m->face_mark(N2[i], 0); for(i=0; i<(unsigned int)N1.length(); i++) m->face_mark(N1[i], 1); for(i=0; i<(unsigned int)N2.length(); i++) m->face_mark(N2[i], m->face_mark(N2[i])+1); double base_error = info->heap_key(); double bias = 0.0; // Check for excess over degree bounds. // unsigned int max_degree = _max(N1.length(), N2.length()); if( max_degree > vertex_degree_limit ) bias += (max_degree-vertex_degree_limit) * meshing_penalty * 0.001f; // Local validity checks // float vnew[3]; vnew[0] = (float)info->target[0]; vnew[1] = (float)info->target[1]; vnew[2] = (float)info->target[2]; unsigned int nfailed = 0; nfailed += check_local_validity(info->v1, vnew); nfailed += check_local_validity(info->v2, vnew); if( nfailed ) bias += nfailed*meshing_penalty; float _scale = 1.f; if( compactness_ratio > 0.0 ){ double c1_min=check_local_compactness(info->v1, vnew); double c2_min=check_local_compactness(info->v2, vnew); double c_min = _min(c1_min, c2_min); if( c_min < compactness_ratio ) _scale += float((compactness_ratio-c_min)/compactness_ratio); } info->heap_key(float((base_error-EDGE_BASE_ERROR)*_scale - bias)); }
LPCSTR DelHyphens( LPCSTR c ) { static string64 buf; u32 sz = xr_strlen( c ); u32 sz1 = _min( iFloor(sz/4.0f), 3 ); u32 j = 0; for ( u32 i = 0; i < sz - sz1; ++i ) { j = i + iFloor( i/4.0f ); buf[i] = c[j]; } buf[sz - sz1] = 0; return buf; }
/*********************************************************** * Name: vc_cec_send_message * * Arguments: * Follower's logical address * Message payload WITHOUT the header byte (can be NULL) * Payload length WITHOUT the header byte (can be zero) * VC_TRUE if the message is a reply to an incoming message * (For poll message set payload to NULL and length to zero) * * Description * Remove all commands to be forwarded. This does not affect * the button presses which are always forwarded * * Returns: if the command is successful (zero) or not (non-zero) * If the command is successful, there will be a Tx callback * in due course to indicate whether the message has been * acknowledged by the recipient or not ***********************************************************/ VCHPRE_ int VCHPOST_ vc_cec_send_message(uint32_t follower, const uint8_t *payload, uint32_t length, bool_t is_reply) { int success = -1; CEC_SEND_MSG_PARAM_T param; vcos_assert(length <= CEC_MAX_XMIT_LENGTH); param.follower = VC_HTOV32(follower); param.length = VC_HTOV32(length); param.is_reply = VC_HTOV32(is_reply); memset(param.payload, 0, sizeof(param.payload)); if(length > 0 && vcos_verify(payload)) { memcpy(param.payload, payload, _min(length, CEC_MAX_XMIT_LENGTH)); } success = cecservice_send_command( VC_CEC_SEND_MSG, ¶m, sizeof(param), 1); return success; }
bool HostGetSaveGameName(int nGame, char *psz, int cb, Date *pdate, int *pnHours24, int *pnMinutes, int *pnSeconds) { // Find the game char szT[PATH_MAX]; if (!FindSaveGame(nGame, szT, sizeof(szT))) { strncpyz(psz, "-- Empty --", cb); return false; } char szPath[PATH_MAX]; PrependSavesDirectory(szT, szPath); // Get the creation time in hours24, minutes struct stat st; if (stat(szPath, &st) > 0) { return false; } time_t tim = st.st_mtimespec.tv_sec; struct tm *ptm = localtime(&tim); *pnHours24 = ptm->tm_hour; *pnMinutes = ptm->tm_min; *pnSeconds = ptm->tm_sec; pdate->nDay = ptm->tm_mday; pdate->nMonth = ptm->tm_mon; pdate->nYear = ptm->tm_year + 1900; // Copy over filename, lose prefix char *pszName = strchr(szT, '_') + 1; int cbName = (int)strlen(pszName) - 4 + 1; strncpyz(psz, pszName, _min(cb, cbName)); // restore '#' to ':' char *pchInvalid = psz; do { pchInvalid = strchr(pchInvalid, '#'); if (pchInvalid != 0) *pchInvalid = ':'; } while (pchInvalid != 0); return true; }
float _ptextwidth( /****************/ /* return text width in percentage screen width of text line. If text_line is NULL, assume 1 character */ char *text_line, text_def *text ) { int pix_width; int pix_height; float width; textdim( text_line, text, &pix_width, &pix_height ); width = (float)pix_width / Width; return( _min( width, 1.0 ) ); }
void CSoundRender_Source::decompress (u32 line, OggVorbis_File* ovf) { VERIFY (ovf); // decompression of one cache-line u32 line_size = SoundRender->cache.get_linesize(); char* dest = (char*) SoundRender->cache.get_dataptr (CAT,line); u32 buf_offs = (psSoundFreq==sf_22K)?(line*line_size):(line*line_size)/2; u32 left_file = dwBytesTotal - buf_offs; u32 left = (u32)_min (left_file,line_size); // seek u32 cur_pos = u32 (ov_pcm_tell(ovf)); if (cur_pos!=buf_offs){ ov_pcm_seek (ovf,buf_offs); } // decompress if (psSoundFreq==sf_22K)i_decompress_hr(ovf,dest,left); else i_decompress_fr(ovf,dest,left); }
float _wtextwidth( /****************/ /* return text width in window coords of text line. If text_line is NULL, assume 1 character */ char *text_line, text_def *text ) { int pix_width; int pix_height; float width; textdim( text_line, text, &pix_width, &pix_height ); width = (float)pix_width / Width * Win_width; return( _min( width, Win_width ) ); }
int maxbuild(const unit * u, const construction * cons) /* calculate maximum size that can be built from available material */ /* !! ignores maximum objectsize and improvements... */ { int c; int maximum = INT_MAX; for (c = 0; cons->materials[c].number; c++) { const resource_type *rtype = cons->materials[c].rtype; int have = get_pooled(u, rtype, GET_DEFAULT, INT_MAX); int need = required(1, cons->reqsize, cons->materials[c].number); if (have < need) { return 0; } else maximum = _min(maximum, have / need); } return maximum; }
static void eaten_by_monster(unit * u) { /* adjustment for smaller worlds */ static double multi = 0.0; int n = 0; int horse = 0; if (multi == 0.0) { multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; } switch (old_race(u_race(u))) { case RC_FIREDRAGON: n = rng_int() % 80 * u->number; horse = get_item(u, I_HORSE); break; case RC_DRAGON: n = rng_int() % 200 * u->number; horse = get_item(u, I_HORSE); break; case RC_WYRM: n = rng_int() % 500 * u->number; horse = get_item(u, I_HORSE); break; default: n = rng_int() % (u->number / 20 + 1); } n = (int)(n * multi); if (n > 0) { n = lovar(n); n = _min(rpeasants(u->region), n); if (n > 0) { deathcounts(u->region, n); rsetpeasants(u->region, rpeasants(u->region) - n); ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); } } if (horse > 0) { set_item(u, I_HORSE, 0); ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); } }
void continue_ship(region * r, unit * u, int want) { const construction *cons; ship *sh; int msize; if (!eff_skill(u, SK_SHIPBUILDING, r)) { cmistake(u, u->thisorder, 100, MSG_PRODUCE); return; } /* Die Schiffsnummer bzw der Schiffstyp wird eingelesen */ sh = getship(r); if (!sh) sh = u->ship; if (!sh) { cmistake(u, u->thisorder, 20, MSG_PRODUCE); return; } cons = sh->type->construction; assert(cons->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */ if (sh->size == cons->maxsize && !sh->damage) { cmistake(u, u->thisorder, 16, MSG_PRODUCE); return; } if (eff_skill(u, cons->skill, r) < cons->minskill) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_build_skill_low", "value", cons->minskill)); return; } msize = maxbuild(u, cons); if (msize == 0) { cmistake(u, u->thisorder, 88, MSG_PRODUCE); return; } if (want > 0) want = _min(want, msize); else want = msize; build_ship(u, sh, want); }
type bst<type>::_remove(np cur) { np tmp; type x; if (_isleaf(cur)) { x = cur->_data; if (!_isroot(cur)) { _setnull(_root, cur); delete(cur); cur = NULL; } return x; } else { tmp = cur->left ? _max(cur->left) : _min(cur->right); x = cur->_data; cur->_data = _remove(tmp); return x; } }
bool CLevelTool::GetSelectionPosition(Fmatrix& result) { if(pCurTool) { Fvector center; Fbox BB; BB.invalidate (); // pCurTool->GetBBox (BB, true); const CCustomObject* object = pCurTool->LastSelected(); if(!object) return false; object->GetBox (BB); BB.getcenter (center); center.y = BB.max.y; Fvector2 pt_ss; pt_ss.set (10000,-10000); Fvector pt_ss_3d; BB.setb (center, Fvector().set(1.0f,1.0f,1.0f)); for(int k=0;k<8;++k) { Fvector pt; BB.getpoint(k,pt); EDevice.mFullTransform.transform(pt_ss_3d, pt); pt_ss.x = _min(pt_ss.x, pt_ss_3d.y); pt_ss.y = _max(pt_ss.y, pt_ss_3d.y); } float r_bb_ss = pt_ss.y - pt_ss.x; clamp(r_bb_ss, 0.0f,0.10f); float des_radius = 0.2f; float csale = des_radius/r_bb_ss; result.scale (csale,csale,csale); result.c = center; return true; }else return false; }
int StringGD::compare (const StringGD& orig) const { int orig_len = orig.length(); int min_len; min_len = _min(len, orig_len); for (int i = 0; i < min_len; i++){ if (this->str[i] > orig.str[i]) return 1; else if (this->str[i] < orig.str[i]) return -1; } if (len == orig_len) return 0; else if (min_len == len) return -1; else{ return 1; } }
static void absorbed_by_monster(unit * u) { int n; switch (old_race(u_race(u))) { default: n = rng_int() % (u->number / 20 + 1); } if (n > 0) { n = lovar(n); n = _min(rpeasants(u->region), n); if (n > 0) { rsetpeasants(u->region, rpeasants(u->region) - n); scale_number(u, u->number + n); ADDMSG(&u->region->msgs, msg_message("absorbpeasants", "unit race amount", u, u_race(u), n)); } } }
void kp() { int i; int mx = 0; int id; for(i=n; str[i]!=0; i++) str[i] = 0; for(i=1; i<n; i++) { if(mx > i) p[i] = _min(p[2*id-i], p[id]+id-1); else p[i] = 1; for(; str[i+p[i]] == str[i-p[i]]; p[i]++); if(p[i]+i > mx) { mx = p[i] + i; id = i; } if(p[i]>ans) ans = p[i]; } }
const curse_type *ct_find(const char *c) { unsigned int hash = tolower(c[0]); quicklist *ctl = cursetypes[hash]; int qi; for (qi = 0; ctl; ql_advance(&ctl, &qi, 1)) { curse_type *type = (curse_type *) ql_get(ctl, qi); if (strcmp(c, type->cname) == 0) { return type; } else { size_t k = _min(strlen(c), strlen(type->cname)); if (!_memicmp(c, type->cname, k)) { return type; } } } return NULL; }
int StringGD::compare (char *str) const { int len_str = _strlen(str); int min_len; min_len = _min(len, len_str); for (int i = 0; i < min_len; i++){ if (this->str[i] > str[i]) return 1; else if (this->str[i] < str[i]) return -1; } if (len == len_str) return 0; else if (min_len == len) return -1; else{ return 1; } }
void Font::DrawTextWithEllipsis(DibBitmap *pbm, char *psz, int cch, int x, int y, int cx, bool fForce) { if (!fForce) { // If not being forced and text fits, draw it without ellipsis if (GetTextExtent(psz) < cx) { DrawText(pbm, psz, x, y, (int)strlen(psz)); return; } } // Do a binary search to find out where the ellipsis is needed char szT[256]; int imin = 0; // Convert to index and ensure room for ellipsis int imax = _min(cch - 1, (int)sizeof(szT) - 3 - 1); if (imax < 0) { imax = 0; } int icur = imax; int ifit = imax; while (true) { int icurT = imin + (imax - imin) / 2; if (icurT == icur) { break; } icur = icurT; int cxT = GetTextExtent(psz, icur + 1); if (cxT >= cx - m_cxEllipsis) { imax = icur - 1; } else { ifit = icur; imin = icur + 1; } } strncpyz(szT, psz, ifit + 2); // convert to count, add one for 0 strcat(szT, "..."); // this fits without checks DrawText(pbm, szT, x, y, (int)strlen(szT)); }
FE_TMPL FE_SYS::FastEvaluationRBFSystem(const std::vector<glm::vec4> &points,int threshold,unsigned int p,float relativeAccuracy ){ if(points.empty()){ root = 0; return; } glm::vec3 _min(points[0]),_max(points[0]); root = new FE_NODE(BoundingAABB(glm::vec3(),glm::vec3())); for(int i = 1;i<points.size();i++){ _min.x = std::min(_min.x,points[i].x); _min.y = std::min(_min.y,points[i].y); _min.z = std::min(_min.z,points[i].z); _max.x = std::max(_max.x,points[i].x); _max.y = std::max(_max.y,points[i].y); _max.z = std::max(_max.z,points[i].z); root->_points.push_back(glm::vec4(points[i])); } root->_aabb = BoundingAABB(_min,_max); root->_c = root->_aabb.getPosition(glm::vec3(0.5f,0.5f,0.5f)); root->_h = root->_aabb.maxPos() - root->_c; std::vector<FE_NODE*> nodes; nodes.push_back(root); while(!nodes.empty()){ auto node = nodes[0]; nodes.erase(nodes.begin()); if(node->_points.size()<threshold*2){ //only split nodes with points more than threshold*2 continue; } node->split(threshold); nodes.push_back(node->_left); nodes.push_back(node->_right); } root->calcFarFieldSeries(p); }
static int heal_fighters(quicklist * fgs, int *power, bool heal_monsters) { int healhp = *power, healed = 0, qi; quicklist *ql; for (qi = 0, ql = fgs; ql; ql_advance(&ql, &qi, 1)) { fighter *df = (fighter *)ql_get(ql, qi); if (healhp <= 0) break; /* Untote kann man nicht heilen */ if (df->unit->number == 0 || (u_race(df->unit)->flags & RCF_NOHEAL)) continue; /* wir heilen erstmal keine Monster */ if (heal_monsters || playerrace(u_race(df->unit))) { int n, hp = df->unit->hp / df->unit->number; int rest = df->unit->hp % df->unit->number; for (n = 0; n < df->unit->number; n++) { int wound = hp - df->person[n].hp; if (rest > n) ++wound; if (wound > 0 && wound < hp) { int heal = _min(healhp, wound); assert(heal >= 0); df->person[n].hp += heal; healhp = _max(0, healhp - heal); ++healed; if (healhp <= 0) break; } } } } *power = healhp; return healed; }
extern float _wtextheight_font( /*****************************/ /* returns text height in window coords using the given font */ char * text, WPI_FONT font ) { int pix_height; int pix_width; float height; if( Text_path == TEXT_VERTICAL ) { textdim_font( NULL, font, &pix_width, &pix_height ); pix_height *= strlen( text ); } else { textdim_font( text, font, &pix_width, &pix_height ); } height = (float)pix_height / Height * Win_height; return( _min( height, Win_height ) ); }
static region *wall_move(const connection * b, struct unit *u, struct region *from, struct region *to, bool routing) { wall_data *fd = (wall_data *) b->data.v; if (!routing && fd->active) { int hp = dice(3, fd->force) * u->number; hp = _min(u->hp, hp); u->hp -= hp; if (u->hp) { ADDMSG(&u->faction->msgs, msg_message("firewall_damage", "region unit", from, u)); } else ADDMSG(&u->faction->msgs, msg_message("firewall_death", "region unit", from, u)); if (u->number > u->hp) { scale_number(u, u->hp); u->hp = u->number; } } return to; }
extern float _wtextwidth_font( /****************************/ /* return text width in window coords of text line. If text_line is NULL, assume 1 character */ char *text_line, WPI_FONT font ) { int pix_width; int pix_height; float width; if( Text_path == TEXT_VERTICAL ) { textdim_font( NULL, font, &pix_width, &pix_height ); } else { textdim_font( text_line, font, &pix_width, &pix_height ); } width = (float)pix_width / Width * Win_width; return( _min( width, Win_width ) ); }
static void _boxdis (char *msg, char *input, int pos, int max) { char *p; int i, j, len = strlen(msg); clear (); border ( '|', '|', '-', '-', '+', '+', '+', '+' ); j = _intlength(max - 1); len = MAX(len, j * 3 + 2); j += _intlength(strlen(input)) + _intlength(POS) + 2; _mvchgrectat(WIN_Y, WIN_X, 5, len + 4, 0, clr_bkg, NULL); move(WIN_Y + 1, WIN_X + 2); attron(COLOR_PAIR(clr_ttl)); addstr(msg); attroff(COLOR_PAIR(clr_ttl)); move(WIN_Y + 2, WIN_X + len - j + 2); attron(COLOR_PAIR(clr_pnum) | A_BOLD); printw("%d", POS); attroff(COLOR_PAIR(clr_pnum) | A_BOLD); addch(' ' | COLOR_PAIR(clr_bkg)); attron(COLOR_PAIR(clr_tnum)); printw("%d/%d", strlen(input), max - 1); attroff(COLOR_PAIR(clr_tnum)); move(WIN_Y + 3, WIN_X + 1); i = POS - DISPOS; if (i < len / 3) dispos = _strpos(input, _max(0, POS - len / 3)); else if (i > len / 3 * 2) dispos = _nstrpos(input, _min(strlen(input) + 1 - len, POS - len / 3 * 2)); addch(COLOR_PAIR(clr_bkg) | (dispos == 0 ? ' ' : '<')); attron(COLOR_PAIR(clr_nptchr) | A_BOLD); addnstr(p = _arrange(&input[DISPOS]), _WSTRPOS(input, DISPOS + len) - DISPOS); free(p); attroff(COLOR_PAIR(clr_nptchr)); attron(COLOR_PAIR(clr_nptspc)); while (getcurx(stdscr) != WIN_X + 2 + len) addch(' '); attroff(COLOR_PAIR(clr_nptspc) | A_BOLD); addch(COLOR_PAIR(clr_bkg) | (DISPOS < (int)strlen(input) + 1 - len ? '>' : ' ')); move(WIN_Y + 3, WIN_X + 2 + pos - dispos ); refresh (); }