-
Notifications
You must be signed in to change notification settings - Fork 0
/
lineproc.go
45 lines (40 loc) · 1.01 KB
/
lineproc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package graphics2d
// CurvesToLinesProc takes a path and converts all of the points to lines.
type CurvesToLinesProc struct {
SkipCP bool
}
// Process implements the PathProcessor interface.
func (clp *CurvesToLinesProc) Process(p *Path) []*Path {
parts := p.Parts()
nparts := [][][]float64{}
cp := parts[0][0]
for _, part := range parts {
if clp.SkipCP {
lp := part[len(part)-1]
nparts = append(nparts, [][]float64{cp, lp})
cp = lp
} else {
for i := 1; i < len(part); i++ {
nparts = append(nparts, [][]float64{cp, part[i]})
cp = part[i]
}
}
}
path := PartsToPath(nparts...)
if p.Closed() {
path.Close()
}
return []*Path{path}
}
// SplitProc breaks up a path into a collection of paths, one for each step in the original path.
type SplitProc struct{}
// Process implements the PathProcessor interface.
func (sp *SplitProc) Process(p *Path) []*Path {
parts := p.Parts()
n := len(parts)
res := make([]*Path, n)
for i := 0; i < n; i++ {
res[i] = PartsToPath(parts[i])
}
return res
}