Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrated to github.com/zyedidia/generic/heap, pathfinding improved. g… #9

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ goos: linux
goarch: amd64
pkg: github.com/s0rg/grid
cpu: AMD Ryzen 5 5500U with Radeon Graphics
BenchmarkGrid/Set-12 1000000000 1.022 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/Get-12 721531257 1.634 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/Neighbours-12 66094719 18.29 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/LineBresenham-12 5609686 215.2 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/CastRay-12 4111668 283.9 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/CastShadow-12 34016 34912 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/LineOfSight-12 11792 100790 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/DijkstraMap-12 1054 1094518 ns/op 20656 B/op 3 allocs/op
BenchmarkGrid/Path-12 120 10212821 ns/op 14209590 B/op 40388 allocs/op
BenchmarkGrid/Set-12 1000000000 0.8379 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/Get-12 781486358 1.521 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/Neighbours-12 61203862 19.25 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/LineBresenham-12 5331663 223.9 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/CastRay-12 4160371 287.7 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/CastShadow-12 33894 34771 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/LineOfSight-12 11482 104325 ns/op 0 B/op 0 allocs/op
BenchmarkGrid/DijkstraMap-12 1011 1105615 ns/op 20656 B/op 3 allocs/op
BenchmarkGrid/Path-12 166 7458693 ns/op 13347421 B/op 13643 allocs/op
```
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module github.com/s0rg/grid

go 1.20
go 1.21

require (
github.com/s0rg/array2d v1.1.1
github.com/s0rg/set v1.0.1
github.com/s0rg/vec2d v1.1.1
github.com/zyedidia/generic v1.2.1
)

require golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b // indirect
require (
github.com/segmentio/fasthash v1.0.3 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ github.com/s0rg/set v1.0.1 h1:eJ2KSRUwnIZOBtlQScgET80+jkm/ro01pn6YeZzgWp4=
github.com/s0rg/set v1.0.1/go.mod h1:aBGSm+F2mCTDjNIRR4GMB04NMqZBhtSh0tOBe/u5z5k=
github.com/s0rg/vec2d v1.1.1 h1:asdV+Iev4M5lcFwB46883k8oLku4JgNQHyI/4SHAtMo=
github.com/s0rg/vec2d v1.1.1/go.mod h1:/0pgb+2ax3mWfBZ1gb9LMMFawvmGyWpgCjk8a/ImCgg=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
github.com/segmentio/fasthash v1.0.3 h1:EI9+KE1EwvMLBWwjpRDc+fEM+prwxDYbslddQGtrmhM=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/zyedidia/generic v1.2.1 h1:Zv5KS/N2m0XZZiuLS82qheRG4X1o5gsWreGb0hR7XDc=
github.com/zyedidia/generic v1.2.1/go.mod h1:ly2RBz4mnz1yeuVbQA/VFwGjK3mnHGRj1JuoG336Bis=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
16 changes: 9 additions & 7 deletions grid.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package grid

import (
"container/heap"
"image"
"math"

"github.com/s0rg/array2d"
"github.com/s0rg/set"
"github.com/s0rg/vec2d"
"github.com/zyedidia/generic/heap"
)

const one = 1.0
Expand Down Expand Up @@ -131,16 +131,18 @@ func (m *Map[T]) Path(

var (
road path
queue pqueue
last image.Point
closed = make(set.Set[image.Point])
)

heap.Init(&queue)
heap.Push(&queue, road.Fork(src, tdist))
queue := heap.New[path](func(a, b path) bool {
return a.Cost < b.Cost
})

queue.Push(road.Fork(src, tdist))

for queue.Len() > 0 {
road = heap.Pop(&queue).(path)
for queue.Size() > 0 {
road, _ = queue.Pop()
last = road.Last()

if !closed.TryAdd(last) {
Expand All @@ -155,7 +157,7 @@ func (m *Map[T]) Path(
var ncost float64

if ncost, ok = cost(p, dist(dst, p), t); ok {
heap.Push(&queue, road.Fork(p, ncost))
queue.Push(road.Fork(p, ncost))
}

return true
Expand Down
14 changes: 0 additions & 14 deletions pqueue.go

This file was deleted.