Skip to content

Commit

Permalink
Use 2D hyperrectangles
Browse files Browse the repository at this point in the history
  • Loading branch information
minkezhang committed Jan 26, 2023
1 parent 956e82a commit d6b92d0
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 28 deletions.
8 changes: 3 additions & 5 deletions boids/boids.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import (
"github.com/downflux/go-database/database"
"github.com/downflux/go-database/database/cache"
"github.com/downflux/go-database/feature"
"github.com/downflux/go-geometry/2d/hyperrectangle"
"github.com/downflux/go-geometry/2d/vector"
"github.com/downflux/go-geometry/nd/hyperrectangle"

vnd "github.com/downflux/go-geometry/nd/vector"
)

var (
Expand Down Expand Up @@ -127,11 +125,11 @@ func (b *B) cache(a agent.RO, rs ...float64) database.RO {

p := a.Position()
aabb := hyperrectangle.New(
vnd.V{
vector.V{
p.X() - r,
p.Y() - r,
},
vnd.V{
vector.V{
p.X() + r,
p.Y() + r,
},
Expand Down
13 changes: 5 additions & 8 deletions boids/boids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/downflux/go-database/feature"
"github.com/downflux/go-database/flags/move"
"github.com/downflux/go-database/flags/size"
"github.com/downflux/go-geometry/2d/hyperrectangle"
"github.com/downflux/go-geometry/2d/vector"
"github.com/downflux/go-geometry/2d/vector/polar"
)
Expand Down Expand Up @@ -88,23 +89,19 @@ func BenchmarkTick(b *testing.B) {
// Add world borders.
// Add xmin border.
db.InsertFeature(feature.O{
Min: vector.V{min - 1, min - 1},
Max: vector.V{min, max + 1},
AABB: *hyperrectangle.New(vector.V{min - 1, min - 1}, vector.V{min, max + 1}),
})
// Add xmax border.
db.InsertFeature(feature.O{
Min: vector.V{max, min - 1},
Max: vector.V{max + 1, max + 1},
AABB: *hyperrectangle.New(vector.V{max, min - 1}, vector.V{max + 1, max + 1}),
})
// Add ymin border.
db.InsertFeature(feature.O{
Min: vector.V{min, min - 1},
Max: vector.V{max, min},
AABB: *hyperrectangle.New(vector.V{min, min - 1}, vector.V{max, min}),
})
// Add ymax border.
db.InsertFeature(feature.O{
Min: vector.V{min, max},
Max: vector.V{max, max + 1},
AABB: *hyperrectangle.New(vector.V{min, max}, vector.V{max, max + 1}),
})

b.StartTimer()
Expand Down
6 changes: 2 additions & 4 deletions constraint/contrib/alignment/alignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/downflux/go-database/database"
"github.com/downflux/go-database/filters"
"github.com/downflux/go-database/flags/move"
"github.com/downflux/go-geometry/2d/hyperrectangle"
"github.com/downflux/go-geometry/2d/vector"
"github.com/downflux/go-geometry/nd/hyperrectangle"

vnd "github.com/downflux/go-geometry/nd/vector"
)

func Align(db database.RO, r float64) constraint.Steer {
Expand All @@ -22,7 +20,7 @@ func Align(db database.RO, r float64) constraint.Steer {

x, y := a.Position().X(), a.Position().Y()
aabb := *hyperrectangle.New(
vnd.V{x - r, y - r}, vnd.V{x + r, y + r},
vector.V{x - r, y - r}, vector.V{x + r, y + r},
)

obstacles := db.QueryAgents(aabb, func(b agent.RO) bool {
Expand Down
5 changes: 2 additions & 3 deletions constraint/contrib/avoidance/avoidance.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (
"github.com/downflux/go-database/feature"
"github.com/downflux/go-database/filters"
"github.com/downflux/go-database/flags/move"
"github.com/downflux/go-geometry/2d/hyperrectangle"
"github.com/downflux/go-geometry/2d/vector"
"github.com/downflux/go-geometry/nd/hyperrectangle"

dhr "github.com/downflux/go-database/geometry/hyperrectangle"
vnd "github.com/downflux/go-geometry/nd/vector"
)

func Avoid(db database.RO, r float64) constraint.Steer {
Expand All @@ -26,7 +25,7 @@ func Avoid(db database.RO, r float64) constraint.Steer {
x, y := a.Position().X(), a.Position().Y()
// Check for collision in the upcoming window.
aabb := *hyperrectangle.New(
vnd.V{x - r, y - r}, vnd.V{x + r, y + r},
vector.V{x - r, y - r}, vector.V{x + r, y + r},
)

// Use a clamping function to ensure some amount of action will
Expand Down
6 changes: 2 additions & 4 deletions constraint/contrib/separation/separation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import (
"github.com/downflux/go-database/database"
"github.com/downflux/go-database/filters"
"github.com/downflux/go-database/flags/move"
"github.com/downflux/go-geometry/2d/hyperrectangle"
"github.com/downflux/go-geometry/2d/vector"
"github.com/downflux/go-geometry/nd/hyperrectangle"

vnd "github.com/downflux/go-geometry/nd/vector"
)

func Separation(db database.RO, r float64) constraint.Steer {
Expand All @@ -21,7 +19,7 @@ func Separation(db database.RO, r float64) constraint.Steer {

x, y := a.Position().X(), a.Position().Y()
aabb := *hyperrectangle.New(
vnd.V{x - r, y - r}, vnd.V{x + r, y + r},
vector.V{x - r, y - r}, vector.V{x + r, y + r},
)

obstacles := db.QueryAgents(aabb, func(b agent.RO) bool {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/downflux/go-boids
go 1.19

require (
github.com/downflux/go-database v0.4.0
github.com/downflux/go-geometry v0.15.4
github.com/downflux/go-database v0.4.1
github.com/downflux/go-geometry v0.16.0
)

require (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ github.com/downflux/go-database v0.3.12 h1:coclMrXPFfvaZXERscdz2jl2arna5xOzIQGZh
github.com/downflux/go-database v0.3.12/go.mod h1:GgparhC7kkqx5VPbyFjE8/zA7o2F/E8P8SR/GwXNs+s=
github.com/downflux/go-database v0.4.0 h1:hQEW46uotxsagUFToqySFSLuAv+KkRIDF/SonQcoM4A=
github.com/downflux/go-database v0.4.0/go.mod h1:GgparhC7kkqx5VPbyFjE8/zA7o2F/E8P8SR/GwXNs+s=
github.com/downflux/go-database v0.4.1 h1:c9/8dCyAuHxYvG4XqM7NOVTe6yTmkykyKeWKH9itPYw=
github.com/downflux/go-database v0.4.1/go.mod h1:cS6YOSUssizKhZhgLzdtyFt7ztbF16mhVUm/9ZkKy4U=
github.com/downflux/go-geometry v0.15.4 h1:COO+vw9M0fEoBIYrR1tY4nzWhnDNAnW1xIcf3TYKqJg=
github.com/downflux/go-geometry v0.15.4/go.mod h1:ZJcto0QwYRdoIbi5G4mh5y6v2xUS+d++/cANaO1F9+8=
github.com/downflux/go-geometry v0.16.0 h1:OivDmtwVTUFCA74D9rlnyzsH3YotVEnl30g9wMdFn+Q=
github.com/downflux/go-geometry v0.16.0/go.mod h1:ZJcto0QwYRdoIbi5G4mh5y6v2xUS+d++/cANaO1F9+8=
github.com/downflux/go-pq v0.3.0 h1:oWLx7rzsD4fv1f2kp33NUq63CJVQvXZORkcpHr6bp9g=
github.com/downflux/go-pq v0.3.0/go.mod h1:vkc6UAQ+TBoNdTwDm5akDexE1auN2kQcR8BFw3hNCiM=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
4 changes: 2 additions & 2 deletions internal/perf/perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/downflux/go-database/agent"
"github.com/downflux/go-database/feature"
"github.com/downflux/go-database/flags/move"
"github.com/downflux/go-geometry/2d/hyperrectangle"
"github.com/downflux/go-geometry/2d/vector"

magent "github.com/downflux/go-database/agent/mock"
Expand Down Expand Up @@ -65,8 +66,7 @@ func BenchmarkSteer(b *testing.B) {
{
name: "Avoidance/SLSDOFeature",
s: avoidance.SLSDOFeature(mfeature.New(0, feature.O{
Min: vector.V{10, 10},
Max: vector.V{100, 100},
AABB: *hyperrectangle.New(vector.V{10, 10}, vector.V{100, 100}),
})),
},
}
Expand Down

0 comments on commit d6b92d0

Please sign in to comment.