filter projectiles and objects by scanners
This commit is contained in:
+12
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
v "bitbucket.org/hackerbots/vector"
|
||||
"math"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
@@ -9,6 +10,17 @@ type Obstacle struct {
|
||||
Bounds v.Rect2d `json:"bounds"`
|
||||
}
|
||||
|
||||
func (o Obstacle) distance_from_point(p v.Point2d) float32 {
|
||||
dist := math.MaxFloat32
|
||||
|
||||
dist = math.Min(dist, float64(p.Sub(o.Bounds.A).Mag()))
|
||||
dist = math.Min(dist, float64(p.Sub(o.Bounds.B).Mag()))
|
||||
dist = math.Min(dist, float64(p.Sub(v.Point2d{o.Bounds.A.X, o.Bounds.B.Y}).Mag()))
|
||||
dist = math.Min(dist, float64(p.Sub(v.Point2d{o.Bounds.B.X, o.Bounds.A.Y}).Mag()))
|
||||
|
||||
return float32(dist)
|
||||
}
|
||||
|
||||
func GenerateObstacles(count int, width, height float32) []Obstacle {
|
||||
out := []Obstacle{}
|
||||
for i := 0; i < count; i++ {
|
||||
|
||||
Reference in New Issue
Block a user