-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.go
55 lines (51 loc) · 905 Bytes
/
select.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
46
47
48
49
50
51
52
53
54
55
package main
import "image"
func Select(pt image.Point, root *Di) Node {
if root == nil {
return nil
}
return select0(pt, root)
}
func select0(pt image.Point, x Node) (a Node) {
if x == nil {
return nil
}
switch x := x.(type) {
case *Nest:
case Node:
if !pt.In(x.Bounds()) {
return nil
}
a = x
}
if x.Kid() == nil {
return x
}
for _, y := range x.Kid() {
z := select0(pt, y)
if z != nil {
return z
}
}
return a
}
func (n *Di) Kid() []Node {
if n.Node == nil {
return nil
}
return []Node{n.Node}
}
func (n *Rect) Kid() []Node {
if n.Node == nil {
return nil
}
return []Node{n.Node}
}
func (n *Nest) Kid() []Node {
return n.m
}
func (n *Circ) Kid() []Node { return []Node{n.Node} }
func (n *Text) Kid() []Node { return nil }
func (n *Link) Kid() []Node { panic("!") }
func (n *Dot) Kid() []Node { panic("!") }
func (n *Line) Kid() []Node { return nil }