package placementcost
import (
"math"
"github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph"
)
type obstructionBounds struct {
left, top, right, bottom float64
usable bool
}
func scoringNodeBounds(node *layoutgraph .Node ) obstructionBounds {
if node == nil || node .TopLeft == nil {
return obstructionBounds {}
}
x , y := node .TopLeft .X , node .TopLeft .Y
right , bottom := x +node .Width , y +node .Height
const bound = math .MaxFloat64 / 8
usable := x >= -bound && x <= bound && y >= -bound && y <= bound &&
right >= -bound && right <= bound && bottom >= -bound && bottom <= bound
return obstructionBounds {min (x , right ), min (y , bottom ), max (x , right ), max (y , bottom ), usable }
}
func (bounds obstructionBounds ) including (other obstructionBounds ) obstructionBounds {
return obstructionBounds {
min (bounds .left , other .left ), min (bounds .top , other .top ),
max (bounds .right , other .right ), max (bounds .bottom , other .bottom ),
bounds .usable && other .usable ,
}
}
func (bounds obstructionBounds ) excludes (node *layoutgraph .Node ) bool {
if !bounds .usable || node == nil || node .TopLeft == nil {
return false
}
x , y := node .TopLeft .X , node .TopLeft .Y
right , bottom := x +node .Width , y +node .Height
if math .IsInf (x , 0 ) || math .IsInf (y , 0 ) || math .IsInf (right , 0 ) || math .IsInf (bottom , 0 ) ||
math .IsNaN (x ) || math .IsNaN (y ) || math .IsNaN (right ) || math .IsNaN (bottom ) {
return false
}
return (x < bounds .left && right < bounds .left ) ||
(x > bounds .right && right > bounds .right ) ||
(y < bounds .top && bottom < bounds .top ) ||
(y > bounds .bottom && bottom > bounds .bottom )
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .