Added function to calculate a next pointer step on the field

This commit is contained in:
Julien Dessaux 2021-09-17 00:45:07 +02:00
parent 7458dd8aa8
commit 2ba8d90815
2 changed files with 95 additions and 0 deletions

20
pkg/field/step.go Normal file
View file

@ -0,0 +1,20 @@
package field
func (f Field) Step(x, y, dx, dy int) (int, int) {
x2, y2 := x+dx, y+dy
if f.IsIn(x2, y2) {
return x2, y2
}
// We are stepping outside, we need to wrap the Lahey-space
for {
x2, y2 := x-dx, y-dy
if !f.IsIn(x2, y2) {
return x, y
}
x, y = x2, y2
}
}
func (f Field) IsIn(x, y int) bool {
return x >= f.x && x < f.x+f.lx && y >= f.y && y < f.y+f.ly
}