-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquadtrees.go
More file actions
69 lines (54 loc) · 1.13 KB
/
Copy pathquadtrees.go
File metadata and controls
69 lines (54 loc) · 1.13 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import "math"
type CustomQuadTreeNode struct {
X, Y int // coordonnées du centre du noeud
TopLeft *CustomQuadTree
TopRight *CustomQuadTree
BottomLeft *CustomQuadTree
BottomRight *CustomQuadTree
Content any
}
type CustomQuadTree struct {
Root *CustomQuadTreeNode
}
func (cq *CustomQuadTree) Search(x, y int) any {
q := cq.Root
if q == nil {
return nil
}
if x == q.X && y == q.Y {
return q.Content
}
if x < 0 && y < 0 {
return q.TopLeft.Search(x, y)
} else if x >= 0 && y < 0 {
return q.TopRight.Search(x, y)
} else if x < 0 && y >= 0 {
return q.BottomLeft.Search(x, y)
} else {
return q.BottomRight.Search(x, y)
}
}
func (cq *CustomQuadTree) Southmost() int { // renvoie la coordonnée Y du point le plus bas
if cq.Root == nil {
return math.MaxInt
}
node := cq.Root
w, e := math.MaxInt, math.MaxInt
if node.TopLeft != nil {
w = node.TopLeft.Southmost()
}
if node.TopRight != nil {
e = node.TopRight.Southmost()
}
if w < e && w < node.Y {
return w
}
if e < w && e < node.Y {
return e
}
if node.Y < w && node.Y < e {
return node.Y
}
return math.MaxInt
}