MCPcopy
hub / github.com/tdewolff/canvas / TestBentleyOttmannPrecision

Function TestBentleyOttmannPrecision

path_intersection_test.go:637–716  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

635}
636
637func TestBentleyOttmannPrecision(t *testing.T) {
638 var tts = []struct {
639 p string
640 op pathOp
641 q string
642 r string
643 }{
644 // intersection is moved upwards
645 {"L4 1L2 2L1 1L4 0z", opSettle, "", "L4 0L2 1zM1 1L4 1L2 2z"},
646
647 // intersection is moved downwards
648 {"L4 1L2 2L-1 1L4 0z", opSettle, "", "M-1 1L2 0L4 1L2 2z"},
649
650 // one intersection and one passing snap to (2,2)
651 {"M-2 -1L5 3L-3 1L-2 0L5 4L6 4L6 -1z", opSettle, "", "M-3 1L-2 0L2 2zM-2 -1L6 -1L6 4L5 4L2 2z"},
652
653 // two intersections snap to (2,2)
654 {"M-2 -1L4 3L5 3L-3 1L-2 4L4 1z", opSettle, "", "M-3 1L2 2L-2 4zM-2 -1L4 1L2 2z"},
655 {"M-2 -1L7 5L9 4L-3 1L-2 4L4 1z", opSettle, "", "M-3 1L2 2L-2 4zM-2 -1L4 1L2 2zM3 3L9 4L7 5z"},
656
657 // one intersections in (2,1) and one in (2,2), first intersection causes second
658 {"M0 1L4 1L4 2L0 2L0 3L3 3L1 0z", opSettle, "", "M0 1L1 0L2 1zM0 2L2 2L3 3L0 3zM2 1L4 1L4 2L2 2z"},
659
660 // one intersections in (2,1) and one in (2,2), first intersection passes through (2,2)
661 {"M0 1L4 1L4 -1L-1 -1L7 5L11 6L-15 -4zM-4 1L4 3L4 4L-4 4z", opSettle, "", "M-15 -4L0 1L2 1L2 2zM-4 1L2 2L4 3L4 4L-4 4zM-1 -1L4 -1L4 1L2 1zM4 3L11 6L7 5z"},
662
663 // segments becomes vertical and overlapping
664 {"M1 4L2.1 1L2 3L2 0L3 0L3 4z", opSettle, "", "M1 4L2 3L2 0L3 0L3 4z"},
665 {"M1 4L2.4 1L2 3L2 0L3 0L3 4z", opSettle, "", "M1 4L2 3L2 0L3 0L3 4z"},
666 {"M2.6 4L2.4 1L2 3L2 0L3 0L3 4z", opSettle, "", "M2 0L3 0L3 4L2 1z"},
667
668 // collapse only bottom-left corner
669 {"M0 2L2 2L1 3L1 1z", opSettle, "", "M1 2L2 2L1 3z"},
670 {"M0 2L2 2L1 1L1 3z", opSettle, "", "M0 2L1 2L1 3zM1 1L2 2L1 2z"},
671
672 // segment is almost vertical but downward-sloped
673 {"M0 2L2 2L1 3L1.0000000000000002 0z", opSettle, "", "M0 2L1 0L1 2zM1 2L2 2L1 3z"},
674
675 // order of overlapping segments
676 {"M0 2L1 1L3 -3L4 -3L4 2z", opOR, "M0 2L1 1L2.1 -1L4 -1L4 2z", "M0 2L1 1L3 -3L4 -3L4 2z"},
677 {"M1 2L4 1L3 2zM1 3L2.4 0L5 3z", opSettle, "", "M1 2L2 2L2 0L3 1L4 1L5 3L1 3z"},
678
679 // breakup test
680 {"M0 2L1 0L2 2zM0 0L2 -1L2 -3z", opSettle, "", "L2 -3L2 -1L1 0zM0 2L1 0L2 2z"},
681
682 // segment crosses square in between
683 {"L3 0L3 7L1.1 7zM1 1L2 2L2 1zM1 3L2 4L2 3zM1 5L2 6L2 5z", opSettle, "", "M0 0L3 0L3 7L1 7L1 5L2 6L2 5L1 5L1 3L2 4L2 3L1 3zM1 1L2 2L2 1z"},
684 {"M1.2 0L3 0L3 10L0 10zM1 3L2 3L2 1zM1 6L2 6L2 4zM1 9L2 9L2 7z", opSettle, "", "M0 10L1 6L2 6L2 4L1 6L1 3L2 3L2 1L1 3L1 0L3 0L3 10zM1 9L2 9L2 7z"},
685
686 {"M0 0L5 2L5 4L0 4L4 -2L4 -1L0 2z", opSettle, "", "M0 0L2 1L0 2zM0 4L2 1L5 2L5 4z"},
687 }
688
689 origEpsilon := BentleyOttmannEpsilon
690 BentleyOttmannEpsilon = 1.0
691 for _, tt := range tts {
692 t.Run(fmt.Sprint(tt.p), func(t *testing.T) {
693 ps := MustParseSVGPath(tt.p).Split()
694 var qs []*Path

Callers

nothing calls this directly

Calls 6

MustParseSVGPathFunction · 0.85
bentleyOttmannFunction · 0.85
SplitMethod · 0.80
TMethod · 0.80
MergeMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected