How to use NEXT_NUMBER method in argos

Best JavaScript code snippet using argos

mod_svg_path.js

Source:mod_svg_path.js Github

copy

Full Screen

1//2// mod_svg_path.js3// fab modules SVG path input4//5// Neil Gershenfeld 6// (c) Massachusetts Institute of Technology 20147// 8// This work may be reproduced, modified, distributed, performed, and 9// displayed for any purpose, but must acknowledge the fab modules 10// project. Copyright is retained and must be preserved. The work is 11// provided as is; no warranty is provided, and users accept all 12// liability.13//14define(['require', 'mods/mod_ui', 'mods/mod_globals', 'outputs/mod_outputs', 'mods/mod_file'], function(require) {15 var ui = require('mods/mod_ui');16 var globals = require('mods/mod_globals');17 var outputs = require('outputs/mod_outputs');18 var fileUtils = require('mods/mod_file');19 var findEl = globals.findEl;20 var MAXWIDTH = 1000021 //22 // mod_load_handler23 // file load handler24 //25 function mod_load_handler() {26 var file = findEl("mod_file_input")27 // file.setAttribute("onchange", "mod_svg_path_read_handler()")28 file.addEventListener("change", function() {29 mod_svg_path_read_handler();30 });31 }32 //33 // mod_svg_path_read_handler34 // SVG path read handler35 //36 function mod_svg_path_read_handler(event) {37 //38 // get input file39 //40 var file_input = findEl("mod_file_input")41 globals.input_file = file_input.files[0]42 globals.input_name = file_input.files[0].name43 globals.input_basename = fileUtils.basename(globals.input_name)44 //45 // read as text46 //47 var file_reader = new FileReader()48 file_reader.onload = mod_svg_path_text_load_handler49 file_reader.readAsText(globals.input_file)50 }51 //52 // mod_svg_path_text_load_handler53 // SVG path text load handler54 //55 function mod_svg_path_text_load_handler(event) {56 //57 // set up UI58 //59 controls = findEl("mod_input_controls")60 controls.innerHTML = "<b>input</b><br>"61 var file_input = findEl("mod_file_input")62 controls.innerHTML += "file: " + globals.input_name + "<br>"63 controls.innerHTML += "size:<br>"64 controls.innerHTML += "<div id='mod_size'></div>"65 //66 // parse path67 //68 str = event.target.result69 result = mod_svg_path_parse(str)70 if (result == false)71 return72 //73 // display path74 //75 //76 // call outputs77 //78 ui.ui_prompt("output format?")79 outputs.init()80 }81 //82 // mod_svg_path_parse83 // parse SVG path84 //85 function mod_svg_path_parse(str) {86 //87 // mm88 // return dimension in mm and set units if found89 //90 function mm(str, ptr) {91 var start = 1 + str.indexOf("\"", ptr)92 var end = str.indexOf("\"", start + 1)93 var units = str.slice(end - 2, end)94 if (units == "px") {95 return (25.4 * parseFloat(str.slice(start, end - 2) / 90.0)) // Inkscape px default 90/inch96 } else if (units == "pt") {97 return (25.4 * parseFloat(str.slice(start, end - 2) / 72.0))98 } else if (units == "in") {99 return (25.4 * parseFloat(str.slice(start, end - 2)))100 } else if (units == "mm") {101 return (parseFloat(str.slice(start, end - 2)))102 } else if (units == "cm") {103 return (10.0 * parseFloat(str.slice(start, end - 2)))104 } else {105 return (parseFloat(str.slice(start, end)))106 }107 }108 //109 // strchr110 // return first occurence of char in string, otherwise -1111 //112 function strchr(str, chr) {113 for (var i = 0; i < str.length; ++i) {114 if (str[i] == chr)115 return i116 }117 return -1118 }119 //120 // next_number121 // return next number after pointer122 //123 function next_number(str, ptr) {124 var haystack = "0123456789.-+"125 //126 // find start127 //128 var start = ptr129 while (1) {130 if (strchr(haystack, str[start]) != -1)131 break132 ++start133 }134 //135 // find end136 //137 var end = start138 while (1) {139 if (strchr(haystack, str[end]) == -1)140 break;141 ++end142 }143 return {144 value: parseFloat(str.slice(start, end)),145 index: end146 }147 }148 /*149 //150 // move pointer to end and return number151 //152 *number = strtod(*ptr,&end);153 *ptr = end;154 }155 */156 //157 // find SVG element158 //159 var ptr = str.indexOf("<svg")160 if (ptr == -1) {161 ui.ui_prompt("error: SVG element not found")162 return false163 }164 var stop = str.indexOf(">", ptr)165 //166 // get width and height167 //168 globals.dpi = 90 // Inkscape default for px169 var start = str.indexOf("width=", ptr)170 if ((start == -1) || (start > stop)) {171 ui.ui_prompt("error: no width")172 return false173 }174 var width = mm(str, start)175 var start = str.indexOf("height=", ptr)176 if ((start == -1) || (start > stop)) {177 ui.ui_prompt("error: no height")178 return false179 }180 var height = mm(str, start)181 var size = findEl('mod_size')182 size.innerHTML = "&nbsp;&nbsp;&nbsp;" + width.toFixed(3) + ' x ' + height.toFixed(3) + ' mm<br>'183 size.innerHTML += "&nbsp;&nbsp;&nbsp;" + (width / 25.4).toFixed(3) + ' x ' + (height / 25.4).toFixed(3) + ' in<br>'184 //185 // check for viewBox186 //187 var start = str.indexOf("viewBox=", ptr)188 if ((start == -1) || (start > stop)) {189 vxmin = 0190 vymin = 0191 vwidth = width192 vheight = height193 } else {194 var result = next_number(str, start)195 var vxmin = result.value196 var result = next_number(str, result.index)197 var vymin = result.value198 var result = next_number(str, result.index)199 var vwidth = result.value200 var result = next_number(str, result.index)201 var vheight = result.value202 }203 // console.log(vxmin)204// console.log(vymin)205// console.log(vwidth)206// console.log(vheight)207 }208 return {209 mod_load_handler: mod_load_handler210 }211});212/*213 aspect = height/width;214 vaspect = vheight/vwidth;215 vxmid = vxmin + vwidth/2.0;216 vymid = vymin + vheight/2.0;217 // assume xMidYMid meet scaling218 if (vaspect > aspect) {219 ynscale = resolution*aspect/vheight;220 xnscale = ynscale;221 }222 else {223 xnscale = resolution/vwidth;224 ynscale = xnscale;225 }226 xnmid = resolution/2.0;227 ynmid = aspect*xnmid;228 }229 else {230 vxmid = width/2.0;231 vymid = height/2.0;232 xnscale = resolution/width;233 ynscale = xnscale;234 xnmid = xnscale*width/2.0;235 ynmid = ynscale*height/2.0;236 }237 */238/*239 //240 // get size241 //242 str = event.target.result243 var i = str.indexOf("width")244 if (i == -1) {245 ui.ui_prompt("error: SVG width not found")246 return247 }248 var i1 = str.indexOf("\"",i+1)249 var i2 = str.indexOf("\"",i1+1)250 var width = str.substring(i1+1,i2)251 i = str.indexOf("height")252 i1 = str.indexOf("\"",i+1)253 i2 = str.indexOf("\"",i1+1)254 var height = str.substring(i1+1,i2)255 ih = str.indexOf("height")256 if (width.indexOf("px") != -1) {257 width = width.slice(0,-2)258 height = height.slice(0,-2)259 var units = 90260 }261 else if (width.indexOf("mm") != -1) {262 width = width.slice(0,-2)263 height = height.slice(0,-2)264 var units = 25.4265 }266 else if (width.indexOf("cm") != -1) {267 width = width.slice(0,-2)268 height = height.slice(0,-2)269 var units = 2.54270 }271 else if (width.indexOf("in") != -1) {272 width = width.slice(0,-2)273 height = height.slice(0,-2)274 var units = 1275 }276 else {277 var units = 90278 }279 globals.dpi = 300280 globals.svg = {}281 globals.svg.units = units282 globals.svg.width = parseFloat(width)283 globals.svg.height = parseFloat(height)284 globals.width = parseInt(globals.dpi*width/units)285 globals.height = parseInt(globals.dpi*height/units)286 //287 // read as URL for display288 //289 var file_reader = new FileReader()290 file_reader.onload = mod_svg_URL_load_handler291 file_reader.readAsDataURL(globals.input_file)292 }293//294// mod_svg_URL_load_handler295// SVG URL load handler296//297function mod_svg_URL_load_handler(event) {298 //299 // read and display image300 //301 var img = new Image()302 img.setAttribute("src",event.target.result)303 globals.svg.svg = event.target.result304 img.onload = function() {305 img.width = globals.width306 img.height = globals.height307 var process_canvas = findEl("mod_process_canvas")308 process_canvas.width = img.width309 process_canvas.height = img.height310 var output_canvas = findEl("mod_output_canvas")311 output_canvas.width = img.width312 output_canvas.height = img.height313 var canvas = findEl("mod_input_canvas")314 canvas.width = img.width315 canvas.height = img.height316 canvas.style.display = "inline"317 var ctx = canvas.getContext("2d")318 ctx.drawImage(img,0,0,img.width,img.height)319 var input_img = ctx.getImageData(0,0,canvas.width,canvas.height)320 mod_image_flatten(input_img)321 ctx.putImageData(input_img,0,0)322 controls = findEl("mod_input_controls")323 controls.innerHTML = "<b>input</b><br>"324 var file_input = findEl("mod_file_input")325 controls.innerHTML += "file: "+globals.input_name+"<br>"326 controls.innerHTML += "units/in: "327 controls.innerHTML += "<input type='text' id='mod_units' size='3' value="+globals.svg.units.toFixed(3)+" onkeyup='{\328 globals.svg.units = \329 parseFloat(findEl(\"mod_units\").value);\330 globals.width = \331 parseInt(globals.dpi*globals.svg.width/globals.svg.units);\332 globals.height = \333 parseInt(globals.dpi*globals.svg.height/globals.svg.units);\334 findEl(\"mod_px\").innerHTML = \335 globals.width+\" x \"+globals.height+\" px\";\336 findEl(\"mod_mm\").innerHTML = \337 (25.4*globals.width/globals.dpi).toFixed(3)+\" x \"+\338 (25.4*globals.height/globals.dpi).toFixed(3)+\" mm\";\339 findEl(\"mod_in\").innerHTML = \340 (globals.width/globals.dpi).toFixed(3)+\" x \"+\341 (globals.height/globals.dpi).toFixed(3)+\" in\";\342 mod_svg_reload();\343 }'><br>"344 controls.innerHTML += "width: "+globals.svg.width.toFixed(3)+"<br>"345 controls.innerHTML += "height: "+globals.svg.height.toFixed(3)+"<br>"346 controls.innerHTML += "dpi: "347 controls.innerHTML += "<input type='text' id='mod_dpi' size='3' value="+globals.dpi.toFixed(3)+" onkeyup='{\348 globals.dpi = \349 parseFloat(findEl(\"mod_dpi\").value);\350 globals.width = \351 parseInt(globals.dpi*globals.svg.width/globals.svg.units);\352 globals.height = \353 parseInt(globals.dpi*globals.svg.height/globals.svg.units);\354 findEl(\"mod_px\").innerHTML = \355 globals.width+\" x \"+globals.height+\" px\";\356 mod_svg_reload();\357 }'><br>"358 controls.innerHTML += "size:<br>"359 controls.innerHTML += "<span id='mod_px'>"+360 globals.width+" x "+globals.height+" px</span><br>"361 controls.innerHTML += "<span id='mod_mm'>"+362 (25.4*globals.width/globals.dpi).toFixed(3)+" x "+363 (25.4*globals.height/globals.dpi).toFixed(3)+" mm</span><br>"364 controls.innerHTML += "<span id='mod_in'>"+365 (globals.width/globals.dpi).toFixed(3)+" x "+366 (globals.height/globals.dpi).toFixed(3)+" in</span><br>"367 controls.innerHTML += "<input type='button' value='invert image' onclick='{\368 mod_ui_clear();\369 var canvas = findEl(\"mod_input_canvas\");\370 canvas.style.display = \"inline\";\371 var ctx = canvas.getContext(\"2d\");\372 var img = ctx.getImageData(0,0,canvas.width,canvas.height);\373 mod_image_invert(img);\374 ctx.putImageData(img,0,0);}'>" 375 }376 //377 // reader.readAsArrayBuffer(file) 378 //379 // call outputs380 //381 ui.ui_prompt("output format?")382 mod_outputs()383 }384//385// mod_svg_reload386// reload SVG image387//388function mod_svg_reload() {389 mod_ui_clear()390 var img = new Image()391 img.setAttribute("src",globals.svg.svg)392 if (globals.width > MAXWIDTH) {393 ui.ui_prompt("error: image too large (greater than mod_svg MAXWIDTH)")394 return395 }396 else397 ui.ui_prompt("")398 img.onload = function() {399 img.width = globals.width400 img.height = globals.height401 var process_canvas = findEl("mod_process_canvas")402 process_canvas.width = img.width403 process_canvas.height = img.height404 var output_canvas = findEl("mod_output_canvas")405 output_canvas.width = img.width406 output_canvas.height = img.height407 var canvas = findEl("mod_input_canvas")408 canvas.width = img.width409 canvas.height = img.height410 canvas.style.display = "inline"411 var ctx = canvas.getContext("2d")412 ctx.drawImage(img,0,0,img.width,img.height)413 var input_img = ctx.getImageData(0,0,canvas.width,canvas.height)414 mod_image_flatten(input_img)415 ctx.putImageData(input_img,0,0)416 }417 }418*/419/*420double angle(double ux, double uy, double vx, double vy) {421 double sign = (((ux*vy-uy*vx) > 0) ? 1 : -1);422 return (sign*acos((ux*vx+uy*vy)/(sqrt(ux*ux+uy*uy)*sqrt(vx*vx+vy*vy))));423 }424 425char next_element(char **ptr, char current_element) {426 //427 // return next path element after pointer428 //429 char number_haystack[] = "0123456789.-+";430 char element_haystack[] = "mMlLhHvVcCsSaAzZ\"";431 while (1) {432 if (strchr(element_haystack,**ptr) != NULL)433 return(**ptr);434 else if (strchr(number_haystack,**ptr) != NULL)435 return(current_element);436 else437 *ptr += 1;438 }439 }440void clear_transform(int *transform) {441 //442 // pop current transform from stack443 //444 *transform -= 1;445 }446int hex_int(char chr) {447 //448 // return hex for char449 //450 if (chr == '0') return 0;451 else if (chr == '1') return 1;452 else if (chr == '2') return 2;453 else if (chr == '3') return 3;454 else if (chr == '4') return 4;455 else if (chr == '5') return 5;456 else if (chr == '6') return 6;457 else if (chr == '7') return 7;458 else if (chr == '8') return 8;459 else if (chr == '9') return 9;460 else if ((chr == 'a') || (chr == 'A')) return 10;461 else if ((chr == 'b') || (chr == 'B')) return 11;462 else if ((chr == 'c') || (chr == 'C')) return 12;463 else if ((chr == 'd') || (chr == 'D')) return 13;464 else if ((chr == 'e') || (chr == 'e')) return 14;465 else if ((chr == 'f') || (chr == 'F')) return 15;466 printf("svg_path: oops -- non-hex char\n");467 exit(-1);468 }469void set_intensity(char *start, int *zn, struct fab_vars *v, int zsign) {470 char *end,*ptr;471 int r,g,b;472 float i;473 //474 // set zn from element intensity475 //476 end = strstr(start+1,">");477 ptr = strstr(start,"stroke:");478 if ((ptr != NULL) && (ptr < end)) {479 //480 // stroke found, check for hex encoding481 //482 ptr = strstr(ptr,"#");483 if ((ptr != NULL) && (ptr < end)) {484 //485 // hex encoding found, set intensity486 //487 r = 16*hex_int(ptr[1]) + hex_int(ptr[2]);488 g = 16*hex_int(ptr[3]) + hex_int(ptr[4]);489 b = 16*hex_int(ptr[5]) + hex_int(ptr[6]);490 if (zsign == 1)491 i = (r+g+b)/(255.0+255.0+255.0);492 else493 i = 1.0 - (r+g+b)/(255.0+255.0+255.0);494 *zn = i * (v->nz - 1);495 }496 else {497 //498 // hex encoding not found, set to bottom499 //500 *zn = 0;501 }502 }503 else {504 //505 // stroke not found, set to bottom506 //507 *zn = 0;508 }509 }510void set_transform(char *start, int *transform, double transforms[SVG_MAX_TRANSFORM][6]) {511 double a,b,c,d,e,f;512 double pi = 4*atan(1.0);513 char *end,*next,*ptr;514 //515 // push transform for current element onto stack516 //517 end = strstr(start+1,">");518 next = strstr(start+1,"<");519 if ((next != NULL) && (next < end))520 end = next;521 //522 // check for transform523 //524 ptr = strstr(start,"transform");525 if ((ptr != NULL) && (ptr < end)) {526 //527 // found, check for matrix528 //529 ptr = strstr(start,"matrix(");530 if ((ptr != NULL) && (ptr < end)) {531 //printf("trans: matrix\n");532 next_number(&ptr,&a);533 next_number(&ptr,&b);534 next_number(&ptr,&c);535 next_number(&ptr,&d);536 next_number(&ptr,&e);537 next_number(&ptr,&f);538 transforms[*transform][0] = a;539 transforms[*transform][1] = b;540 transforms[*transform][2] = c;541 transforms[*transform][3] = d;542 transforms[*transform][4] = e;543 transforms[*transform][5] = f;544 *transform += 1;545 return;546 }547 //548 // check for translate549 //550 ptr = strstr(start,"translate(");551 if ((ptr != NULL) && (ptr < end)) {552 //printf("trans: translate\n");553 next_number(&ptr,&e);554 next_number(&ptr,&f);555 transforms[*transform][0] = 1;556 transforms[*transform][1] = 0;557 transforms[*transform][2] = 0;558 transforms[*transform][3] = 1;559 transforms[*transform][4] = e;560 transforms[*transform][5] = f;561 *transform += 1;562 return;563 }564 //565 // check for scale566 //567 ptr = strstr(start,"scale(");568 if ((ptr != NULL) && (ptr < end)) {569 //printf("trans: scale\n");570 next_number(&ptr,&a);571 transforms[*transform][0] = a;572 transforms[*transform][1] = 0;573 transforms[*transform][2] = 0;574 transforms[*transform][3] = a;575 transforms[*transform][4] = 0;576 transforms[*transform][5] = 0;577 *transform += 1;578 return;579 }580 //581 // check for rotate582 //583 ptr = strstr(start,"rotate(");584 if ((ptr != NULL) && (ptr < end)) {585 //printf("trans: rotate\n");586 next_number(&ptr,&a);587 transforms[*transform][0] = cos(a*pi/180.0);588 transforms[*transform][1] = sin(a*pi/180.0);589 transforms[*transform][2] = -sin(a*pi/180.0);590 transforms[*transform][3] = cos(a*pi/180.0);591 transforms[*transform][4] = 0;592 transforms[*transform][5] = 0;593 *transform += 1;594 return;595 }596 //597 // check for skewX598 //599 ptr = strstr(start,"skewX(");600 if ((ptr != NULL) && (ptr < end)) {601 //printf("trans: skewX\n");602 next_number(&ptr,&a);603 transforms[*transform][0] = 1;604 transforms[*transform][1] = 0;605 transforms[*transform][2] = tan(a*pi/180.0);606 transforms[*transform][3] = 1;607 transforms[*transform][4] = 0;608 transforms[*transform][5] = 0;609 *transform += 1;610 return;611 }612 //613 // check for skewY614 //615 ptr = strstr(start,"skewY(");616 if ((ptr != NULL) && (ptr < end)) {617 //printf("trans: skewY\n");618 next_number(&ptr,&a);619 transforms[*transform][0] = 1;620 transforms[*transform][1] = tan(a*pi/180.0);621 transforms[*transform][2] = 0;622 transforms[*transform][3] = 1;623 transforms[*transform][4] = 0;624 transforms[*transform][5] = 0;625 *transform += 1;626 return;627 }628 //629 // didn't find transform630 //631 printf("svg_path: oops -- didn't find transform\n");632 transforms[*transform][0] = 1;633 transforms[*transform][1] = 0;634 transforms[*transform][2] = 0;635 transforms[*transform][3] = 1;636 transforms[*transform][4] = 0;637 transforms[*transform][5] = 0;638 *transform += 1;639 return;640 }641 else {642 //643 // transform not found, set unit transform644 //645 transforms[*transform][0] = 1;646 transforms[*transform][1] = 0;647 transforms[*transform][2] = 0;648 transforms[*transform][3] = 1;649 transforms[*transform][4] = 0;650 transforms[*transform][5] = 0;651 *transform += 1;652 return;653 }654 }655void path_point(int *xn, int *yn, double x, double y, int transform, double transforms[SVG_MAX_TRANSFORM][6],656 double xnscale, double ynscale, double xnmid, double vxmid, double ynmid, double vymid) {657 double xt,yt,xtemp,ytemp;658 int t;659 //660 // return path point661 //662 xt = x;663 yt = y;664 for (t = (transform-1); t >= 0; --t) {665 xtemp = transforms[t][0]*xt + transforms[t][2]*yt + transforms[t][4];666 ytemp = transforms[t][1]*xt + transforms[t][3]*yt + transforms[t][5];667 xt = xtemp;668 yt = ytemp;669 }670 *xn = xnmid + xnscale*(xt - vxmid);671 *yn = ynmid + ynscale*(yt - vymid);672 }673void fab_read_svg(struct fab_vars *v, char *input_file_name, float scale, int points, int resolution, float zmin, float zmax) {674 //675 // read SVG into fab_vars676 //677 FILE *input_file;678 char buf[SVG_MAX_FILE];679 char units[3];680 char current_element,last_element;681 int point,ret;682 char *ptr,*start,*stop,*endptr;683 int transform;684 double transforms[SVG_MAX_TRANSFORM][6];685 double unit_scale;686 double xnscale,ynscale,xnmid,ynmid;687 double vxmin,vymin,vxmid,vymid,vwidth,vheight,vaspect;688 double width,height,aspect;689 double x,y,z,x0,y0,x1,y1,x2,y2;690 double rx,ry,theta,theta_0,theta_1,theta_diff,rotation,large_arc,sweep;691 double phi,x1p,y1p,sign,cxp,cyp;692 double ax,bx,cx,ay,by,cy,xt,yt,t,r;693 double pi;694 int xn,yn,zn;695 int zsign;696 int count;697 pi = 4*atan(1.0);698 699 //700 // start path701 //702 v->nx = 2*xnmid;703 v->ny = 2*ynmid;704 v->dx = scale*width*unit_scale;705 v->dy = scale*height*unit_scale;706 v->xmin = 0;707 v->ymin = 0;708 zsign = 1;709 if (v->path->dof > 2) {710 if (zmin > zmax) {711 z = zmin;712 zmin = zmax;713 zmax = z;714 zsign = -1;715 }716 v->nz = 1+xnscale*(zmax-zmin);717 v->dz = zmax-zmin;718 v->zmin = zmin;719 }720 //721 // find graphic elements722 //723 ptr = buf;724 transform = 0;725 do {726 ptr += 1;727 if (strncmp(ptr,"<g",2) == 0) {728 //729 // opening g, check for transform and intensity730 //731 set_transform(ptr,&transform,transforms);732 set_intensity(ptr,&zn,v,zsign);733 }734 else if (strncmp(ptr,"/g>",2) == 0) {735 //736 // closing g, clear transform737 //738 clear_transform(&transform);739 }740 else if (strncmp(ptr,"<defs",5) == 0) {741 //742 // defs743 //744 while (1) {745 //746 // find closure747 //748 ptr +=1;749 if (strncmp(ptr,"/>",2) == 0)750 //751 // self-closing752 //753 break;754 else if (strncmp(ptr,">",1) == 0) {755 //756 // not self-closing757 //758 while (1) {759 ptr += 1;760 if (strncmp(ptr,"</defs>",7) == 0)761 break;762 }763 break;764 }765 }766 printf(" svg_path: defs not yet implemented\n");767 }768 else if (strncmp(ptr,"<image",6) == 0) {769 //770 // defs771 //772 while (1) {773 //774 // find closure775 //776 ptr +=1;777 if (strncmp(ptr,"/>",2) == 0)778 //779 // self-closing780 //781 break;782 else if (strncmp(ptr,">",1) == 0) {783 //784 // not self-closing785 //786 while (1) {787 ptr += 1;788 if (strncmp(ptr,"</image>",8) == 0)789 break;790 }791 break;792 }793 }794 printf(" svg_path: image not yet implemented\n");795 }796 else if (strncmp(ptr,"<path",5) == 0) {797 //798 // path799 //800 set_transform(ptr,&transform,transforms);801 set_intensity(ptr,&zn,v,zsign);802 ptr = 4+strstr(ptr," d=");803 current_element = 0;804 last_element = 0;805 x0 = 0;806 y0 = 0;807 do {808 last_element = current_element;809 current_element = next_element(&ptr, current_element);810 if (current_element == 'm') {811 //812 // relative moveto813 //814 next_number(&ptr,&x);815 next_number(&ptr,&y);816 x0 = x0 + x;817 y0 = y0 + y;818 //printf(" path m: %f %f\n",x0,y0);819 current_element = 'l';820 fab_path_segment(v);821 fab_path_point(v);822 path_point(&xn,&yn,x0,y0,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);823 fab_path_axis(v,xn);824 fab_path_axis(v,yn);825 if (v->path->dof > 2)826 fab_path_axis(v,zn);827 }828 else if (current_element == 'M') {829 //830 // absolute moveto831 //832 next_number(&ptr,&x0);833 next_number(&ptr,&y0);834 //printf(" path M: %f %f\n",x0,y0);835 current_element = 'L';836 fab_path_segment(v);837 fab_path_point(v);838 path_point(&xn,&yn,x0,y0,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);839 fab_path_axis(v,xn);840 fab_path_axis(v,yn);841 if (v->path->dof > 2)842 fab_path_axis(v,zn);843 }844 else if (current_element == 'l') {845 //846 // relative lineto847 //848 next_number(&ptr,&x);849 next_number(&ptr,&y);850 //printf(" path l: %f %f\n",x,y);851 current_element = 'l';852 fab_path_point(v);853 path_point(&xn,&yn,x0+x,y0+y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);854 fab_path_axis(v,xn);855 fab_path_axis(v,yn);856 if (v->path->dof > 2)857 fab_path_axis(v,zn);858 x0 = x0+x;859 y0 = y0+y;860 }861 else if (current_element == 'L') {862 //863 // absolute lineto864 //865 next_number(&ptr,&x);866 next_number(&ptr,&y);867 //printf(" path L: %f %f\n",x,y);868 current_element = 'L';869 fab_path_point(v);870 path_point(&xn,&yn,x,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);871 fab_path_axis(v,xn);872 fab_path_axis(v,yn);873 if (v->path->dof > 2)874 fab_path_axis(v,zn);875 x0 = x;876 y0 = y;877 }878 else if (current_element == 'h') {879 //880 // relative horizontal881 //882 next_number(&ptr,&x);883 //printf(" path h: %f\n",x);884 current_element = 'j';885 fab_path_point(v);886 path_point(&xn,&yn,x0+x,y0,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);887 fab_path_axis(v,xn);888 fab_path_axis(v,yn);889 if (v->path->dof > 2)890 fab_path_axis(v,zn);891 x0 = x0+x;892 }893 else if (current_element == 'H') {894 //895 // absolute horizontal896 //897 next_number(&ptr,&x);898 //printf(" path H: %f\n",x);899 current_element = 'H';900 fab_path_point(v);901 path_point(&xn,&yn,x,y0,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);902 fab_path_axis(v,xn);903 fab_path_axis(v,yn);904 if (v->path->dof > 2)905 fab_path_axis(v,zn);906 x0 = x;907 }908 else if (current_element == 'v') {909 //910 // relative vertical911 //912 next_number(&ptr,&y);913 //printf(" path v: %f\n",y);914 current_element = 'v';915 fab_path_point(v);916 path_point(&xn,&yn,x0,y0+y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);917 fab_path_axis(v,xn);918 fab_path_axis(v,yn);919 if (v->path->dof > 2)920 fab_path_axis(v,zn);921 y0 = y0+y;922 }923 else if (current_element == 'V') {924 //925 // absolute vertical926 //927 next_number(&ptr,&y);928 //printf(" path V: %f\n",y);929 current_element = 'V';930 fab_path_point(v);931 path_point(&xn,&yn,x0,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);932 fab_path_axis(v,xn);933 fab_path_axis(v,yn);934 if (v->path->dof > 2)935 fab_path_axis(v,zn);936 y0 = y;937 }938 else if (current_element == 'c') {939 //940 // relative curveto941 //942 next_number(&ptr,&x1);943 x1 += x0;944 next_number(&ptr,&y1);945 y1 += y0;946 next_number(&ptr,&x2);947 x2 += x0;948 next_number(&ptr,&y2);949 y2 += y0;950 next_number(&ptr,&x);951 x += x0;952 next_number(&ptr,&y);953 y += y0;954 //printf(" path c: %f %f %f %f %f %f\n",x1,y1,x2,y2,x,y);955 current_element = 'c';956 cx = 3 * (x1 - x0);957 bx = 3 * (x2 - x1) - cx;958 ax = x - x0 - cx - bx;959 cy = 3 * (y1 - y0);960 by = 3 * (y2 - y1) - cy;961 ay = y - y0 - cy - by;962 for (point = 0; point < points; ++point) {963 t = point / (points - 1.0);964 xt = ax*t*t*t + bx*t*t + cx*t + x0;965 yt = ay*t*t*t + by*t*t + cy*t + y0;966 fab_path_point(v);967 path_point(&xn,&yn,xt,yt,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);968 fab_path_axis(v,xn);969 fab_path_axis(v,yn);970 if (v->path->dof > 2)971 fab_path_axis(v,zn);972 }973 x0 = x;974 y0 = y;975 }976 else if (current_element == 'C') {977 //978 // absolute curveto979 //980 next_number(&ptr,&x1);981 next_number(&ptr,&y1);982 next_number(&ptr,&x2);983 next_number(&ptr,&y2);984 next_number(&ptr,&x);985 next_number(&ptr,&y);986 //printf(" path C: %f %f %f %f %f %f\n",x1,y1,x2,y2,x,y);987 current_element = 'C';988 cx = 3 * (x1 - x0);989 bx = 3 * (x2 - x1) - cx;990 ax = x - x0 - cx - bx;991 cy = 3 * (y1 - y0);992 by = 3 * (y2 - y1) - cy;993 ay = y - y0 - cy - by;994 for (point = 0; point < points; ++point) {995 t = point / (points - 1.0);996 xt = ax*t*t*t + bx*t*t + cx*t + x0;997 yt = ay*t*t*t + by*t*t + cy*t + y0;998 fab_path_point(v);999 path_point(&xn,&yn,xt,yt,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1000 fab_path_axis(v,xn);1001 fab_path_axis(v,yn);1002 if (v->path->dof > 2)1003 fab_path_axis(v,zn);1004 }1005 x0 = x;1006 y0 = y;1007 }1008 else if (current_element == 's') {1009 //1010 // relative smooth curveto1011 //1012 if ((last_element == 'c') || (last_element == 'C') || (last_element == 's') || (last_element == 'S')) {1013 x1 = x0 + (x0-x2);1014 y1 = y0 + (y0-y2);1015 }1016 else {1017 x1 = x0;1018 y1 = y0;1019 }1020 next_number(&ptr,&x2);1021 x2 += x0;1022 next_number(&ptr,&y2);1023 y2 += y0;1024 next_number(&ptr,&x);1025 x += x0;1026 next_number(&ptr,&y);1027 y += y0;1028 //printf(" path s: %f %f %f %f\n",x2,y2,x,y);1029 current_element = 'c';1030 cx = 3 * (x1 - x0);1031 bx = 3 * (x2 - x1) - cx;1032 ax = x - x0 - cx - bx;1033 cy = 3 * (y1 - y0);1034 by = 3 * (y2 - y1) - cy;1035 ay = y - y0 - cy - by;1036 for (point = 0; point < points; ++point) {1037 t = point / (points - 1.0);1038 xt = ax*t*t*t + bx*t*t + cx*t + x0;1039 yt = ay*t*t*t + by*t*t + cy*t + y0;1040 fab_path_point(v);1041 path_point(&xn,&yn,xt,yt,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1042 fab_path_axis(v,xn);1043 fab_path_axis(v,yn);1044 if (v->path->dof > 2)1045 fab_path_axis(v,zn);1046 }1047 x0 = x;1048 y0 = y;1049 }1050 else if (current_element == 'S') {1051 //1052 // absolute smooth curveto1053 //1054 if ((last_element == 'c') || (last_element == 'C') || (last_element == 's') || (last_element == 'S')) {1055 x1 = x0 + (x0-x2);1056 y1 = y0 + (y0-y2);1057 }1058 else {1059 x1 = x0;1060 y1 = y0;1061 }1062 next_number(&ptr,&x2);1063 next_number(&ptr,&y2);1064 next_number(&ptr,&x);1065 next_number(&ptr,&y);1066 //printf(" path S: %f %f %f %f\n",x2,y2,x,y);1067 current_element = 'C';1068 cx = 3 * (x1 - x0);1069 bx = 3 * (x2 - x1) - cx;1070 ax = x - x0 - cx - bx;1071 cy = 3 * (y1 - y0);1072 by = 3 * (y2 - y1) - cy;1073 ay = y - y0 - cy - by;1074 for (point = 0; point < points; ++point) {1075 t = point / (points - 1.0);1076 xt = ax*t*t*t + bx*t*t + cx*t + x0;1077 yt = ay*t*t*t + by*t*t + cy*t + y0;1078 fab_path_point(v);1079 path_point(&xn,&yn,xt,yt,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1080 fab_path_axis(v,xn);1081 fab_path_axis(v,yn);1082 if (v->path->dof > 2)1083 fab_path_axis(v,zn);1084 }1085 x0 = x;1086 y0 = y;1087 }1088 else if (current_element == 'a') {1089 //1090 // relative arc1091 //1092 next_number(&ptr,&rx);1093 next_number(&ptr,&ry);1094 next_number(&ptr,&rotation);1095 next_number(&ptr,&large_arc);1096 next_number(&ptr,&sweep);1097 next_number(&ptr,&x);1098 x += x0;1099 next_number(&ptr,&y);1100 y += y0;1101 //printf(" path a: %f %f %f %f %f %f %f\n",rx,ry,rotation,large_arc,sweep,x,y);1102 current_element = 'a';1103 phi = rotation*pi/180.0;1104 x1 = x0;1105 x2 = x;1106 y1 = y0;1107 y2 = y;1108 x1p = cos(phi)*(x1-x2)/2.0 + sin(phi)*(y1-y2)/2.0;1109 y1p = -sin(phi)*(x1-x2)/2.0 + cos(phi)*(y1-y2)/2.0;1110 sign = ((large_arc == sweep) ? -1 : 1);1111 if ((rx*rx*ry*ry - rx*rx*y1p*y1p - ry*ry*x1p*x1p) < 0) {1112 cxp = 0;1113 cyp = 0;1114 }1115 else {1116 cxp = sign * sqrt((rx*rx*ry*ry - rx*rx*y1p*y1p - ry*ry*x1p*x1p)/(rx*rx*y1p*y1p + ry*ry*x1p*x1p)) * rx*y1p/ry;1117 cyp = -1 * sign * sqrt((rx*rx*ry*ry - rx*rx*y1p*y1p - ry*ry*x1p*x1p)/(rx*rx*y1p*y1p + ry*ry*x1p*x1p)) * ry*x1p/rx;1118 }1119 cx = cos(phi)*cxp - sin(phi)*cyp + (x1+x2)/2.0;1120 cy = sin(phi)*cxp + cos(phi)*cyp + (y1+y2)/2.0;1121 theta_0 = angle(1,0,(x1p-cxp)/rx,(y1p-cyp)/ry);1122 theta_diff = angle ((x1p-cxp)/rx,(y1p-cyp)/ry,(-x1p-cxp)/rx,(-y1p-cyp)/ry);1123 theta_1 = theta_0 + theta_diff;1124 if (large_arc == 1) {1125 if (sweep == 0)1126 theta_1 -= 2*pi;1127 else1128 theta_1 += 2*pi;1129 }1130 for (point = 0; point < points; ++point) {1131 theta = theta_0 + (theta_1-theta_0) * point / (points - 1.0);1132 xt = cx + rx*cos(theta);1133 yt = cy + ry*sin(theta);1134 fab_path_point(v);1135 path_point(&xn,&yn,xt,yt,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1136 fab_path_axis(v,xn);1137 fab_path_axis(v,yn);1138 if (v->path->dof > 2)1139 fab_path_axis(v,zn);1140 }1141 x0 = x;1142 y0 = y;1143 }1144 else if (current_element == 'A') {1145 //1146 // absolute arc1147 //1148 next_number(&ptr,&rx);1149 next_number(&ptr,&ry);1150 next_number(&ptr,&rotation);1151 next_number(&ptr,&large_arc);1152 next_number(&ptr,&sweep);1153 next_number(&ptr,&x);1154 next_number(&ptr,&y);1155 //printf(" path A: %f %f %f %f %f %f %f\n",rx,ry,rotation,large_arc,sweep,x,y);1156 current_element = 'A';1157 phi = rotation*pi/180.0;1158 x1 = x0;1159 x2 = x;1160 y1 = y0;1161 y2 = y;1162 x1p = cos(phi)*(x1-x2)/2.0 + sin(phi)*(y1-y2)/2.0;1163 y1p = -sin(phi)*(x1-x2)/2.0 + cos(phi)*(y1-y2)/2.0;1164 sign = ((large_arc == sweep) ? -1 : 1);1165 if ((rx*rx*ry*ry - rx*rx*y1p*y1p - ry*ry*x1p*x1p) < 0) {1166 cxp = 0;1167 cyp = 0;1168 }1169 else {1170 cxp = sign * sqrt((rx*rx*ry*ry - rx*rx*y1p*y1p - ry*ry*x1p*x1p)/(rx*rx*y1p*y1p + ry*ry*x1p*x1p)) * rx*y1p/ry;1171 cyp = -1 * sign * sqrt((rx*rx*ry*ry - rx*rx*y1p*y1p - ry*ry*x1p*x1p)/(rx*rx*y1p*y1p + ry*ry*x1p*x1p)) * ry*x1p/rx;1172 }1173 cx = cos(phi)*cxp - sin(phi)*cyp + (x1+x2)/2.0;1174 cy = sin(phi)*cxp + cos(phi)*cyp + (y1+y2)/2.0;1175 theta_0 = angle(1,0,(x1p-cxp)/rx,(y1p-cyp)/ry);1176 theta_diff = angle ((x1p-cxp)/rx,(y1p-cyp)/ry,(-x1p-cxp)/rx,(-y1p-cyp)/ry);1177 theta_1 = theta_0 + theta_diff;1178 if (large_arc == 1) {1179 if (sweep == 0)1180 theta_1 -= 2*pi;1181 else1182 theta_1 += 2*pi;1183 }1184 for (point = 0; point < points; ++point) {1185 theta = theta_0 + (theta_1-theta_0) * point / (points - 1.0);1186 xt = cx + rx*cos(theta);1187 yt = cy + ry*sin(theta);1188 fab_path_point(v);1189 path_point(&xn,&yn,xt,yt,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1190 fab_path_axis(v,xn);1191 fab_path_axis(v,yn);1192 if (v->path->dof > 2)1193 fab_path_axis(v,zn);1194 }1195 x0 = x;1196 y0 = y;1197 }1198 else if ((current_element == 'z') || (current_element == 'Z')) {1199 //1200 // closepath1201 //1202 //printf(" path zZ\n");1203 fab_path_point(v);1204 fab_path_axis(v,v->path->segment->first->first->value);1205 fab_path_axis(v,v->path->segment->first->first->next->value);1206 if (v->path->dof > 2)1207 fab_path_axis(v,zn);1208 current_element = 0;1209 ptr += 1;1210 }1211 } while (*ptr != '\"');1212 clear_transform(&transform);1213 }1214 else if (strncmp(ptr,"<rect",5) == 0) {1215 //1216 // rectangle1217 //1218 set_transform(ptr,&transform,transforms);1219 set_intensity(ptr,&zn,v,zsign);1220 start = strstr(ptr,"width=");1221 next_number(&start,&width);1222 start = strstr(ptr,"height=");1223 next_number(&start,&height);1224 start = strstr(ptr,"x=");1225 next_number(&start,&x);1226 start = strstr(ptr,"y=");1227 next_number(&start,&y);1228 while (strncmp(ptr,"/>",2) != 0) ptr += 1; // read to end of element1229 //printf(" rect: %f %f %f %f\n",width,height,x,y);1230 fab_path_segment(v);1231 fab_path_point(v);1232 path_point(&xn,&yn,x,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1233 fab_path_axis(v,xn);1234 fab_path_axis(v,yn);1235 if (v->path->dof > 2)1236 fab_path_axis(v,zn);1237 fab_path_point(v);1238 path_point(&xn,&yn,x,y+height,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1239 fab_path_axis(v,xn);1240 fab_path_axis(v,yn);1241 if (v->path->dof > 2)1242 fab_path_axis(v,zn);1243 fab_path_point(v);1244 path_point(&xn,&yn,x+width,y+height,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1245 fab_path_axis(v,xn);1246 fab_path_axis(v,yn);1247 if (v->path->dof > 2)1248 fab_path_axis(v,zn);1249 fab_path_point(v);1250 path_point(&xn,&yn,x+width,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1251 fab_path_axis(v,xn);1252 fab_path_axis(v,yn);1253 if (v->path->dof > 2)1254 fab_path_axis(v,zn);1255 fab_path_point(v);1256 path_point(&xn,&yn,x,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1257 fab_path_axis(v,xn);1258 fab_path_axis(v,yn);1259 if (v->path->dof > 2)1260 fab_path_axis(v,zn);1261 clear_transform(&transform);1262 }1263 else if (strncmp(ptr,"<circle",7) == 0) {1264 //1265 // circle 1266 //1267 set_transform(ptr,&transform,transforms);1268 set_intensity(ptr,&zn,v,zsign);1269 start = strstr(ptr,"cx=");1270 next_number(&start,&cx);1271 start = strstr(ptr,"cy=");1272 next_number(&start,&cy);1273 start = strstr(ptr,"r=");1274 next_number(&start,&r);1275 while (strncmp(ptr,"/>",2) != 0) ptr += 1; // read to end of element1276 //printf(" circle: %f %f %f\n",cx,cy,r);1277 fab_path_segment(v);1278 for (point = 0; point < points; ++point) {1279 fab_path_point(v);1280 x = cx + r*cos(point*2*pi/(points-1.0));1281 y = cy + r*sin(point*2*pi/(points-1.0));1282 path_point(&xn,&yn,x,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1283 fab_path_axis(v,xn);1284 fab_path_axis(v,yn);1285 if (v->path->dof > 2)1286 fab_path_axis(v,zn);1287 }1288 clear_transform(&transform);1289 }1290 else if (strncmp(ptr,"<ellipse",8) == 0) {1291 //1292 // ellipse 1293 //1294 while (strncmp(ptr,"/>",2) != 0) ptr += 1; // read to end of element1295 printf(" svg_path: ellipse not yet implemented\n");1296 }1297 else if (strncmp(ptr,"<line",5) == 0) {1298 //1299 // line1300 //1301 set_transform(ptr,&transform,transforms);1302 set_intensity(ptr,&zn,v,zsign);1303 start = 3+strstr(ptr,"x1=");1304 next_number(&start,&x1);1305 start = 3+strstr(ptr,"y1=");1306 next_number(&start,&y1);1307 start = 3+strstr(ptr,"x2=");1308 next_number(&start,&x2);1309 start = 3+strstr(ptr,"y2=");1310 next_number(&start,&y2);1311 while (strncmp(ptr,"/>",2) != 0) ptr += 1; // read to end of element1312 //printf(" line: %f %f %f %f\n",x1,y1,x2,y2);1313 fab_path_segment(v);1314 fab_path_point(v);1315 path_point(&xn,&yn,x1,y1,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1316 fab_path_axis(v,xn);1317 fab_path_axis(v,yn);1318 if (v->path->dof > 2)1319 fab_path_axis(v,zn);1320 fab_path_point(v);1321 path_point(&xn,&yn,x2,y2,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1322 fab_path_axis(v,xn);1323 fab_path_axis(v,yn);1324 if (v->path->dof > 2)1325 fab_path_axis(v,zn);1326 clear_transform(&transform);1327 }1328 else if (strncmp(ptr,"<polyline",9) == 0) {1329 //1330 // polyline1331 //1332 set_transform(ptr,&transform,transforms);1333 set_intensity(ptr,&zn,v,zsign);1334 ptr = 8+strstr(ptr,"points=");1335 //1336 // move to first point1337 //1338 next_number(&ptr,&x);1339 next_number(&ptr,&y);1340 fab_path_segment(v);1341 fab_path_point(v);1342 path_point(&xn,&yn,x,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1343 fab_path_axis(v,xn);1344 fab_path_axis(v,yn);1345 if (v->path->dof > 2)1346 fab_path_axis(v,zn);1347 while (1) {1348 //1349 // loop over remaining points 1350 //1351 next_number(&ptr,&x);1352 next_number(&ptr,&y);1353 fab_path_point(v);1354 path_point(&xn,&yn,x,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1355 fab_path_axis(v,xn);1356 fab_path_axis(v,yn);1357 if (v->path->dof > 2)1358 fab_path_axis(v,zn);1359 while ((*ptr == ' ') || (*ptr == '"') || (*ptr == 13) || (*ptr == 10)) ptr += 1; // skip space1360 if (strncmp(ptr,"/>",2) == 0) break; // check for end1361 }1362 clear_transform(&transform);1363 }1364 else if (strncmp(ptr,"<polygon",8) == 0) {1365 //1366 // polygon1367 //1368 set_transform(ptr,&transform,transforms);1369 set_intensity(ptr,&zn,v,zsign);1370 ptr = 8+strstr(ptr,"points=");1371 //1372 // move to first point1373 //1374 next_number(&ptr,&x0);1375 next_number(&ptr,&y0);1376 fab_path_segment(v);1377 fab_path_point(v);1378 path_point(&xn,&yn,x0,y0,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1379 fab_path_axis(v,xn);1380 fab_path_axis(v,yn);1381 if (v->path->dof > 2)1382 fab_path_axis(v,zn);1383 while (1) {1384 //1385 // loop over remaining points 1386 //1387 next_number(&ptr,&x);1388 next_number(&ptr,&y);1389 fab_path_point(v);1390 path_point(&xn,&yn,x,y,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1391 fab_path_axis(v,xn);1392 fab_path_axis(v,yn);1393 if (v->path->dof > 2)1394 fab_path_axis(v,zn);1395 while ((*ptr == ' ') || (*ptr == '"') || (*ptr == 13) || (*ptr == 10)) ptr += 1; // skip space1396 if (strncmp(ptr,"/>",2) == 0) break; // check for end1397 }1398 fab_path_point(v);1399 path_point(&xn,&yn,x0,y0,transform,transforms,xnscale,ynscale,xnmid,vxmid,ynmid,vymid);1400 fab_path_axis(v,xn);1401 fab_path_axis(v,yn);1402 if (v->path->dof > 2)1403 fab_path_axis(v,zn);1404 clear_transform(&transform);1405 }1406 else if (strncmp(ptr,"<text",5) == 0) {1407 //1408 // text 1409 //1410 while (strncmp(ptr,"/text>",6) != 0) ptr += 1; // read to end of element1411 printf(" svg_path: text not implemented\n");1412 }1413 } while ((endptr-ptr) > 1);1414 }1415int main(int argc, char **argv) {1416 //1417 // local vars1418 //1419 struct fab_vars v;1420 init_vars(&v);1421 int points,resolution;1422 float scale,zmin,zmax;1423 //1424 // command line args1425 // Largo al Factotum Canadian Brass1426 //1427 if ((argc != 3) && (argc != 4) && (argc != 5) && (argc != 6) && (argc != 7) && (argc != 8)) {1428 printf("command line: svg_path in.svg out.path [scale [points [resolution [zmin [zmax]]]]]\n");1429 printf(" in.svg = input binary SVG file\n");1430 printf(" out.path = output path file\n");1431 printf(" scale = scale factor (optional, default 1.0)\n");1432 printf(" points = points per curve segment (optional, default 25)\n");1433 printf(" resolution = path x resolution (optional, default 10000)\n");1434 printf(" zmin = path min intensity z (optional, mm, default 0)\n");1435 printf(" zmax = path max intensity z (optional, mm, default zmin)\n");1436 exit(-1);1437 }1438 if (argc == 3) {1439 scale = 1.0;1440 points = 25;1441 resolution = 10000;1442 zmin = 0;1443 zmax = 0;1444 }1445 else if (argc == 4) {1446 sscanf(argv[3],"%f",&scale);1447 points = 25;1448 resolution = 10000;1449 zmin = 0;1450 zmax = 0;1451 }1452 else if (argc == 5) {1453 sscanf(argv[3],"%f",&scale);1454 sscanf(argv[4],"%d",&points);1455 resolution = 10000;1456 zmin = 0;1457 zmax = 0;1458 }1459 else if (argc == 6) {1460 sscanf(argv[3],"%f",&scale);1461 sscanf(argv[4],"%d",&points);1462 sscanf(argv[5],"%d",&resolution);1463 zmin = 0;1464 zmax = 0;1465 }1466 else if (argc == 7) {1467 sscanf(argv[3],"%f",&scale);1468 sscanf(argv[4],"%d",&points);1469 sscanf(argv[5],"%d",&resolution);1470 sscanf(argv[6],"%f",&zmin);1471 zmax = zmin;1472 }1473 else if (argc == 8) {1474 sscanf(argv[3],"%f",&scale);1475 sscanf(argv[4],"%d",&points);1476 sscanf(argv[5],"%d",&resolution);1477 sscanf(argv[6],"%f",&zmin);1478 sscanf(argv[7],"%f",&zmax);1479 }1480 //1481 // read SVG1482 //1483 if (argc <= 6)1484 fab_path_start(&v,2);1485 else1486 fab_path_start(&v,3);1487 fab_read_svg(&v,argv[1],scale,points,resolution,zmin,zmax);1488 //1489 // write path1490 //1491 fab_write_path(&v,argv[2]);1492 //1493 // return1494 //1495 return(0);1496 }...

