int check_cmd(int argc, char **argv) { int i; int cycles; i = 1; cycles = -1; if (!ft_strcmp(argv[i], "-dump")) { if (i + 2 < argc) { if ((cycles = ft_atoi(argv[i + 1])) <= 0) ft_er("Cycle must be positiv"); i += 2; } else ft_er("Wrong number of arguments"); } while (i < argc) { i = check_n(argc, argv, i); i = check_a(argc, argv, i); i = check_c(argv, i); } return (cycles); }
static int treverse (lua_State *L) { lua_Integer begin, end; checktab(L, 1, TAB_RW); begin = luaL_optinteger(L, 2, 1); end = luaL_opt(L, luaL_checkinteger, 3, check_n(L, 1)); lua_settop(L, 1); reverse(L, begin, end); return 0; }
void main(int ac, char **av) { if (ac == 2) { check_arg(av[1]); borwein(check_n(atof(av[1]))); } else exit_write("Usage\t./110borwein [n]\tWhen n is a number superior or equal to 0"); }
static int fill_program(t_program *program, int i, int argc, const char **argv) { if (check_a(program, i, argc, argv) == RET_FAILURE) return (RET_FAILURE); if (check_n(program, i, argc, argv) == RET_FAILURE) return (RET_FAILURE); if (check_file(program, i, argv) == RET_FAILURE) return (RET_FAILURE); return (RET_SUCCESS); }
void ps1_checker_2(s_ps1 ps1_st, bool *escaped, bool *checked) { check_n(ps1_st, escaped, checked); check_dollar(ps1_st, escaped, checked); check_a(ps1_st, escaped, checked); check_e(ps1_st, escaped, checked); check_r(ps1_st, escaped, checked); }
static int tshuffle (lua_State *L) { lua_Integer begin, end; checktab(L, 1, TAB_RW); begin = luaL_optinteger(L, 2, 1); end = luaL_opt(L, luaL_checkinteger, 3, check_n(L, 1)); while (end >= begin) { double f = l_rand() * (1.0/(L_RANDMAX+1.0)); lua_Integer j = begin + (lua_Integer)(f * (end-begin+1)); lua_geti(L, 1, end); lua_geti(L, 1, j); lua_seti(L, 1, end); lua_seti(L, 1, j); --end; } return 0; }
static int trotate (lua_State *L) { lua_Integer n, begin, end; checktab(L, 1, TAB_RW); n = -luaL_checkinteger(L, 2); begin = luaL_optinteger(L, 3, 1); end = luaL_opt(L, luaL_checkinteger, 4, check_n(L, 1)); if (end > begin) { n %= end - begin + 1; if (n < 0) n += end - begin + 1; if (n != 0) { lua_settop(L, 1); reverse(L, begin, begin+n-1); reverse(L, begin+n, end); reverse(L, begin, end); } } return 0; }
static int tconcat (lua_State *L) { luaL_Buffer b; lua_Integer i, last; size_t lsep; const char *sep; checktab(L, 1, TAB_R); sep = luaL_optlstring(L, 2, "", &lsep); i = luaL_optinteger(L, 3, 1); last = luaL_opt(L, luaL_checkinteger, 4, check_n(L, 1)); luaL_buffinit(L, &b); for (; i < last; i++) { addfield(L, &b, i); luaL_addlstring(&b, sep, lsep); } if (i == last) /* add last value (if interval was not empty) */ addfield(L, &b, i); luaL_pushresult(&b); return 1; }
// Generate light and refractive index profile light_rays light_gen(dimensions dim, double max_vel, double angle, dimensions origin, double radius){ light_rays ray_diagram; // create rays for (size_t i = 0; i < lightnum; i++){ ray_diagram.ray[i].x = (double)i * dim.x / lightnum; ray_diagram.ray[i].y = 0; //ray_diagram.ray[i].y = cos(angle); //ray_diagram.ray[i].x = sin(angle); ray_diagram.ray_vel[i].x = max_vel * cos(angle); ray_diagram.ray_vel[i].y = max_vel * sin(angle); ray_diagram.index[i] = check_n(ray_diagram.ray[i].x, ray_diagram.ray[i].y, origin, radius); } return ray_diagram; }
int main (int argc, char *argv[]) { if (argc > 1 && strcmp (argv[1], "-s") == 0) option_libc_scanf = 1; tests_start (); mp_trace_base = 16; check_z (); check_q (); check_f (); check_n (); check_misc (); unlink (TEMPFILE); tests_end (); exit (0); }
int main (int argc, char *argv[]) { if (argc > 1 && strcmp (argv[1], "-s") == 0) option_check_printf = 1; tests_start (); check_vfprintf_fp = fopen (CHECK_VFPRINTF_FILENAME, "w+"); ASSERT_ALWAYS (check_vfprintf_fp != NULL); check_z (); check_q (); check_f (); check_limb (); check_n (); check_misc (); ASSERT_ALWAYS (fclose (check_vfprintf_fp) == 0); unlink (CHECK_VFPRINTF_FILENAME); tests_end (); exit (0); }
static int treplace (lua_State *L) { lua_Integer len, tpos, start, end, start2, end2, i; len = aux_getn(L, 1, TAB_RW); if (lua_type(L, 2) == LUA_TNUMBER) { start = luaL_checkinteger(L, 2); luaL_argcheck(L, start >= 1 && start <= len+1, 2, "index out of bounds"); if (lua_type(L, 3) == LUA_TNUMBER) { end = luaL_checkinteger(L, 3); luaL_argcheck(L, end >= start-1 && end <= len, 3, "invalid end index"); tpos = 4; } else { end = start; if (end > len) end = len; tpos = 3; } } else { start = len+1; end = len; tpos = 2; } checktab(L, tpos, TAB_R); start2 = luaL_optinteger(L, tpos+1, 1); end2 = luaL_opt(L, luaL_checkinteger, tpos+2, check_n(L, tpos)); luaL_argcheck(L, end2 >= start2-1, tpos+2, "invalid end index"); if (end2-start2 > end-start) { /* array needs to grow */ lua_pushinteger(L, len+end2-start2-end+start); lua_setfield(L, 1, "n"); /* t.n = number of elements */ } if (start <= len) { /* replace values */ lua_Integer shift = end2-start2-end+start; if (shift < 0) { /* shift to left */ for (i = end+1; i <= len; ++i) { lua_geti(L, 1, i); lua_seti(L, 1, i+shift); } for (i = len; i > len+shift; --i) { lua_pushnil(L); lua_seti(L, 1, i); } } else if (shift != 0) { /* shift to right */ for (i = len-shift+1; i <= len; ++i) { lua_geti(L, 1, i); lua_seti(L, 1, i+shift); } for (i = len-shift; i > end; --i) { lua_geti(L, 1, i); lua_seti(L, 1, i+shift); } } } /* copy from list2 to list1 */ for (i = start2; i <= end2; ++i) { lua_geti(L, tpos, i); lua_seti(L, 1, start+i-start2); } /* array must shrink */ if (end2-start2 < end-start) { lua_pushinteger(L, len+end2-start2-end+start); lua_setfield(L, 1, "n"); /* t.n = number of elements */ } return 0; }
// Propagate light through media light_rays propagate(light_rays ray_diagram, double step_size, double max_vel, dimensions origin, double radius, std::ofstream &output){ double index_p, theta, theta_p; double iratio, dotprod; // move simulation every timestep for (size_t i = 0; i < time_res; i++){ for (size_t j = 0; j < lightnum; j++){ ray_diagram.ray[j].x += ray_diagram.ray_vel[j].x * step_size; ray_diagram.ray[j].y += ray_diagram.ray_vel[j].y * step_size; if (ray_diagram.index[j] != check_n(ray_diagram.ray[j].x, ray_diagram.ray[j].y, origin, radius)){ index_p = check_n(ray_diagram.ray[j].x, ray_diagram.ray[j].y, origin, radius); std::cout << index_p << '\t' << i << '\t' << j << '\n'; /* // Non vector form theta = atan2(ray_diagram.ray_vel[j].y, ray_diagram.ray_vel[j].x); theta_p = asin((ray_diagram.index[j] / index_p) * sin(theta)); ray_diagram.ray_vel[j].y = max_vel * sin(theta_p); ray_diagram.ray_vel[j].x = max_vel * cos(theta_p); */ // Vector form -- Solution by Gustorn! double r = ray_diagram.index[j] / index_p; double mag = std::sqrt(ray_diagram.ray_vel[j].x * ray_diagram.ray_vel[j].x + ray_diagram.ray_vel[j].y * ray_diagram.ray_vel[j].y); double ix = ray_diagram.ray_vel[j].x / mag; double iy = ray_diagram.ray_vel[j].y / mag; // c for later; Normal was: [-1, 0] double c = find_c(ix, iy, origin, radius); double k = 1.0 - r * r * (1.0 - c * c); if (k < 0.0) { // Do whatever } else { double k1 = std::sqrt(k); ray_diagram.ray_vel[j].x = r * ix - (r * c - k1); ray_diagram.ray_vel[j].y = r * iy; } ray_diagram.index[j] = index_p; } } /* output << ray_diagram.ray[5].x <<'\t'<< ray_diagram.ray[5].y << '\t' << ray_diagram.ray_vel[5].x <<'\t'<< ray_diagram.ray_vel[5].y << '\n'; */ for (size_t q = 0; q < lightnum; q++){ output << ray_diagram.ray[q].x <<'\t'<< ray_diagram.ray[q].y << '\t' << ray_diagram.ray_vel[q].x <<'\t'<< ray_diagram.ray_vel[q].y << '\n'; } output << '\n' << '\n'; } return ray_diagram; }