std::vector<vec3f> displace_polyline(const std::vector<vec3f> &poly, const float min_length, const float fac_limit) const { std::vector<vec3f> res; std::vector<vec3f> to_add; std::vector<vec3f>::const_iterator input(poly.begin()); res.push_back(vlookup(*input++)); to_add.push_back(vlookup(*input++)); vec3f split; while(true) { while(!to_add.empty()) { while(max_diff(split, res.back(), to_add.back(), min_length, fac_limit)) { to_add.push_back(split); } res.push_back(to_add.back()); to_add.pop_back(); } if(input == poly.end()) return res; to_add.push_back(vlookup(*input++)); } }
void project_vertices(std::vector<vertex> &vrts) const { for(vertex &v: vrts) { v.position = vlookup(v.position); } }
void displace_shapes(osm::shape_t &s, const float min_length, const float fac_limit, osm::network &net) const { osm::shape_t res; osm::shape_t to_add; osm::shape_t::iterator input(s.begin()); (*input)->xy = vlookup((*input)->xy); res.push_back(*input); ++input; (*input)->xy = vlookup((*input)->xy); to_add.push_back(*input); ++input; vec3f split; while(true) { while(!to_add.empty()) { while(max_diff(split, res.back()->xy, to_add.back()->xy, min_length, fac_limit)) { to_add.push_back(net.add_node(split, res.back()->is_overpass && to_add.back()->is_overpass)); } res.push_back(to_add.back()); to_add.pop_back(); } if(input == s.end()) { s.swap(res); return; } (*input)->xy = vlookup((*input)->xy); to_add.push_back(*input); ++input; } }
static void vtoken(char *s) { value_t *p; char *cp; if ((cp = strchr(s, '='))) { *cp = '\0'; if ((p = vlookup(s))) { cp++; if (p->v_type&NUMBER) vassign(p, (char *)(intptr_t)atoi(cp)); else { if (strcmp(s, "record") == 0) cp = expand(cp); vassign(p, cp); } return; } } else if ((cp = strchr(s, '?'))) { *cp = '\0'; if ((p = vlookup(s)) && vaccess(p->v_access, READ)) { vprint(p); return; } } else { if (*s != '!') p = vlookup(s); else p = vlookup(s+1); if (p != NOVAL) { vassign(p, s); return; } } printf("%s: unknown variable\r\n", s); }
/* * assign variable s with value v (for NUMBER or STRING or CHAR types) */ int vstring(char *s, char *v) { value_t *p; p = vlookup(s); if (p == 0) return (1); if (p->v_type&NUMBER) vassign(p, (char *)(intptr_t)atoi(v)); else { if (strcmp(s, "record") == 0) v = expand(v); vassign(p, v); } return (0); }
void setmgvar( /* set a variable */ char *fname, FILE *fp, char *string ) { char name[128]; FILE *fp2; register int i; register char *s; register VARIABLE *vp; if (!strncmp(string, "include=", 8)) { /* include file */ if ((s = findfile(string+8, libpath)) == NULL) { fprintf(stderr, "%s\n", string); fprintf(stderr, "%s: %s: File not found: %s\n", progname, fname, string+8); quit(1); } strcpy(name, s); mgload(name); return; } s = string; i = 0; while (i < sizeof(name)-1 && isid(*s)) name[i++] = *s++; name[i] = '\0'; vp = vlookup(name); if (vp != NULL) { undefine(vp); switch (vp->type) { case REAL: case FUNCTION: if ((*s == '(') != (vp->type == FUNCTION)) { fprintf(stderr, "%s\n", string); fprintf(stderr, "%s: %s: Bad %s declaration: %s\n", progname, fname, vp->type == FUNCTION ? "function" : "variable", name); quit(1); } scompile(string, fname, 0); vp->v.dfn = savestr(string); break; case STRING: if (*s++ != '=') { fprintf(stderr, "%s\n", string); fprintf(stderr, "%s: %s: Missing '='\n", progname, fname); quit(1); } vp->v.s = savestr(s); break; case DATA: if (*s++ != '=') { fprintf(stderr, "%s\n", string); fprintf(stderr, "%s: %s: Missing '='\n", progname, fname); quit(1); } if (!*s) { loaddata(fname, fp, &vp->v.d); } else if (*s == '!') { if ((fp2 = popen(s+1, "r")) == NULL) { fprintf(stderr, "%s\n", string); fprintf(stderr, "%s: %s: Cannot execute: %s\n", progname, fname, s+1); quit(1); } loaddata(s, fp2, &vp->v.d); pclose(fp2); } else { if ((fp2 = fopen(s, "r")) == NULL) { fprintf(stderr, "%s\n", string); fprintf(stderr, "%s: %s: Data file not found: %s\n", progname, fname, s); quit(1); } loaddata(s, fp2, &vp->v.d); fclose(fp2); } break; } vp->flags |= DEFINED; } else setivar(name, fname, string); /* intermediate */ }