bool project(unsigned char * bilinear, float * dist, float3 voxel_coord, int q_idx) { float3 normal = {bscan_plane_equation_queue[q_idx].a, bscan_plane_equation_queue[q_idx].b, bscan_plane_equation_queue[q_idx].c}; float dist0 = abs(distance(voxel_coord, bscan_plane_equation_queue[q_idx])); float3 p0 = sub(add(voxel_coord, scale(-dist0, normal)), plane_points_queue[q_idx].corner0); float px0 = dot(p0, x_vector_queue[q_idx])/bscan_spacing_x; float py0 = dot(p0, y_vector_queue[q_idx])/bscan_spacing_y; float xa = px0-floor(px0); float ya = py0-floor(py0); int xa0 = (int)px0; int ya0 = (int)py0; bool valid = false; float bilinear0 = 0; if (inrange(xa0, 0, bscan_w) && inrange(ya0, 0, bscan_h) && inrange(xa0+1, 0, bscan_w) && inrange(ya0+1, 0, bscan_h)) if (mask[xa0 + ya0*bscan_w] != 0 && mask[xa0+1 + (ya0+1)*bscan_w] != 0 && mask[xa0+1 + ya0*bscan_w] != 0 && mask[xa0 + (ya0+1)*bscan_w] != 0) { if (bilinear != NULL) bilinear0 = bscans_queue_a(q_idx,xa0,ya0)*(1-xa)*(1-ya) + bscans_queue_a(q_idx,xa0+1,ya0)*xa*(1-ya) + bscans_queue_a(q_idx,xa0,ya0+1)*(1-xa)*ya + bscans_queue_a(q_idx,xa0+1,ya0+1)*xa*ya; valid = true; } *dist = dist0; if (bilinear != NULL) *bilinear = (unsigned char) bilinear0; return valid; }
int visible_pages(int * pageinfo) { unsigned int i, a; float f, pf, s, e, scale; f = pf = 0; s = e = 0; pageinfo = NULL; a = 0; for(i = 0; i < pagec; i++) { scale = (((float)pages[i].sw / pages[i].w) * pages[i].w) / w; pf = f; f -= pages[i].sh; s = scroll; e = scroll - h * scale; if ( inrange(s, e, pf) || inrange(s, e, f) || inrange(pf, f, s) || inrange(pf, f, e) ) { pageinfo = realloc(pageinfo, sizeof(int) * ++a); pageinfo[a - 1] = i; } } return a; }
void pos_from_monte_carlo(int n,double step, Vec *L, double t, Vec* pos) { int i,j; Vec spos,dist; double dU; double chProb,Udiff; //printf("pos3! %.3f\n", pos[3].x); for(i=0; i<n; i++) { spos.x = inrange(pos[i].x + dran_sign()*step,L->x); spos.y = inrange(pos[i].y + dran_sign()*step,L->y); dU = 0.0; for(j=0; j<n; j++) if(i!=j) dU += pair_interaction(dist2(L, &spos, pos+j, &dist)) - pair_interaction(dist2(L, pos+i, pos+j, &dist)); chProb = fmin(1,exp(-dU/t)); if(dran() < chProb) { pos[i].x = spos.x; pos[i].y = spos.y; } } }
void plot_lines(double *xd, double *yd, long n, int line_type, int line_thickness) { int i; /* point index */ int x,y; /* point in terminal coordinates */ struct termentry *t = &term_tbl[term]; int prev = UNDEFINED; /* type of previous point */ double ex, ey; /* an edge point */ double lx[2], ly[2]; /* two edge points */ check_scales("plot_lines"); line_type = set_linetype(line_type); set_linethickness(line_thickness); for (i = 0; i < n; i++) { x = map_x(xd[i]); y = map_y(yd[i]); if ((!clip_lines1 && !clip_lines2) || (inrange(xd[i], xmin, xmax) && inrange(yd[i], ymin, ymax))) { if (prev == INRANGE) { (*t->vector)(x,y); } else if (prev == OUTRANGE) { /* from outrange to inrange */ if (!clip_lines1) { (*t->move)(x,y); } else { edge_intersect(xd[i-1], yd[i-1], xd[i], yd[i], &ex, &ey); (*t->move)(map_x(ex), map_y(ey)); (*t->vector)(x,y); } } else { /* prev == UNDEFINED */ (*t->move)(x,y); (*t->vector)(x,y); } prev = INRANGE; } else { if (prev == INRANGE) { /* from inrange to outrange */ if (clip_lines1) { edge_intersect(xd[i-1], yd[i-1], xd[i], yd[i], &ex, &ey); (*t->vector)(map_x(ex), map_y(ey)); } } else if (prev == OUTRANGE) { /* from outrange to outrange */ if (clip_lines2) { if (two_edge_intersect(xd[i-1], yd[i-1], xd[i], yd[i], lx, ly)) { (*t->move)(map_x(lx[0]), map_y(ly[0])); (*t->vector)(map_x(lx[1]), map_y(ly[1])); } } } prev = OUTRANGE; } } xu_pos = xd[n-1]; yu_pos = yd[n-1]; set_linetype(line_type); }
void pos_from_vel(int n, double deltat, Vec *L, Vec *pos, Vec *vel) { int i; for (i = 0; i < n; i++) { pos[i].x = inrange(pos[i].x + deltat * vel[i].x, L->x); pos[i].y = inrange(pos[i].y + deltat * vel[i].y, L->y); } }
int isOverlap(const Position *position_1, const SDL_Surface *surface_1, const Position *position_2, const SDL_Surface *surface_2){ int x_overlap = inrange(position_1->x, position_2->x, position_2->x + surface_2->w) || inrange(position_2->x, position_1->x, position_1->x + surface_1->w); int y_overlap = inrange(position_1->y, position_2->y, position_2->y + surface_2->h) || inrange(position_2->y, position_1->y, position_1->y + surface_1->h); return x_overlap && y_overlap; }
/** * Sets key to selected key in keymap * Defaults to SDLK_UNKNOWN if no key found in keymap or in Ascii table * Referencekey is used for debugging */ void PlayerControls::setControl(const int player, const std::list<SDL_GameController*>& controllers, const std::map<SDL_GameController*, Sint32>& controllerToDeviceId, lwe::EventCondition& condition, const std::string& keyname) { std::string controllerKeyName = ""; if (lwe::Utils::startsWith(keyname, "controller_")) { controllerKeyName = keyname.substr(11, keyname.size()); } if (keyname.length() == 1) { /* Ascii? if so, ez convert to SDL_Keysym instantly. * see SDL_keysym.h for values mapped to SDL keys. */ // TODO make this an "isValidAscii" method int comparekey = keyname[0]; int customvalues[6] = {8,9,12,13,19,27}; if (inrange(comparekey,91,127) || inrange(comparekey, 32, 64) || in(comparekey, customvalues)) { //if valid ascii condition.addTrigger(std::make_shared<lwe::KeyboardTrigger>(comparekey, true)); } } else if (__keymap.find(keyname) != __keymap.end()) { condition.addTrigger(std::make_shared<lwe::KeyboardTrigger>(__keymap[keyname], true)); } else if (__gameControllerMap.find(controllerKeyName) != __gameControllerMap.end()) { auto it = controllers.begin(); for (int i = 0; i < player; ++i) { it++; } auto controller = (*it); int device = controllerToDeviceId.at(controller); condition.addTrigger(std::make_shared<lwe::GameControllerButtonTrigger>(device, __gameControllerMap[controllerKeyName], true)); } if (!condition.hasTriggers()) { LOG_ERROR("%s was not set.", keyname.c_str()); } }
static void message (void) { #define inrange(x,y) ((x) < (((y)*3)/2) && (x) > (((y)*2)/3)) static int count = 0; static unsigned long lastnumblocks = 0; static unsigned long lasttotalmem = 0; if (!inrange(numblocks, lastnumblocks) || !inrange(totalmem, lasttotalmem) || count++ >= 5000) { fprintf(stderr,"blocks = %lu mem = %luK\n", numblocks, totalmem/1000); count = 0; lastnumblocks = numblocks; lasttotalmem = totalmem; } }
void singleclick(Network::Client* client, u32 serial) { passert_always(client != nullptr && client->chr != nullptr); if (IsCharacter(serial)) { Mobile::Character* chr = nullptr; if (serial == client->chr->serial) chr = client->chr; else chr = find_character(serial); if (chr != nullptr && inrange(client->chr, chr) && !client->chr->is_concealed_from_me(chr)) { if (chr->has_title_guild() && (settingsManager.ssopt.core_handled_tags & 0x1)) send_nametext(client, chr, "[" + chr->title_guild() + "]"); send_nametext(client, chr, chr->name()); std::string tags = create_nametags(chr); if (!tags.empty()) send_nametext(client, chr, tags); } } else // single clicked on an item { Items::Item* item = find_legal_singleclick_item(client->chr, serial); if (item) { send_objdesc(client, item); } } }
bool send_signal(struct flagged_int *p, void *data_) { struct trace_data *data = (struct trace_data*) data_; const int *signal; int count = 0; if (inrange(p->state, STATE_ATTACHED, STATE_DETACHED)) { for (signal = data->d.signal; *signal != SIGINVALID; signal++) { if (kill((pid_t) p->i, *signal) == 0) { p->state = data->target_state; if (data->target_state == STATE_TERMINATED) p->valid = false; count++; } else { p->valid = false; switch (errno) { case ESRCH: p->state = STATE_TERMINATED; break; default: assert(errno != EINVAL); UNEXPECTED_STATE(); break; } break; } } } if (count) data->count++; return true; }
int check(int si, int sj, int di, int dj) { int i = si, j = sj, k, cnt = 0, prev = cell[si][sj]; if(!inrange(0, si + (kth-1)*di, row-1) || !inrange(0, sj + (kth-1)*dj, col-1)) return '.'; for(k=0; k<kth; k++) { if(cell[i][j] == '.') return '.'; if(cell[i][j] != prev) return '.'; cnt += cell[i][j]; i += di; j += dj; } if(cnt == kth*'o') return 'o'; else if(cnt == kth*'x') return 'x'; return '.'; }
int parse_options(int key, char *arg, struct argp_state *state) { int r; if ((r = argp_action_wrapper(key, arg, state)) != ARGP_ERR_UNKNOWN) { switch (key) { case 'i': if (r == EINVAL || !inrange(waitproc_options.interval_sec, 1, UINT_MAX+1)) { argp_error(state, "'%s' is not a time period from 1 to %u seconds.", arg, UINT_MAX); return EINVAL; } break; } return r; } switch (key) { case ARGP_KEY_ARG: { unsigned int remainig_argc = (unsigned int)(state->argc - state->next + 1); a_flagged_int_init(&waitproc_options.pids, remainig_argc); if (parse_pids(remainig_argc, &state->argv[state->next-1]) > 0) { state->next = state->argc; return 0; } // else: fall through } case ARGP_KEY_NO_ARGS: argp_usage(state); // don't return or fall through } return ARGP_ERR_UNKNOWN; }
//Connect randomly to one of the adjacent points in the spanning tree void con_frnt() { int n, which, ydelt = 0, xdelt = 0; int choice[4]; int cnt = 0, y, x; //Choose a random frontier n = rnd(frcnt); ny = fr_y[n]; nx = fr_x[n]; fr_y[n] = fr_y[frcnt - 1]; fr_x[n] = fr_x[--frcnt]; //Count and collect the adjacent points we can connect to if (maze_at({ nx, ny - 2 }) > 0) choice[cnt++] = 0; if (maze_at({ nx, ny + 2 }) > 0) choice[cnt++] = 1; if (maze_at({ nx - 2, ny }) > 0) choice[cnt++] = 2; if (maze_at({ nx + 2, ny }) > 0) choice[cnt++] = 3; //Choose one of the open places, connect to it and then the task is complete which = choice[rnd(cnt)]; splat({ nx,ny }); switch (which) { case 0: which = 1; ydelt = -1; break; case 1: which = 0; ydelt = 1; break; case 2: which = 3; xdelt = -1; break; case 3: which = 2; xdelt = 1; break; } y = ny + ydelt; x = nx + xdelt; if (inrange({ x,y })) splat({ x,y }); }
static bool raft_appendable(raft_t r, int previndex, int prevterm) { int low, high; low = RAFT_LOG_FIRST_INDEX(r); if (low == 0) low = -1; // allow appending at the start high = RAFT_LOG_LAST_INDEX(r); if (!inrange(low, previndex, high)) { debug( "previndex %d is outside log range %d-%d\n", previndex, low, high ); return false; } if (previndex != -1) { raft_entry_t *pe = &RAFT_LOG(r, previndex); if (pe->term != prevterm) { debug("log term %d != prevterm %d\n", pe->term, prevterm); return false; } } return true; }
/* . * given the name of a parameter, print it on t_out, the task pipe channel. */ void o_inspect (memel *argp) { char *pname = (char *) argp; char *pk, *t, *p, *f; struct param *pp; struct operand o; breakout (pname, &pk, &t, &p, &f); pp = paramsrch (pk, t, p); if (*f == FN_NULL && (pp->p_type & PT_LIST)) { /* Hitting EOF from a list is ok during an inspect stmt so * avoid using paramget() with its EOF error. * readlist() may set P_LEOF. */ o = readlist (pp); if ((pp->p_flags & P_LEOF) || inrange (pp, &o)) pushop (&o); else query (pp); } else validparamget (pp, *f); o = popop(); if (cldebug && (o.o_type & OT_BASIC) == OT_STRING) eprintf ("Inspect--%s\n", o.o_val.v_s); prop (&o); tprintf ("\n"); }
static void fixgroups (bool use_uid, uid_t uid, bool use_gid, gid_t gid) { switch (0) case 0: case (NGROUPS_MAX >= 3):; if (use_gid && !inrange (gid)) fatal << "gid " << gid << " not in range of reserved group ids\n"; GETGROUPS_T group_buf[NGROUPS_MAX + 2]; GETGROUPS_T *groups = group_buf + 2; GETGROUPS_T *grouplim; { int ngroups = getgroups (NGROUPS_MAX, groups); if (ngroups < 0) fatal ("getgroups: %m\n"); grouplim = groups + ngroups; } gid_t g0 = (gid_t) -1; // XXX - initialize to placate egcs if (sfsaid_shift) g0 = groups < grouplim ? *groups++ : getgid (); // Clear any old marker groups for (GETGROUPS_T *gp = groups; gp < grouplim; gp++) if (*gp == sfs_gid) { grouplim = groups; break; } if (use_uid) { grouplim = groups; *grouplim++ = uid; if (use_gid) *grouplim++ = gid; *grouplim++ = sfs_gid; } else { if (groups < grouplim && inrange (*groups)) groups++; if (use_gid) *--groups = gid; } if (sfsaid_shift) *--groups = g0; if (setgroups (min<int> (grouplim - groups, NGROUPS_MAX), groups) < 0) fatal ("setgroups: %m\n"); }
void runSuccess() { log(1.0); log(0.0); log(-1.0); log(outrange()); log(inrange()); log(anydouble()); }
void runSuccess() { log2f(1.0f); log2f(0.0f); log2f(-1.0f); log2f(outrange()); log2f(inrange()); log2f(anyfloat()); }
// Find a file containing info about the given 'xid'. Return the clogfile // pointer, or NULL if not found. static clogfile_t *clog_xid_to_file(clog_t clog, xid_t xid) { clogfile_chain_t *cur; for (cur = clog->lastfile; cur; cur = cur->prev) { if (inrange(cur->file.min, xid, cur->file.max)) { return &cur->file; } } return NULL; }
void runSuccess() { asin(1.0); asin(0.0); asin(-1.0); asin(2.0); asin(-2.0); asin(inrange()); asin(outrange()); asin(anydouble()); }
void runSuccess() { atanhl(1.0L); atanhl(0.0L); atanhl(-1.0L); atanhl(2.0L); atanhl(-2.0L); atanhl(inrange()); atanhl(outrange1()); atanhl(outrange2()); atanhl(anylongdouble()); }
void add_frnt(Coord p) { if (frcnt == MAXFRNT - 1) debug("MAZE DRAWING ERROR #3\n"); if (inrange(p) && game->level().get_tile(p) == NOTHING) { game->level().set_tile(p, FRONTIER); fr_y[frcnt] = p.y; fr_x[frcnt++] = p.x; } }
bool check_inrange(xid_t min, xid_t x, xid_t max, bool check) { bool result = inrange(min, x, max); bool ok = result == check; printf( "%u <= %u <= %u == %s (%s)\n", min, x, max, result ? "true" : "false", ok ? "ok" : "FAILED" ); return ok; }
void runSuccess() { acoshf(1.0f); acoshf(0.0f); acoshf(-1.0f); acoshf(2.0f); acoshf(-2.0f); acoshf(NAN); acoshf(INFINITY); acoshf(inrange()); acoshf(outrange()); acoshf(anyfloat()); }
// Get the current status of a voxel unsigned char getvoxel(int x, int y, int z) { if (inrange(x, y, z)) { if (cube[z][y] & (1 << x)) { return 0x01; } else { return 0x00; } } }
void UOClientInterface::bcast_vital_changed( Mobile::Character* who, const Core::Vital* vital ) const { const ClientVitalUpdaters& cvu = vital_updaters[vital->vitalid]; if ( cvu.others_vital_changed != NULL ) { for ( auto &client : clients ) { if ( client->ready && inrange( who, client->chr ) ) { cvu.others_vital_changed( client, who, vital ); } } } }
int wiz_hit(struct monst *mtmp) { /* if we have stolen or found the amulet, we disappear */ if(mtmp->minvent && mtmp->minvent->olet == AMULET_SYM && mtmp->minvent->spe == 0) { /* vanish -- very primitive */ fall_down(mtmp); return(1); } /* if it is lying around someplace, we teleport to it */ if(!carrying(AMULET_OF_YENDOR)) { struct obj *otmp; for(otmp = fobj; otmp; otmp = otmp->nobj) if(otmp->olet == AMULET_SYM && !otmp->spe) { if((u.ux != otmp->ox || u.uy != otmp->oy) && !m_at(otmp->ox, otmp->oy)) { /* teleport to it and pick it up */ mtmp->mx = otmp->ox; mtmp->my = otmp->oy; freeobj(otmp); mpickobj(mtmp, otmp); pmon(mtmp); return(0); } goto hithim; } return(0); /* we don't know where it is */ } hithim: if(rn2(2)) { /* hit - perhaps steal */ /* if hit 1/20 chance of stealing amulet & vanish - amulet is on level 26 again. */ if(hitu(mtmp, d(mtmp->data->damn,mtmp->data->damd)) && !rn2(20) && stealamulet(mtmp)) ; } else inrange(mtmp); /* try magic */ return(0); }
void set_alarm() { assert(!waitproc_flags_test(WAITPROC_FLAG_ALARMSET) && timespec_iszero(&waitproc_options.wait_start)); verify(clock_gettime(CLOCK_MONOTONIC, &waitproc_options.wait_start) == 0); if (waitproc_options.interval_sec) { struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_handler = &signal_handler_store_signum; waitproc_options.last_signal = SIGINVALID; sigaction(SIGALRM, &action, NULL); assert(inrange(waitproc_options.interval_sec, 1, UINT_MAX+1)); alarm((unsigned int) waitproc_options.interval_sec); waitproc_flags_set(WAITPROC_FLAG_ALARMSET); } }
void statrequest( Network::Client* client, u32 serial ) { if ( serial == client->chr->serial ) { send_full_statmsg( client, client->chr ); } else { Mobile::Character* chr = find_character( serial ); if ( chr != NULL ) { if ( client->chr->is_visible_to_me( chr ) ) { if ( inrange( client->chr, chr ) ) send_short_statmsg( client, chr ); } } } }
MME_ERROR MME_AbortCommand(MME_TransformerHandle_t handle, MME_CommandId_t cmdId) { MME_ERROR Status; if (!TransformContexts[handle].Open) return MME_INVALID_HANDLE; if (!inrange(cmdId, 0, 255) || (TransformContexts[handle].OutstandingCommands[cmdId] == NULL)) return MME_INVALID_ARGUMENT; Status = AbortFunction(TransformContexts[handle].Context, cmdId); if (Status == MME_SUCCESS) TransformContexts[handle].OutstandingCommands[cmdId] = NULL; return Status; }