void pike_module_init( void ) { STRS(data) = make_shared_string("data"); STRS(file) = make_shared_string("file"); STRS(method) = make_shared_string("method"); STRS(protocol) = make_shared_string("protocol"); STRS(query) = make_shared_string("query"); STRS(raw_url) = make_shared_string("raw_url"); SVAL(data)->type = T_STRING; SVAL(file)->type = T_STRING; SVAL(method)->type = T_STRING; SVAL(protocol)->type = T_STRING; SVAL(query)->type = T_STRING; SVAL(raw_url)->type = T_STRING; add_function_constant( "parse_headers", f_parse_headers, "function(string:mapping)", 0); add_function_constant( "parse_query_string", f_parse_query_string, "function(string,mapping:void)", OPT_SIDE_EFFECT); add_function_constant( "get_address", f_get_address, "function(string:string)", 0); start_new_program(); ADD_STORAGE( buffer ); add_function( "append", f_buf_append, "function(string:int)", OPT_SIDE_EFFECT ); add_function( "create", f_buf_create, "function(mapping,mapping:void)", 0 ); set_exit_callback(free_buf_struct); set_init_callback(alloc_buf_struct); parsehttp_program = end_program(); add_program_constant("ParseHTTP", parsehttp_program, 0); }
struct arc *leaf_to_arc (struct leaf *lf) { int j, k; struct arc *a; struct vertex *v; struct cept *ex; a = allocate_arc (); if (a == NULL) { add_object (tail_cept, ARC, "leaf arc"); add_function (tail_cept, "leaf_to_arc"); add_source (tail_cept, "msrender.c"); return(NULL); } a -> cir = lf -> cir; for (j = 0; j < 2; j++) { v = allocate_vertex (); if (error()) { add_object (tail_cept, VERTEX, "leaf vertex"); add_function (tail_cept, "leaf_to_arc"); add_source (tail_cept, "msrender.c"); return(NULL); } for (k = 0; k < 3; k++) v -> center[k] = lf -> ends[j][k]; a -> vtx[j] = v; } return (a); }
int closest (struct surface *current_surface, struct leaf *lf, double pnt[3]) { int j, k, jmin, nch; double dmin; double dta[MAXPA]; double several_centers[MAXPA][3], several_radii[MAXPA]; struct cept *ex; if (lf -> type == SPHERE && lf -> shape == CONVEX) nch = 1; else if (lf -> shape == SADDLE) nch = 2; else if (lf -> type == SPHERE && lf -> shape == CONCAVE) nch = 3; else if (lf -> type == CYLINDER) nch = 2; else if (lf -> type == TORUS && lf -> shape == CONVEX) nch = 1; else { ex = new_cept (LOGIC_ERROR, NOT_FOUND, FATAL_SEVERITY); add_function (ex, "closest"); add_source (ex, "msrender.c"); add_long (ex, "leaf type", (long) lf -> type); add_long (ex, "leaf shape", (long) lf -> shape); return(0); } if (nch <= 1) return (lf -> atmnum[0]); if (lf -> atmnum[3] > 0) nch = 4; for (j = 0; j < nch; j++) { for (k = 0; k < 3; k++) several_centers[j][k] = *(current_surface -> atom_centers + 3 * (lf -> atmnum[j] - 1) + k); several_radii[j] = *(current_surface -> atom_radii + (lf -> atmnum[j] - 1)); } /* find closest atom */ for (j = 0; j < nch; j++) dta[j] = distance (pnt, several_centers[j]) - several_radii[j]; /* initialization */ dmin = 1000000.0; jmin = -1; for (j = 0; j < nch; j++) if (dta[j] < dmin) { dmin = dta[j]; jmin = j; } if (jmin < 0 || jmin >= nch) { ex = new_cept (LOGIC_ERROR, NOT_FOUND, FATAL_SEVERITY); add_function (ex, "closest"); add_source (ex, "msrender.c"); add_message (ex, "cannot find closest atom"); return (0); } return (lf -> atmnum[jmin]); }
/* create permanent tori */ void create_permanent (struct surface *this_srf) { int k; long niter; char message[MAXLINE]; struct arc *arcptr; struct torus *torus_ptr; struct central *central_ptr; struct cept *ex; /* create permanent tori for central circles */ this_srf -> n_tori = 0; if (this_srf -> n_pair > 0) { for (central_ptr = this_srf -> head_central; central_ptr != NULL; central_ptr = central_ptr -> next) { torus_ptr = allocate_torus (); if (torus_ptr == NULL) { ex = new_cept (MEMORY_ERROR, ALLOCATION, FATAL_SEVERITY); add_object (ex, TORUS, "torus"); add_function (ex, "create_permanent"); add_source (ex, "mstorus.c"); return; } /* store data in structure */ for (k = 0; k < 3; k++) { torus_ptr -> center[k] = central_ptr -> center[k]; torus_ptr -> axis[k] = central_ptr -> axis[k]; } torus_ptr -> radius = central_ptr -> radius; torus_ptr -> atm[0] = central_ptr -> sph[0]; torus_ptr -> atm[1] = central_ptr -> sph[1]; torus_ptr -> free = central_ptr -> free; torus_ptr -> buried = 0; torus_ptr -> first_arc = central_ptr -> first_arc; /* set up arc -> torus pointers */ niter = 0; for (arcptr = torus_ptr -> first_arc; arcptr != NULL; arcptr = arcptr -> next, niter++) { arcptr -> tor = torus_ptr; if (niter > 2 * this_srf -> n_atom) { add_object (ex, ARC, "arcptr"); add_function (ex, "create_permanent"); add_source (ex, "mstorus.c"); add_message (ex, "infinite loop for torus <--> arc"); return; } } if (this_srf -> head_torus == NULL) this_srf -> head_torus = torus_ptr; else this_srf -> tail_torus -> next = torus_ptr; this_srf -> tail_torus = torus_ptr; this_srf -> n_tori++; torus_ptr -> number = this_srf -> n_tori; } } sprintf (message,"%8ld tori", this_srf -> n_tori); inform(message); }
int subdivide_leaf (double fine_pixel, struct leaf *lf, double **pntptr) { int j, k, n; double alpha; struct arc *lfarc; struct vertex *lfvtx[2]; struct cept *ex; if (lf -> cir -> radius <= 0.0) { return (0); } lfarc = allocate_arc (); if (lfarc == NULL) { add_object (tail_cept, ARC, "leaf arc"); add_function (tail_cept, "subdivide_leaf"); add_source (tail_cept, "msrender.c"); return (0); } for (j = 0; j < 2; j++) { lfvtx[j] = allocate_vertex (); if (error()) { add_object (tail_cept, VERTEX, "leaf vertex"); add_function (tail_cept, "subdivide_leaf"); add_source (tail_cept, "msrender.c"); return (0); } } /* convert to arc for subdivision */ lfarc -> cir = lf -> cir; for (k = 0; k < 3; k++) { lfvtx[0] -> center[k] = lf -> ends[0][k]; lfvtx[1] -> center[k] = lf -> ends[1][k]; } for (j = 0; j < 2; j++) lfarc -> vtx[j] = lfvtx[j]; /* angular parameter for subdivision */ alpha = fine_pixel / (lf -> cir -> radius); /* call geometric subdivision function */ n = render_sub_arc (lfarc, pntptr, alpha); if (error()) return(0); free_arc (lfarc); for (j = 0; j < 2; j++) free_vertex (lfvtx[j]); return (n); /* return number of subdivision points */ }
void def(std::string const &name, R (*f)(BOOST_PP_ENUM_PARAMS(n,T)), policies const &p = policies()) { add_function(name, boost::shared_ptr<details::callback_base>( new details::BOOST_PP_CAT(callback,n)<R BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n,T)>(f)), p); }
std::unique_ptr<graphics::plot> create_function_plot(const char *title, unsigned flags) { auto p = std::make_unique<graphics::plot>(graphics::plot::show_units | graphics::plot::auto_limits); p->set_clip_mode(false); p->set_title(title); agg::rgba8 blue(0, 0, 180, 255); agg::rgba8 red(180, 0, 0, 255); const double x0 = 3.14159265358979323846/2, x1 = 8 * 2 * 3.14159265358979323846; auto fsin = [](double x) { return std::sin(x) / x; }; auto fcos = [](double x) { return std::cos(x) / x; }; add_function(*p, x0, x1, fsin, blue, flags); add_function(*p, x0, x1, fcos, red, flags); p->commit_pending_draw(); return p; }
void add_function(const std::string &name, const std::string &source, const std::map<std::string, std::string> &definitions) { typedef std::map<std::string, std::string>::const_iterator iter; std::stringstream s; // add #define's for(iter i = definitions.begin(); i != definitions.end(); i++){ s << "#define " << i->first; if(!i->second.empty()){ s << " " << i->second; } s << "\n"; } s << source << "\n"; // add #undef's for(iter i = definitions.begin(); i != definitions.end(); i++){ s << "#undef " << i->first << "\n"; } add_function(name, s.str()); }
int along (struct edge *edg, double axis[3]) { int orn, k, sgn; double dt; double vect[3]; struct vertex *vtx1, *vtx2; struct arc *a; struct cept *ex; a = edg -> arcptr; vtx1 = a -> vtx[0]; vtx2 = a -> vtx[1]; if (vtx1 == NULL || vtx2 == NULL) { ex = new_cept (PARAMETER_ERROR, NULL_VALUE, FATAL_SEVERITY); add_object (ex, VERTEX, "vtx1 or vtx2"); add_function (ex, "along"); add_source (ex, "msrender.c"); return(0); } orn = edg -> orn; sgn = 1 - 2 * orn; for (k = 0; k < 3; k++) vect[k] = vtx2 -> center[k] - vtx1 -> center[k]; dt = dot_product (vect, axis) * sgn; return (dt > 0.0); }
bool check_prog(struct prog* prog, struct symtable *syms) { bool correct = true; fill_std_types(syms); fill_std_fun(syms); constdecllist_t consts = prog->entry_point->const_decls; for(unsigned i =0; i < consts.size; ++i) correct = correct && check_const(list_nth(consts,i), syms, true); correct = correct && add_types(syms, prog->entry_point->type_decls); correct = correct && add_variables(syms, prog->entry_point->var_decl, true, false, false); for(unsigned i = 0; i < prog->algos.size; ++i) { struct algo* al = list_nth(prog->algos, i); struct function* f = malloc(sizeof(struct function)); f->ident = al->ident; f->ret = find_type(syms->types, al->return_type); f->arg = get_args(al->declarations->param_decl, syms); add_function(syms->functions, f); } for (unsigned i = 0; i < prog->entry_point->instructions.size; ++i) if (!check_inst( prog->entry_point->instructions.data[i], find_type(syms->types, TYPE_INT), syms)) correct = false; for(unsigned i = 0; i < prog->algos.size; ++i) { struct algo* al = list_nth(prog->algos, i); if (!check_algo(al, syms)) correct = false; } return correct; }
void compute_torus_center (double probe_radius, struct sphere *sphere1,struct sphere *sphere2, double torus_center[3]) { int k; double radius1, radius2, asymmetry, distance12_squared; char message[MAXLINE]; struct cept *ex; distance12_squared = distance_squared (sphere1 -> center, sphere2 -> center); if (distance12_squared <= 0.0) { ex = new_cept (GEOMETRY_ERROR, DEGENERACY, FATAL_SEVERITY); add_function (ex, "compute_torus_center"); add_source (ex, "mstorus.c"); add_message (ex, "coincident atoms"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } radius1 = sphere1 -> radius; radius2 = sphere2 -> radius; asymmetry = (radius1 + probe_radius) * (radius1 + probe_radius) - (radius2 + probe_radius) * (radius2 + probe_radius); for (k = 0; k < 3; k++) torus_center[k] = 0.5 * (sphere1 -> center[k] + sphere2 -> center[k]) + 0.5 * ( asymmetry / distance12_squared) * (sphere2 -> center[k] - sphere1 -> center[k]); }
VariableMap::VariableMap( int function_count, std::vector<bool> common ) : input_var_c(common.size()), output_var_c(0) { for (int i = 0; i < function_count; ++i) { add_function( common ); } }
/** * Increment of a given key, by number $value * * @param string $keyName * @param long $value * @return mixed */ PHP_METHOD(Phalcon_Cache_Backend_Apc, increment){ zval *key_name, *value = NULL, prefix = {}, prefixed_key = {}, cached_content = {}; phalcon_fetch_params(0, 1, 1, &key_name, &value); if (!value || Z_TYPE_P(value) == IS_NULL) { value = &PHALCON_GLOBAL(z_one); } else { PHALCON_ENSURE_IS_LONG(value); } phalcon_read_property(&prefix, getThis(), SL("_prefix"), PH_NOISY); PHALCON_CONCAT_SVV(&prefixed_key, "_PHCA", &prefix, key_name); phalcon_update_property_zval(getThis(), SL("_lastKey"), &prefixed_key); if (SUCCESS == phalcon_function_exists_ex(SL("apc_inc"))) { PHALCON_RETURN_CALL_FUNCTIONW("apc_inc", &prefixed_key, value); } else { PHALCON_CALL_FUNCTIONW(&cached_content, "apc_fetch", &prefixed_key); if (Z_TYPE(cached_content) == IS_LONG) { add_function(return_value, &cached_content, value); PHALCON_CALL_METHODW(NULL, getThis(), "save", key_name, return_value); } else { RETURN_FALSE; } } }
void litehtml::el_before_after_base::add_style(const litehtml::style& st) { html_tag::add_style(st); tstring content = get_style_property(_t("content"), false, _t("")); if(!content.empty()) { int idx = value_index(content.c_str(), content_property_string); if(idx < 0) { tstring fnc; tstring::size_type i = 0; while(i < content.length() && i != tstring::npos) { if(content.at(i) == _t('"')) { fnc.clear(); i++; tstring::size_type pos = content.find(_t('"'), i); tstring txt; if(pos == tstring::npos) { txt = content.substr(i); i = tstring::npos; } else { txt = content.substr(i, pos - i); i = pos + 1; } add_text(txt); } else if(content.at(i) == _t('(')) { i++; litehtml::trim(fnc); litehtml::lcase(fnc); tstring::size_type pos = content.find(_t(')'), i); tstring params; if(pos == tstring::npos) { params = content.substr(i); i = tstring::npos; } else { params = content.substr(i, pos - i); i = pos + 1; } add_function(fnc, params); fnc.clear(); } else { fnc += content.at(i); i++; } } } } }
/* write face */ void write_faces (struct surface *srf, FILE *fp_surface) { int icyc; long n_face; char message[MAXLINE]; struct face *fac; struct facbin facout; struct variety *vty; struct cept *ex; n_face = 0; icyc = 1; for (fac = srf -> head_face; fac != NULL; fac = fac -> next) { vty = fac -> vty; if (vty == NULL) { ex = new_cept (POINTER_ERROR, NULL_VALUE, FATAL_SEVERITY); add_function (ex, "write_faces"); add_source (ex, "msrollio.c"); return; } facout.error = 0; facout.vtynum = vty -> number; sprintf (message, "%8ld face %8ld variety %1d shape", n_face, vty -> number, (int) fac -> shape); informd (message); switch ((int) fac -> shape) { case CONVEX: facout.type = CONVEX_FACE_TYPE; facout.fcynum = ((fac -> n_cycle > 0) ? icyc : 0); icyc += fac -> n_cycle; break; case SADDLE: facout.type = SADDLE_FACE_TYPE; facout.fcynum = icyc; if (fac -> n_arc == 2) icyc += 2; else icyc++; break; case CONCAVE: facout.type = CONCAVE_FACE_TYPE; /* problem concave face */ if (fac -> problem) facout.error = 1; facout.fcynum = icyc; if (fac -> ptr.prb -> low) icyc += fac -> n_cycle; else icyc++; break; default: set_error1 ("write_faces: invalid face shape"); return; } facout.comp = fac -> comp; fwrite ((char *) &facout, sizeof (facout), 1, fp_surface); n_face++; } sprintf (message, "%8ld faces written", n_face); informd (message); }
Function *FunctionManager::build_function_internal( uint16_t address, const uint8_t *ct_memory) { Registers ®isters = mpu_->internal->registers_; TRACE("Building Function for code at 0x" << std::hex << std::setfill('0') << std::setw(4) << registers.pc); FunctionBuilder fb(mpu_, ct_memory, code_at_address_, registers.pc); boost::shared_ptr<Function> f(fb.build()); add_function(f); return f.get(); }
/* Initialize and start module */ void pike_module_init( void ) { STRS(data) = make_shared_string("data"); STRS(file) = make_shared_string("file"); STRS(method) = make_shared_string("method"); STRS(protocol) = make_shared_string("protocol"); STRS(query) = make_shared_string("query"); STRS(raw_url) = make_shared_string("raw_url"); SVAL(data)->type = T_STRING; SVAL(file)->type = T_STRING; SVAL(method)->type = T_STRING; SVAL(protocol)->type = T_STRING; SVAL(query)->type = T_STRING; SVAL(raw_url)->type = T_STRING; add_function_constant( "parse_headers", f_parse_headers, "function(string:mapping)", 0); add_function_constant( "parse_query_string", f_parse_query_string, "function(string,mapping:void)", OPT_SIDE_EFFECT); add_function_constant( "parse_prestates", f_parse_prestates, "function(string,multiset,multiset:string)", OPT_SIDE_EFFECT); add_function_constant( "get_address", f_get_address, "function(string:string)", 0); add_function_constant( "extension", f_extension, "function(string:string)", 0); add_function_constant( "create_process", f_create_process, "function(array(string),void|mapping(string:mixed):int)", 0); start_new_program(); ADD_STORAGE( buffer ); add_function( "append", f_buf_append, "function(string:int)", OPT_SIDE_EFFECT ); add_function( "create", f_buf_create, "function(mapping,mapping,int|void:void)", 0 ); set_init_callback(alloc_buf_struct); set_exit_callback(free_buf_struct); end_class("ParseHTTP", 0); init_nbio(); }
void translation_init(void) { add_function("lt", &eval_lt); add_function("eq", &eval_eq); add_function("int", &eval_int); add_function("add", &eval_add); add_function("strlen", &eval_strlen); add_function("if", &eval_if); add_function("isnull", &eval_isnull); }
int function_register(const function_t *func_info) { if(function_registered(func_info->name)) { return 1; } if(add_function(func_info) != 0) { return 1; } return 0; }
struct leaf *allocate_leaf () { struct leaf *lef; struct cept *ex; lef = (struct leaf *) allocate_object (LEAF); if (lef == NULL) { ex = new_cept (MEMORY_ERROR, ALLOCATION, FATAL_SEVERITY); add_function (ex, "allocate_leaf"); add_source (ex, "msrender.c"); return(NULL); } return (lef); }
std::shared_ptr<soft_function> environment::find_or_add (const std::string& name) { auto func(find_function(name)); if (func == nullptr) { std::shared_ptr<soft_function> soft_func(new soft_function(name)); add_function(soft_func); return soft_func; } else if (!func->is_native()) return std::static_pointer_cast<soft_function>(func); else return nullptr; }
void init_avs_count_program(void) { // start building the AVS.Search program start_new_program(); // request space for the per-object private data ADD_STORAGE(struct private_count_data); // add the program methods add_function("create", f_create, "function(object:void)", ID_PUBLIC); add_function("destroy", f_destroy, "function(void:void)", ID_PUBLIC); add_function("get_count", f_get_count, "function(void:int)", ID_PUBLIC); add_function("next", f_next, "function(void:void)", ID_PUBLIC); add_function("get_word", f_get_word, "function(void:string)", ID_PUBLIC); // finish and add the AVS.Search program count_program = end_program(); add_program_constant("Count", count_program, 0); }
struct surface *new_surface () { struct surface *srf_ptr; struct cept *ex; srf_ptr = (struct surface *) allocate_object (SURFACE); if (srf_ptr == NULL) { ex = new_cept (MEMORY_ERROR, ALLOCATION, FATAL_SEVERITY); add_object (ex, SURFACE, "srf_ptr"); add_function (ex, "new_surface"); return (NULL); } srf_ptr -> surface_thickness = DEFAULT_THICKNESS; return (srf_ptr); }
static int add_functions_from_module(libcrange* lr, set* functions, const char* module, const char* prefix) { void* handle; char filename[512]; const char** all_functions; snprintf(filename, sizeof filename, "%s/%s.so", /* if absolute path, don't use funcdir * bit of a hack. FIXME need better handling * for setting funcdir and other implied paths * in the conf */ module[0] == '/' ? "" : lr->funcdir, module); filename[sizeof filename - 1] = '\0'; if (access(filename, R_OK) != 0) { fprintf(stderr, "module %s (can't read %s.)\n", module, filename); return 1; } if ((handle = dlopen(filename, RTLD_NOW)) == NULL) { fprintf(stderr, "%s: can't dlopen: %s\n", filename, dlerror()); return 1; } dlerror(); /* Clear any existing errors */ all_functions = get_function_names(lr, handle, module); if (all_functions == NULL) return 1; while (*all_functions) { int err = add_function(lr, functions, handle, module, prefix, *all_functions++); if (err != 0) return err; } return 0; }
void render_surface (struct msscene *ms, struct surface *current_surface) { int is_vdw, type; double fine_pixel; char message[MAXLINE]; struct face *fac; struct variety *vty; struct cept *ex; fine_pixel = ms -> pixel_width / ms -> fineness; is_vdw = (current_surface -> type == PQMS_SURFACE && current_surface -> probe_radius <= 0.0); for (fac = current_surface -> head_face; fac != NULL; fac = fac -> next) { vty = fac -> vty; if (fac -> problem) { sprintf (message,"skip problem face of atoms %5d %5d %5d %5d", vty -> atmnum[0], vty -> atmnum[1], vty -> atmnum[2], vty -> atmnum[3]); inform(message); continue; } if (is_vdw && (fac -> shape == CONCAVE || fac -> shape == SADDLE)) continue; type = (int) vty -> type; switch (type) { case SPHERE: slice_sphere (ms, current_surface, fine_pixel, fac); break; case TORUS: slice_torus (ms, current_surface, fine_pixel, current_surface -> probe_radius, fac); break; case CYLINDER: slice_cylinder (ms, current_surface, fine_pixel, fac); break; default: ex = new_cept (ENUM_ERROR, INVALID_VALUE, FATAL_SEVERITY); add_function (ex, "render_surface"); add_source (ex, "msrender.c"); add_long (ex, "variety type", (long) type); return; } if (error()) return; } }
/** * Adds an option to the current options * * @param array $option * @return $this */ PHP_METHOD(Phalcon_Forms_Element_Select, addOption){ zval **option, *values, *tmp; phalcon_fetch_params_ex(1, 0, &option); PHALCON_ENSURE_IS_ARRAY(option); values = phalcon_fetch_nproperty_this(getThis(), SL("_optionsValues"), PH_NOISY TSRMLS_CC); ALLOC_ZVAL(tmp); if (Z_TYPE_P(values) != IS_ARRAY) { MAKE_COPY_ZVAL(option, tmp); } else { add_function(tmp, *option, values TSRMLS_CC); } Z_SET_REFCOUNT_P(tmp, 0); phalcon_update_property_this(getThis(), SL("_optionsValues"), tmp TSRMLS_CC); RETURN_THISW(); }
struct leaf *duplicate_leaf (struct leaf *lf) { int j, k; struct leaf *lf2; struct cept *ex; lf2 = allocate_leaf (); if (lf2 == NULL) { add_object (tail_cept, LEAF, "leaf"); add_function (tail_cept, "duplicate_leaf"); return(NULL); } lf2 -> cir = lf -> cir; lf2 -> shape = lf -> shape; lf2 -> type = lf -> type; lf2 -> fac = lf -> fac; lf2 -> side = lf -> side; lf2 -> comp = lf -> comp; lf2 -> input_hue = lf -> input_hue; lf2 -> cep = lf -> cep; lf2 -> clip_ep = lf -> clip_ep; for (j = 0; j < 2; j++) { lf2 -> where[j] = lf -> where[j]; lf2 -> when[j] = lf -> when[j]; for (k = 0; k < 3; k++) lf2 -> ends[j][k] = lf -> ends[j][k]; } for (k = 0; k < 3; k++) lf2 -> focus[k] = lf -> focus[k]; for (k = 0; k < MAXPA; k++) lf2 -> atmnum[k] = lf -> atmnum[k]; return (lf2); }
/* create tori */ void create_tori (struct surface *this_srf) { int k; long n_pair; double root1, root2, distance12, squared_distance12; double radius1, radius2, torus_radius; double axis[3]; double *sphere1_center, *sphere2_center; char message[MAXLINE]; struct sphere *sphere1, *sphere2; struct neighbor *first_neighbor, *last_neighbor, *neighbor; struct neighbor *first_neighbor2, *last_neighbor2, *neighbor2; struct pair *pair_ptr; struct cept *ex; if (this_srf -> n_pair <= 0) return; /* initialize to tmp tor array beginning */ pair_ptr = this_srf -> pair_array; n_pair = 0; /* loop through sphere list */ for (sphere1 = (struct sphere *) (this_srf -> head_atom); sphere1 != NULL; sphere1 = sphere1 -> next) { if ((first_neighbor = sphere1 -> first_neighbor) == NULL) continue; last_neighbor = sphere1 -> last_neighbor; /* transfer info to local variables */ sphere1_center = sphere1 -> center; radius1 = sphere1 -> radius; /* loop through neighbors of this sphere */ for (neighbor = first_neighbor; neighbor <= last_neighbor; neighbor++) { sphere2 = neighbor -> sphptr; if (sphere1 >= sphere2) continue; /* no duplication */ /* transfer info to local variables */ sphere2_center = sphere2 -> center; radius2 = sphere2 -> radius; /* geometric computations for torus */ for (k = 0; k < 3; k++) axis[k] = *(sphere2_center + k) - *(sphere1_center + k); distance12 = norm (axis); if (distance12 <= 0.0) { ex = new_cept (GEOMETRY_ERROR, DEGENERACY, FATAL_SEVERITY); add_function (ex, "create_tori"); add_source (ex, "mstorus.c"); add_message (ex, "coincident atoms"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } squared_distance12 = distance12 * distance12; if (squared_distance12 <= 0.0) { ex = new_cept (GEOMETRY_ERROR, DEGENERACY, FATAL_SEVERITY); add_function (ex, "create_tori"); add_source (ex, "mstorus.c"); add_message (ex, "coincident atoms"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } root1 = (radius1 + radius2 + 2 * this_srf -> probe_radius) * (radius1 + radius2 + 2 * this_srf -> probe_radius) - squared_distance12; if (root1 < 0.0) continue; /* sphere too far away */ root1 = sqrt (root1); root2 = squared_distance12 - (radius1 - radius2) * (radius1 - radius2); if (root2 < 0.0) continue; /* one sphere inside other */ root2 = sqrt (root2); torus_radius = 0.5 * root1 * root2 / distance12; if (torus_radius <= 0.0) continue; /* store pointer for torus in first spheres list */ neighbor -> torptr = pair_ptr; /* store pointer for torus in second spheres list */ first_neighbor2 = sphere2 -> first_neighbor; last_neighbor2 = sphere2 -> last_neighbor; for (neighbor2 = first_neighbor2; neighbor2 <= last_neighbor2; neighbor2++) if (neighbor2 -> sphptr == sphere1) { neighbor2 -> torptr = pair_ptr; break; } pair_ptr -> free = TRUE; pair_ptr -> buried = TRUE; pair_ptr -> sph[0] = sphere1; pair_ptr -> sph[1] = sphere2; pair_ptr++; n_pair = pair_ptr - this_srf -> pair_array; if (n_pair > this_srf -> n_pair) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "create_tori"); add_source (ex, "mstorus.c"); add_long (ex, "before", this_srf -> n_pair); add_long (ex, "after", n_pair); add_message (ex, "inconsistent number of neighbors"); return; } } } this_srf -> n_pair = n_pair; sprintf (message, "%8ld neighbor pairs", n_pair); inform (message); return; }
void setup_torus_fields (double probe_radius, struct pair *pair_ptr, double torus_center[3], double *return_radius, double torus_axis[3]) { int k; double root1, root2, asymmetry; double distance12, distance12_squared; double radius1, radius2, torus_radius; double *sphere1_center, *sphere2_center; char message[MAXLINE]; struct sphere *sphere1, *sphere2; struct cept *ex; sphere1 = pair_ptr -> sph[0]; sphere2 = pair_ptr -> sph[1]; if (sphere1 >= sphere2) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } /* transfer info to local variables */ sphere1_center = sphere1 -> center; radius1 = sphere1 -> radius; sphere2_center = sphere2 -> center; radius2 = sphere2 -> radius; /* geometric computations for torus */ for (k = 0; k < 3; k++) torus_axis[k] = *(sphere2_center + k) - *(sphere1_center + k); distance12 = norm (torus_axis); if (distance12 <= 0.0) { ex = new_cept (GEOMETRY_ERROR, DEGENERACY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "coincident atoms"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } distance12_squared = distance12 * distance12; if (distance12_squared <= 0.0) { ex = new_cept (GEOMETRY_ERROR, DEGENERACY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "coincident atoms"); add_atom (ex, sphere1); add_atom (ex, sphere2); return; } for (k = 0; k < 3; k++) torus_axis[k] /= distance12; root1 = (radius1 + radius2 + 2 * probe_radius) * (radius1 + radius2 + 2 * probe_radius) - distance12_squared; if (root1 < 0.0) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "inconsistent existence of torus"); add_atom (ex, sphere1); add_atom (ex, sphere2); add_double (ex, "root1", root1); return; } root1 = sqrt (root1); root2 = distance12_squared - (radius1 - radius2) * (radius1 - radius2); if (root2 < 0.0) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "inconsistent existence of torus"); add_atom (ex, sphere1); add_atom (ex, sphere2); add_double (ex, "root2", root2); return; } root2 = sqrt (root2); torus_radius = 0.5 * root1 * root2 / distance12; if (torus_radius <= 0) { ex = new_cept (LOGIC_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "setup_torus_fields"); add_source (ex, "mstorus.c"); add_message (ex, "inconsistent existence of torus"); add_atom (ex, sphere1); add_atom (ex, sphere2); add_double (ex, "torus_radius", torus_radius); return; } asymmetry = (radius1 + probe_radius) * (radius1 + probe_radius) - (radius2 + probe_radius) * (radius2 + probe_radius); for (k = 0; k < 3; k++) torus_center[k] = 0.5 * (*(sphere1_center + k) + *(sphere2_center + k)) + 0.5 * torus_axis[k] * asymmetry / distance12; *return_radius = torus_radius; return; }
/* regular saddle surfaces for this torus */ void regular_saddle (struct surface *this_srf, struct torus *torus_ptr) { int k, n_torus_arcs, arc_index; int index0, index1; struct arc *arc1, *arc2; struct circle *circle1, *circle2; double circle_points[MAX_SORT][3]; double point_vector1[3]; double point_vector2[3]; short arc_orn[MAX_SORT]; short indices[MAX_SORT]; struct arc **arc_list, **arc_hdl; double wrap_angle; struct cept *ex; /* set up circles */ circle1 = new_contact_circle (this_srf, torus_ptr, 0); if (error()) return; circle2 = new_contact_circle (this_srf, torus_ptr, 1); if (error()) return; /* count arcs belonging to torus */ n_torus_arcs = 0; for (arc1 = torus_ptr -> first_arc; arc1 != NULL; arc1 = arc1 -> next) n_torus_arcs++; if (n_torus_arcs <= 0) return; /* must be even */ if (0 != n_torus_arcs % 2) { ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "regular_saddle"); add_source (ex, "msface.c"); add_long (ex, "n_torus_arcs", n_torus_arcs); add_atom (ex, torus_ptr -> atm[0]); add_atom (ex, torus_ptr -> atm[1]); add_message (ex, "odd number of torus arcs"); return; } if (n_torus_arcs > MAX_SORT) { ex = new_cept (GEOMETRY_ERROR, MSOVERFLOW, FATAL_SEVERITY); add_function (ex, "regular_saddle"); add_source (ex, "msface.c"); add_long (ex, "n_torus_arcs", n_torus_arcs); add_long (ex, "MAX_SORT", MAX_SORT); add_atom (ex, torus_ptr -> atm[0]); add_atom (ex, torus_ptr -> atm[1]); return; } /* allocate memory */ arc_list = (struct arc **) allocate_pointers (ARC, n_torus_arcs); if (arc_list == NULL) { ex = new_cept (MEMORY_ERROR, ALLOCATION, FATAL_SEVERITY); add_function (ex, "regular_saddle"); add_source (ex, "msface.c"); add_atom (ex, torus_ptr -> atm[0]); add_atom (ex, torus_ptr -> atm[1]); return; } /* set up torus arc pointer list */ for (arc1 = torus_ptr -> first_arc, arc_index = 0; arc_index < n_torus_arcs; arc1 = arc1 -> next, arc_index++) { arc_hdl = arc_list + arc_index; *arc_hdl = arc1; /* pointer to arc */ } setup_torus_arcs (torus_ptr -> axis, n_torus_arcs, arc_list, circle_points, arc_orn); if (error()) return; sort_points (torus_ptr -> center, torus_ptr -> radius, torus_ptr -> axis, n_torus_arcs, circle_points, arc_orn, indices); if (error()) return; for (arc_index = 0; arc_index < n_torus_arcs; arc_index += 2) { index0 = indices[arc_index]; arc_hdl = arc_list + index0; arc1 = *arc_hdl; index1 = indices[arc_index+1]; arc_hdl = arc_list + index1; arc2 = *arc_hdl; /* compute saddle wrap angle */ for (k = 0; k < 3; k++) { point_vector1[k] = (circle_points[index0][k] - torus_ptr -> center[k]) / torus_ptr -> radius; point_vector2[k] = (circle_points[index1][k] - torus_ptr -> center[k]) / torus_ptr -> radius; } wrap_angle = positive_angle (point_vector1, point_vector2, torus_ptr -> axis); /* create saddle face */ newsad (this_srf, arc1, arc2, circle1, circle2, torus_ptr, wrap_angle); if (error()) return; } /* free temporary memory */ free_pointers (ARC, arc_list); }