Blob Blame Raw


void spSkipSpace(const char **pos)
  { while(**pos && isspace(**pos)) ++*pos; }


double spReadNum(const char **pos) {
  spSkipSpace(pos);
  char *end = "";
  double x = strtod(*pos, &end);
  *pos = end;
  return x;
}


void spTrack(const char *path, double *x, double *y) {
  double sx = *x, sy = *y;
  const char *c = path;
  spSkipSpace(&c);
  while(*c) {
    switch(*c++) {
    case 'M':
      sx = (*x = spReadNum(&c));
      sy = (*y = spReadNum(&c));
      break;
    case 'm':
      sx = (*x += spReadNum(&c));
      sy = (*y += spReadNum(&c));
      break;

    case 'C':
      spReadNum(&c);
      spReadNum(&c);
    case 'Q':
      spReadNum(&c);
      spReadNum(&c);
    case 'L':
      *x = spReadNum(&c);
      *y = spReadNum(&c);
      break;

    case 'c':
      spReadNum(&c);
      spReadNum(&c);
    case 'q':
      spReadNum(&c);
      spReadNum(&c);
    case 'l':
      *x += spReadNum(&c);
      *y += spReadNum(&c);
      break;

    case 'Z':
    case 'z':
      *x = sx;
      *y = sy;
      break;
    default:
      printf("unknown path command \'%c\'\n", *(c - 1));
    }
    spSkipSpace(&c);
  }
}