| 443 | } |
| 444 | |
| 445 | func TestPathReplace(t *testing.T) { |
| 446 | line := func(p0, p1 Point) *Path { |
| 447 | p := &Path{} |
| 448 | p.MoveTo(p0.X, p0.Y) |
| 449 | p.LineTo(p1.X, p1.Y-5.0) |
| 450 | return p |
| 451 | } |
| 452 | quad := func(p0, p1, p2 Point) *Path { |
| 453 | p := &Path{} |
| 454 | p.MoveTo(p0.X, p0.Y) |
| 455 | p.LineTo(p2.X, p2.Y) |
| 456 | return p |
| 457 | } |
| 458 | cube := func(p0, p1, p2, p3 Point) *Path { |
| 459 | p := &Path{} |
| 460 | p.MoveTo(p0.X, p0.Y) |
| 461 | p.LineTo(p3.X, p3.Y) |
| 462 | return p |
| 463 | } |
| 464 | arc := func(p0 Point, rx, ry, phi float64, largeArc, sweep bool, p1 Point) *Path { |
| 465 | p := &Path{} |
| 466 | p.MoveTo(p0.X, p0.Y) |
| 467 | p.ArcTo(rx, ry, phi, !largeArc, sweep, p1.X, p1.Y) |
| 468 | return p |
| 469 | } |
| 470 | |
| 471 | var tts = []struct { |
| 472 | orig string |
| 473 | res string |
| 474 | line func(Point, Point) *Path |
| 475 | quad func(Point, Point, Point) *Path |
| 476 | cube func(Point, Point, Point, Point) *Path |
| 477 | arc func(Point, float64, float64, float64, bool, bool, Point) *Path |
| 478 | }{ |
| 479 | {"C0 10 10 10 10 0L30 0", "L30 0", nil, quad, cube, nil}, |
| 480 | {"M20 0L30 0C0 10 10 10 10 0", "M20 0L30 0L10 0", nil, quad, cube, nil}, |
| 481 | {"M10 0L20 0Q25 10 20 10A5 5 0 0 0 30 10z", "M10 0L20 -5L20 10A5 5 0 1 0 30 10L10 -5z", line, quad, cube, arc}, |
| 482 | {"L10 0L0 5z", "L10 -5L10 0L0 0L0 5L0 -5z", line, nil, nil, nil}, |
| 483 | } |
| 484 | for _, tt := range tts { |
| 485 | t.Run(tt.orig, func(t *testing.T) { |
| 486 | p := MustParseSVGPath(tt.orig) |
| 487 | test.T(t, p.replace(tt.line, tt.quad, tt.cube, tt.arc), MustParseSVGPath(tt.res)) |
| 488 | }) |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | func TestPathMarkers(t *testing.T) { |
| 493 | start := MustParseSVGPath("L1 0L0 1z") |