test dw distances
This commit is contained in:
@@ -2,6 +2,7 @@ package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
|
||||
"github.com/iliadenisov/galaxy/pkg/generator/plotter"
|
||||
@@ -67,6 +68,18 @@ func (m Map) NewCoordinate(deadZoneRaduis float64) (Coordinate, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m Map) ShortDistance(from, to Coordinate) float64 {
|
||||
dx := math.Abs(to.X - from.X)
|
||||
dy := math.Abs(to.Y - from.Y)
|
||||
if dx > float64(m.Width/2) {
|
||||
dx = float64(m.Width) - dx
|
||||
}
|
||||
if dy > float64(m.Height/2) {
|
||||
dy = float64(m.Height) - dy
|
||||
}
|
||||
return math.Sqrt(math.Pow(dx, 2) + math.Pow(dy, 2))
|
||||
}
|
||||
|
||||
func NewPlanet(c Coordinate, size, resources float64) Planet {
|
||||
return Planet{
|
||||
Position: c,
|
||||
|
||||
Reference in New Issue
Block a user