mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
packing: Refactoring
This commit is contained in:
parent
7e70d5ca69
commit
951568e403
@ -79,7 +79,7 @@ func square(width, height int) float64 {
|
|||||||
return float64(height) / float64(width)
|
return float64(height) / float64(width)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) alloc(width, height int) *Node {
|
func (p *Page) alloc(n *Node, width, height int) *Node {
|
||||||
if n.width < width || n.height < height {
|
if n.width < width || n.height < height {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -124,15 +124,15 @@ func (n *Node) alloc(width, height int) *Node {
|
|||||||
parent: n,
|
parent: n,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return n.child0.alloc(width, height)
|
return p.alloc(n.child0, width, height)
|
||||||
}
|
}
|
||||||
if n.child0 == nil || n.child1 == nil {
|
if n.child0 == nil || n.child1 == nil {
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
if node := n.child0.alloc(width, height); node != nil {
|
if node := p.alloc(n.child0, width, height); node != nil {
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
if node := n.child1.alloc(width, height); node != nil {
|
if node := p.alloc(n.child1, width, height); node != nil {
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -155,7 +155,7 @@ func (p *Page) Alloc(width, height int) *Node {
|
|||||||
if height < minSize {
|
if height < minSize {
|
||||||
height = minSize
|
height = minSize
|
||||||
}
|
}
|
||||||
n := p.root.alloc(width, height)
|
n := p.alloc(p.root, width, height)
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user