Skip to content

Commit

Permalink
Merge pull request #9 from s0rg/release/v1.4.0
Browse files Browse the repository at this point in the history
migrated to github.com/zyedidia/generic/heap, pathfinding improved. g…
  • Loading branch information
s0rg authored Aug 17, 2023
2 parents e9d7a02 + e1415a1 commit 13cbded
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
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.

0 comments on commit 13cbded

Please sign in to comment.