take 'many things' and turn them into a line based on the formatting string. 'm' - moveTo, needs a Vec2 or a Vec3 'l' - lineTo, needs a Vec2 or a Vec3 'c' - cubicTo, needs 3 Vec2 or Vec3; 's' - smoothTo, needs 1 Vec2 or Vec3 ' ' will loop the previous instruction; '+' will loop the whole set of
(String format, Object... input)
| 677 | Vec3 lastMove = null; |
| 678 | char[] cs = format.toCharArray(); |
| 679 | boolean looping = false; |
| 680 | for (int i = 0; i < cs.length; i++) { |
| 681 | char c = cs[i]; |
| 682 | |
| 683 | if (c == '*') { |
| 684 | c = cs[i - 1]; |
| 685 | i--; |
| 686 | looping = true; |
| 687 | } |
| 688 | if (c == '+') { |
| 689 | c = cs[0]; |
| 690 | i = 0; |
| 691 | looping = true; |
| 692 | } |
| 693 | if (c == 't') |
| 694 | c = f.get(q) instanceof TaggedVec3 ? ((TaggedVec3) f.get(q)).tag : (i == 0 ? 'm' : 'l'); |
| 695 | |
| 696 | try { |
| 697 | switch (c) { |
| 698 | |
| 699 | case 'b': |
| 700 | if (lastMove == null) |
| 701 | throw new IllegalArgumentException(" 'b' without previous 'm'"); |
| 702 | f.add(q, lastMove); |
| 703 | break; |
| 704 | case 'm': |
| 705 | lastMove = f.get(q++); |
| 706 | moveTo(lastMove); |
| 707 | break; |
| 708 | case 'l': |
| 709 | lineTo(f.get(q++)); |
| 710 | break; |
| 711 | case 'd': |
| 712 | q++; |
| 713 | break; |
| 714 | case 's': |
| 715 | smoothTo(f.get(q++)); |
| 716 | break; |
| 717 | case 'c': |
| 718 | cubicTo(f.get(q++), f.get(q++), f.get(q++)); |
| 719 | break; |
| 720 | case 'C': |
| 721 | cubicTo(f.get(q - 2), f.get(q - 1), f.get(q)); |
| 722 | q++; |
| 723 | break; |
| 724 | case '1': |
| 725 | q++; |
| 726 | break; |
| 727 | case '2': |
| 728 | q++; |
| 729 | break; |
| 730 | |
| 731 | default: |
| 732 | throw new IllegalArgumentException(" unknown format specification " + c); |
| 733 | } |
| 734 | } catch (IndexOutOfBoundsException e) { |
| 735 | if (looping) return this; |
| 736 | throw e; |
no test coverage detected