-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcloner.go
39 lines (34 loc) · 911 Bytes
/
cloner.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
package composite
type cloner map[int]*Layer
func (cl cloner) clone(src *Layer, dest *Layer) {
*dest = *src
cl[dest.SeqID] = dest
dest.Children = make([]Layer, len(src.Children))
for i := range dest.Children {
cl.clone(&src.Children[i], &dest.Children[i])
dest.Children[i].Parent = dest
}
}
func (cl cloner) registerClippingGroup(src *Layer, dest *Layer) {
dest.Clip = make([]*Layer, len(src.Clip))
for i := range dest.Clip {
dest.Clip[i] = cl[src.Clip[i].SeqID]
}
if src.ClippedBy != nil {
dest.ClippedBy = cl[src.ClippedBy.SeqID]
}
for i := range dest.Children {
cl.registerClippingGroup(&src.Children[i], &dest.Children[i])
}
}
func (cl cloner) Clone(t *Tree) *Tree {
nt := *t
nt.Renderer = &Renderer{
tree: &nt,
cache: map[int]*cache{},
}
nt.Renderer.pool.New = nt.Renderer.allocate
cl.clone(&t.Root, &nt.Root)
cl.registerClippingGroup(&t.Root, &nt.Root)
return &nt
}