PathDataIterFunc traverses the path data and calls given function on each coordinate point, passing overall starting index of coords in data stream, command, index of the points within that command, and coord values (absolute, not relative, regardless of the command type), including special control
(data []PathData, fun func(idx int, cmd PathCmds, ptIndex int, cp math32.Vector2, ctrls []math32.Vector2) bool)
| 422 | // when multiple, e.g., C,S. |
| 423 | // For A: order is: nc, prv, rad, math32.Vector2{X: ang}, math32.Vec2(laf, sf)} |
| 424 | func PathDataIterFunc(data []PathData, fun func(idx int, cmd PathCmds, ptIndex int, cp math32.Vector2, ctrls []math32.Vector2) bool) { |
| 425 | sz := len(data) |
| 426 | if sz == 0 { |
| 427 | return |
| 428 | } |
| 429 | lastCmd := PcErr |
| 430 | var st, cp, xp, ctrl, nc math32.Vector2 |
| 431 | for i := 0; i < sz; { |
| 432 | cmd, n := PathDataNextCmd(data, &i) |
| 433 | rel := false |
| 434 | switch cmd { |
| 435 | case PcM: |
| 436 | cp = PathDataNextVector(data, &i) |
| 437 | if !fun(i-2, cmd, 0, cp, nil) { |
| 438 | return |
| 439 | } |
| 440 | st = cp |
| 441 | for np := 1; np < n/2; np++ { |
| 442 | cp = PathDataNextVector(data, &i) |
| 443 | if !fun(i-2, cmd, np, cp, nil) { |
| 444 | return |
| 445 | } |
| 446 | } |
| 447 | case Pcm: |
| 448 | cp = PathDataNextRel(data, &i, cp) |
| 449 | if !fun(i-2, cmd, 0, cp, nil) { |
| 450 | return |
| 451 | } |
| 452 | st = cp |
| 453 | for np := 1; np < n/2; np++ { |
| 454 | cp = PathDataNextRel(data, &i, cp) |
| 455 | if !fun(i-2, cmd, np, cp, nil) { |
| 456 | return |
| 457 | } |
| 458 | } |
| 459 | case PcL: |
| 460 | for np := 0; np < n/2; np++ { |
| 461 | cp = PathDataNextVector(data, &i) |
| 462 | if !fun(i-2, cmd, np, cp, nil) { |
| 463 | return |
| 464 | } |
| 465 | } |
| 466 | case Pcl: |
| 467 | for np := 0; np < n/2; np++ { |
| 468 | cp = PathDataNextRel(data, &i, cp) |
| 469 | if !fun(i-2, cmd, np, cp, nil) { |
| 470 | return |
| 471 | } |
| 472 | } |
| 473 | case PcH: |
| 474 | for np := 0; np < n; np++ { |
| 475 | cp.X = PathDataNext(data, &i) |
| 476 | if !fun(i-1, cmd, np, cp, nil) { |
| 477 | return |
| 478 | } |
| 479 | } |
| 480 | case Pch: |
| 481 | for np := 0; np < n; np++ { |
no test coverage detected