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

Function TestPathSimplifyVisvalingamWhyatt

path_simplify_test.go:9–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestPathSimplifyVisvalingamWhyatt(t *testing.T) {
10 tests := []struct {
11 p string
12 tolerance float64
13 r string
14 }{
15 // closed path
16 {"M0 0L10 0L10 4L11 5L10 6L10 10L0 10z", 1.0, "M0 0L10 0L10 4L11 5L10 6L10 10L0 10z"},
17 {"M0 0L10 0L10 4L11 5L10 6L10 10L0 10z", 2.0, "M0 0L10 0L10 10L0 10z"},
18 {"M0 0L10 0L10 4L11 5L10 6L10 10L0 10z", 50.0, "M0 0L10 0L10 10L0 10z"},
19 {"M0 0L10 0L10 4L11 5L10 6L10 10L0 10z", 51.0, ""},
20
21 // open path
22 {"M0 0L10 0L11 1L12 0L13 -5L14 0", 1.0, "M0 0L10 0L11 1L12 0L13 -5L14 0"},
23 {"M0 0L10 0L11 1L12 0L13 -5L14 0", 2.0, "M0 0L12 0L13 -5L14 0"},
24 {"M0 0L10 0L11 1L12 0L13 -5L14 0", 6.0, "M0 0L14 0"},
25
26 // bugs
27 {"M0 0L1 1L2 0zM2 0L4 2L4 0zM4 0L5 1L6 0z", 2.0, "M2 0L4 2L4 0z"},
28 {"M2 0L4 2L4 0zM0 0L1 1L2 0zM4 0L5 1L6 0z", 2.0, "M2 0L4 2L4 0z"},
29 {"M0 0L1 1L2 0zM4 0L5 1L6 0zM2 0L4 2L4 0z", 2.0, "M2 0L4 2L4 0z"},
30 {"M0 0L40 0L40.1 0.1L40.2 0L40.3 0.5L40 40z", 2.0, "M0 0L40.2 0L40.3 0.5L40 40z"},
31 {"M0 0L40 0L40.1 0.1L40.2 0L40.3 0.5L40 40z", 3.0, "M0 0L40.2 0L40 40z"},
32 {"M0 0L10 0", 1.0, "M0 0L10 0"},
33 }
34
35 for _, tt := range tests {
36 t.Run(tt.p, func(t *testing.T) {
37 p := MustParseSVGPath(tt.p)
38 r := MustParseSVGPath(tt.r)
39 test.T(t, p.SimplifyVisvalingamWhyatt(tt.tolerance), r)
40 })
41 }
42
43 p := MustParseSVGPath("M0 0L10 0L5 10z")
44 test.T(t, NewVisvalingamWhyatt(func(_ Point) bool {
45 return false
46 }).Simplify(p.Split(), 1.0), p)
47}
48
49func TestPathFastClip(t *testing.T) {
50 tests := []struct {

Callers

nothing calls this directly

Calls 7

MustParseSVGPathFunction · 0.85
NewVisvalingamWhyattFunction · 0.85
TMethod · 0.80
SimplifyMethod · 0.80
SplitMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected