-
Notifications
You must be signed in to change notification settings - Fork 0
/
box.go
67 lines (60 loc) · 980 Bytes
/
box.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
56
57
58
59
60
61
62
63
64
65
66
67
package lin3dmath
type Boxi struct {
Start Vector3i
End Vector3i
}
func (s Boxi) GrowBy(val int) Boxi {
s.Start.X -= val
s.Start.Y -= val
s.Start.Z -= val
s.End.X += val
s.End.Y += val
s.End.Z += val
return s
}
func (s *Boxi) Intersection(b Boxi) (exist bool, r Boxi) {
exist = true
if s.Start.X >= b.Start.X {
r.Start.X = s.Start.X
} else {
r.Start.X = b.Start.X
}
if s.End.X <= b.End.X {
r.End.X = s.End.X
} else {
r.End.X = b.End.X
}
if r.End.X < r.Start.X {
exist = false
return
}
if s.Start.Y >= b.Start.Y {
r.Start.Y = s.Start.Y
} else {
r.Start.Y = b.Start.Y
}
if s.End.Y <= b.End.Y {
r.End.Y = s.End.Y
} else {
r.End.Y = b.End.Y
}
if r.End.Y < r.Start.Y {
exist = false
return
}
if s.Start.Z >= b.Start.Z {
r.Start.Z = s.Start.Z
} else {
r.Start.Z = b.Start.Z
}
if s.End.Z <= b.End.Z {
r.End.Z = s.End.Z
} else {
r.End.Z = b.End.Z
}
if r.End.Z < r.Start.Z {
exist = false
return
}
return
}