Full Screen

Full Screen

isvr-menu-block-nav.js

Source:isvr-menu-block-nav.js Github

copy

Full Screen

1AFRAME.registerComponent('isvr-menu-block-nav', {2 schema: {3 show: { 4 type: 'string'5 },6 inactivecolor: {7 type: 'string'8 },9 activecolor: {10 type: 'string'11 }12 },13 14 init: function () {15 var self = this;16 var data = this.data;17 /* initial state */18 if (this.el.getAttribute('color') == data.activecolor) {19 this.el.addState('active');20 } 21 this.el.addEventListener('mouseenter', function(evt) {22 self.el.setAttribute('color', data.activecolor);23 });24 this.el.addEventListener('mouseleave', function() {25 if (!self.el.is('active')) {26 self.el.setAttribute('color', data.inactivecolor);27 }28 });29 var all = document.querySelectorAll('.nav-circle');30 this.el.addEventListener('click', function() {31 var activeEl = null;32 if (self.el.is('active')) {33 return;34 }35 for (var i=0; i<all.length; i++) {36 if (all[i].is('active')) {37 activeEl = all[i];38 }39 all[i].setAttribute('color', data.inactivecolor);40 all[i].removeState('active');41 }42 self.el.setAttribute('color', data.activecolor);43 self.el.addState('active');44 var next_number = data.show.slice(-1);45 var current_number = activeEl.getAttribute('isvr-menu-block-nav').show.slice(-1);46 document.querySelector('#item-wrapper').emit('from_' + current_number + '_to_' + next_number);47 /* show next menu block */48 setTimeout(function() {49 //document.querySelector('#menu-block-' + next_number).setAttribute('visible', true);50 if (current_number < next_number) {51 for (var j = current_number; j <= next_number; j++){52 document.querySelector('#menu-block-' + j).setAttribute('visible', true);53 }54 } else { 55 for (var j = current_number; j >= next_number; j--){56 document.querySelector('#menu-block-' + j).setAttribute('visible', true);57 }58 }59 }, 300);60 setTimeout(function() {61 //document.querySelector('#menu-block-' + current_number).setAttribute('visible', false);62 if (current_number < next_number) {63 for (var j = current_number; j < next_number; j++) {64 document.querySelector('#menu-block-' + j).setAttribute('visible', false);65 }66 } else {67 for (var j = current_number; j > next_number; j--) {68 document.querySelector('#menu-block-' + j).setAttribute('visible', false);69 }70 }71 }, 500); 72 });73 74 }...

Full Screen

Full Screen

problem2.js

Source:problem2.js Github

copy

Full Screen

1var fs = require('fs');2var starter_sequence_arr = [];3function parseNumberSequence(filename) {4 var file_array = fs.readFileSync(filename).toString().split("\n");5 starter_sequence_arr = file_array[0].split(",").map(val => parseInt(val));6}7function executeSequenceToTurn(last_turn) {8 // 3 1 29 // var previous_seen = {3:2,1:1}; //object to keep track of previous references10 // var next_number = 2;11 // last_turn = 2020;12 // 1 3 213 // var previous_seen = {1:2,3:1}; //object to keep track of previous references14 // var next_number = 2;15 // last_turn = 2020;16 // 0 3 617 // var previous_seen = {0:2,3:1}; //object to keep track of previous references18 // var next_number = 6;19 // 0,3,620 var previous_seen = {0:2,3:1}; //object to keep track of previous references21 var next_number = 6;22 last_turn = 30000000;23 // 0,6,1,7,2,19,2024 var previous_seen = {0:7,6:6,1:5,7:4,2:3,19:1}; //object to keep track of previous references25 var next_number = 20;26 last_turn = 30000000;27 for (var n=Object.keys(previous_seen).length+1; n<last_turn; n++) {28 if (!(next_number in previous_seen)) {29 previous_seen[next_number] = 0;30 next_number = 0;31 for (seen_number of Object.keys(previous_seen)) { previous_seen[seen_number]++; }32 } else {33 var tmp = next_number;34 next_number = previous_seen[next_number];35 previous_seen[tmp] = 0;36 for (seen_number of Object.keys(previous_seen)) { previous_seen[seen_number]++; }37 }38 // console.log(`previous_seen: ${JSON.stringify(previous_seen)}`);39 // console.log(`next_number: ${JSON.stringify(next_number)}`);40 if ((n%10000)==0) {console.log(n);}41 // console.log(n);42 }43 44 console.log(next_number);45 return next_number;46}47// parseNumberSequence("example_input.txt");48// console.log(`${JSON.stringify(starter_sequence_arr)}`);49executeSequenceToTurn(10);50// parseNumberSequence("example2_input.txt");51// console.log(`${JSON.stringify(starter_sequence_arr)}`);52// executeSequenceToTurn(2020);53// parseNumberSequence("actual_input.txt");54// console.log(`${JSON.stringify(starter_sequence_arr)}`);55// executeSequenceToTurn(2020);56// parseNumberSequence("example2_input.txt");57// console.log(`${JSON.stringify(starter_sequence_arr)}`);58// executeSequenceToTurn(30000000);59// parseNumberSequence("actual_input.txt");60// console.log(`${JSON.stringify(starter_sequence_arr)}`);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = async function (argosy) {2 const nextNumber = argosy.pattern('NEXT_NUMBER')3 const number = await nextNumber()4 console.log(number)5}6See full documentation at [Argosy](

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run argos automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful