minor cleanups
This commit is contained in:
parent
f1adaead81
commit
a9d6c8827f
2 changed files with 18 additions and 10 deletions
|
@ -131,15 +131,18 @@ func (d *DrawDAG) Update() error {
|
||||||
func (d *DrawDAG) Add(x DrawBoxer) {
|
func (d *DrawDAG) Add(x DrawBoxer) {
|
||||||
πsign := d.proj.Sign()
|
πsign := d.proj.Sign()
|
||||||
|
|
||||||
|
// Ensure vertex is present
|
||||||
|
d.dag.addVertex(x)
|
||||||
|
|
||||||
// Update the box cache
|
// Update the box cache
|
||||||
bb := x.BoundingBox()
|
xb := x.BoundingBox()
|
||||||
d.boxCache[x] = bb
|
d.boxCache[x] = xb
|
||||||
|
|
||||||
// Update the reverse chunk map
|
// Update the reverse chunk map
|
||||||
br := bb.BoundingRect(d.proj)
|
xbr := xb.BoundingRect(d.proj)
|
||||||
revr := image.Rectangle{
|
revr := image.Rectangle{
|
||||||
Min: br.Min.Div(d.ChunkSize),
|
Min: xbr.Min.Div(d.ChunkSize),
|
||||||
Max: br.Max.Sub(image.Pt(1, 1)).Div(d.ChunkSize),
|
Max: xbr.Max.Sub(image.Pt(1, 1)).Div(d.ChunkSize),
|
||||||
}
|
}
|
||||||
d.chunksRev[x] = revr
|
d.chunksRev[x] = revr
|
||||||
|
|
||||||
|
@ -167,14 +170,14 @@ func (d *DrawDAG) Add(x DrawBoxer) {
|
||||||
y := c.(DrawBoxer)
|
y := c.(DrawBoxer)
|
||||||
// Bounding rectangle overlap test
|
// Bounding rectangle overlap test
|
||||||
// No overlap, no edge.
|
// No overlap, no edge.
|
||||||
if ybr := y.BoundingBox().BoundingRect(d.proj); !br.Overlaps(ybr) {
|
if ybr := y.BoundingBox().BoundingRect(d.proj); !xbr.Overlaps(ybr) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case drawOrderConstraint(y, x, πsign):
|
|
||||||
d.dag.addEdge(y, x)
|
|
||||||
case drawOrderConstraint(x, y, πsign):
|
case drawOrderConstraint(x, y, πsign):
|
||||||
d.dag.addEdge(x, y)
|
d.dag.addEdge(x, y)
|
||||||
|
case drawOrderConstraint(y, x, πsign):
|
||||||
|
d.dag.addEdge(y, x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,6 +294,11 @@ func (d *dag) removeEdge(u, v Drawer) {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// addVertex ensures the vertex is present, even if there are no edges.
|
||||||
|
func (d *dag) addVertex(v Drawer) {
|
||||||
|
d.all[v] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
// removeVertex removes all in and out edges associated with v in O(degree(v)).
|
// removeVertex removes all in and out edges associated with v in O(degree(v)).
|
||||||
func (d *dag) removeVertex(v Drawer) {
|
func (d *dag) removeVertex(v Drawer) {
|
||||||
for u := range d.in[v] {
|
for u := range d.in[v] {
|
||||||
|
|
|
@ -20,8 +20,6 @@ func (d *DrawDFS) DrawAll(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DrawDFS) Scan() []interface{} { return d.Components }
|
|
||||||
|
|
||||||
func (d *DrawDFS) draw(component interface{}, screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
func (d *DrawDFS) draw(component interface{}, screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
||||||
// Hidden? stop drawing
|
// Hidden? stop drawing
|
||||||
if h, ok := component.(Hider); ok && h.Hidden() {
|
if h, ok := component.(Hider); ok && h.Hidden() {
|
||||||
|
@ -48,3 +46,5 @@ func (d *DrawDFS) draw(component interface{}, screen *ebiten.Image, opts ebiten.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DrawDFS) Scan() []interface{} { return d.Components }
|
||||||
|
|
Loading…
Reference in a new issue