-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid.go
More file actions
36 lines (32 loc) · 903 Bytes
/
grid.go
File metadata and controls
36 lines (32 loc) · 903 Bytes
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
package main
// intPoint represents an integer coordinate on the simulation grid.
type intPoint struct {
x int
y int
}
// buildLOSPerimeterTargets precomputes the grid edge cells used when casting
// line-of-sight rays.
func buildLOSPerimeterTargets() []intPoint {
points := make([]intPoint, 0, 2*(w+h))
for x := 0; x < w; x++ {
points = append(points, intPoint{x: x, y: 0})
points = append(points, intPoint{x: x, y: h - 1})
}
for y := 1; y < h-1; y++ {
points = append(points, intPoint{x: 0, y: y})
points = append(points, intPoint{x: w - 1, y: y})
}
return points
}
// clampCoord constrains v to lie within the inclusive [min, max] range.
func clampCoord(v, min, max int) int {
if v < min {
return min
}
if v > max {
return max
}
return v
}
// losPerimeterTargets caches the perimeter cells used for visibility checks.
var losPerimeterTargets = buildLOSPerimeterTargets()