Skip to content

Commit

Permalink
Fix collider benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
minkezhang committed Dec 28, 2022
1 parent ca38196 commit 9252e9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion collider/collider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (c *C) InsertFeature(o feature.O) *feature.F {
f := feature.New(o)
feature.SetID(f, x)

c.features[x] = f
if err := c.bvhFeatures.Insert(x, f.AABB()); err != nil {
panic(fmt.Sprintf("cannot insert feature: %v", err))
}
Expand Down Expand Up @@ -166,7 +167,6 @@ func (c *C) queryFeatures(q hyperrectangle.R, filter func(f *feature.F) bool) []
collisions = append(collisions, x)
}
}

return collisions
}

Expand Down
23 changes: 23 additions & 0 deletions collider/collider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,29 @@ func BenchmarkTick(b *testing.B) {
Mask: mask.MSizeSmall,
})
}

// Add world borders.
// Add xmin border.
collider.InsertFeature(feature.O{
Min: vector.V{-1, -1},
Max: vector.V{0, max + 1},
})
// Add xmax border.
collider.InsertFeature(feature.O{
Min: vector.V{max, -1},
Max: vector.V{max + 1, max + 1},
})
// Add ymin border.
collider.InsertFeature(feature.O{
Min: vector.V{0, -1},
Max: vector.V{max, 0},
})
// Add ymax border.
collider.InsertFeature(feature.O{
Min: vector.V{0, max},
Max: vector.V{max, max + 1},
})

b.StartTimer()
for i := 0; i < b.N; i++ {
collider.Tick(33 * time.Millisecond)
Expand Down

0 comments on commit 9252e9a

Please sign in to comment.