Skip to content

Commit

Permalink
Refactor collider API
Browse files Browse the repository at this point in the history
  • Loading branch information
minkezhang committed Jan 5, 2023
1 parent 6046e95 commit b7df325
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions collider/collider.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var (
)

type O struct {
DB *database.DB
PoolSize int
}

Expand All @@ -34,12 +33,12 @@ type C struct {
poolSize int
}

func New(o O) *C {
func New(db *database.DB, o O) *C {
if o.PoolSize < 2 {
panic(fmt.Sprintf("PoolSize specified %v is smaller than the minimum value of 2", o.PoolSize))
}
return &C{
db: o.DB,
db: db,
poolSize: o.PoolSize,
}
}
Expand Down
12 changes: 6 additions & 6 deletions collider/collider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestTick(t *testing.T) {
configs := []config{
func() config {
db := database.New(database.DefaultO)
collider := New(O{DB: db, PoolSize: DefaultO.PoolSize})
collider := New(db, O{PoolSize: DefaultO.PoolSize})
a := db.InsertAgent(agent.O{
Position: vector.V{0, 0},
TargetVelocity: vector.V{1, 1},
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestTick(t *testing.T) {
}(),
func() config {
db := database.New(database.DefaultO)
collider := New(O{DB: db, PoolSize: DefaultO.PoolSize})
collider := New(db, DefaultO)
a := db.InsertAgent(agent.O{
Position: vector.V{10, 10},
TargetVelocity: vector.V{1, 1},
Expand All @@ -120,7 +120,7 @@ func TestTick(t *testing.T) {
}(),
func() config {
db := database.New(database.DefaultO)
collider := New(O{DB: db, PoolSize: DefaultO.PoolSize})
collider := New(db, DefaultO)
a := db.InsertAgent(agent.O{
Position: vector.V{10, 10},
TargetVelocity: vector.V{0, 1},
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestTick(t *testing.T) {
}(),
func() config {
db := database.New(database.DefaultO)
collider := New(O{DB: db, PoolSize: DefaultO.PoolSize})
collider := New(db, DefaultO)
a := db.InsertAgent(agent.O{
Position: vector.V{10, 10},
TargetVelocity: vector.V{0, 1},
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestTick(t *testing.T) {
}(),
func() config {
db := database.New(database.DefaultO)
collider := New(O{DB: db, PoolSize: DefaultO.PoolSize})
collider := New(db, DefaultO)
a := db.InsertAgent(agent.O{
Position: vector.V{60.0040783686527, 80.40391843262739},
TargetVelocity: vector.V{10, 10},
Expand Down Expand Up @@ -256,7 +256,7 @@ func BenchmarkTick(b *testing.B) {
max := math.Sqrt(area)

db := database.New(database.DefaultO)
collider := New(O{DB: db, PoolSize: DefaultO.PoolSize})
collider := New(db, DefaultO)
for i := 0; i < c.n; i++ {
db.InsertAgent(agent.O{
Radius: R,
Expand Down

0 comments on commit b7df325

Please sign in to comment.