{"id":20761689,"url":"https://github.com/s0rg/grid","last_synced_at":"2025-09-11T05:40:34.647Z","repository":{"id":64300162,"uuid":"570609529","full_name":"s0rg/grid","owner":"s0rg","description":"Generic 2D grid","archived":false,"fork":false,"pushed_at":"2025-08-15T15:17:25.000Z","size":44,"stargazers_count":22,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-16T09:35:42.730Z","etag":null,"topics":["2d-game-library","astar-algorithm","bresenham-algorithm","dda-algorithm","dejkstra","generic","golang","golang-package","roguelike-library","shadowcasting"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s0rg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-11-25T15:55:49.000Z","updated_at":"2025-07-24T13:57:55.000Z","dependencies_parsed_at":"2023-12-13T00:35:28.986Z","dependency_job_id":"d5301599-5236-43cd-8559-52316b797ee8","html_url":"https://github.com/s0rg/grid","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/s0rg/grid","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0rg%2Fgrid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0rg%2Fgrid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0rg%2Fgrid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0rg%2Fgrid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s0rg","download_url":"https://codeload.github.com/s0rg/grid/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0rg%2Fgrid/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274583899,"owners_count":25311899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-game-library","astar-algorithm","bresenham-algorithm","dda-algorithm","dejkstra","generic","golang","golang-package","roguelike-library","shadowcasting"],"created_at":"2024-11-17T10:25:16.890Z","updated_at":"2025-09-11T05:40:34.629Z","avatar_url":"https://github.com/s0rg.png","language":"Go","readme":"[![PkgGoDev](https://pkg.go.dev/badge/github.com/s0rg/grid)](https://pkg.go.dev/github.com/s0rg/grid)\n[![License](https://img.shields.io/github/license/s0rg/grid)](https://github.com/s0rg/grid/blob/master/LICENSE)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/s0rg/grid)](go.mod)\n[![Tag](https://img.shields.io/github/v/tag/s0rg/grid?sort=semver)](https://github.com/s0rg/grid/tags)\n\n[![CI](https://github.com/s0rg/grid/workflows/ci/badge.svg)](https://github.com/s0rg/grid/actions?query=workflow%3Aci)\n[![Go Report Card](https://goreportcard.com/badge/github.com/s0rg/grid)](https://goreportcard.com/report/github.com/s0rg/grid)\n[![Maintainability](https://qlty.sh/badges/2683df5e-28a8-4d8d-87da-295f252742d4/maintainability.svg)](https://qlty.sh/gh/s0rg/projects/grid)\n[![Code Coverage](https://qlty.sh/badges/2683df5e-28a8-4d8d-87da-295f252742d4/test_coverage.svg)](https://qlty.sh/gh/s0rg/projects/grid)\n![Issues](https://img.shields.io/github/issues/s0rg/grid)\n\n# grid\n\nGeneric 2D grid\n\n# features\n\n- [DDA RayCasting](https://lodev.org/cgtutor/raycasting.html)\n- [A-Star pathfinding](https://en.wikipedia.org/wiki/A*_search_algorithm)\n- [Ray-based line of sight](https://en.wikipedia.org/wiki/Line_of_sight_(video_games))\n- [Recursive ShadowCasting](http://www.roguebasin.com/index.php/Shadow_casting)\n- [Dijkstra maps](http://www.roguebasin.com/index.php/Dijkstra_Maps_Visualized)\n- [Bresenham's lines](https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm)\n- 100% test cover\n\n# usage\n\n```go\nimport (\n    \"image\"\n\n    \"github.com/s0rg/grid\"\n)\n\nconst mapW, mapH = 100, 100\n\nfunc valueExample() {\n    // working with value-types is straightforward\n    g := grid.New[int](image.Rect(0, 0, mapW, mapH))\n\n    // now grid is filled with nil-value for your type\n    // you still can re-fill it with some other values:\n    g.Fill(func() int {\n        return 1\n    })\n}\n\nfunc pointerExample() {\n    // working with pointer-types is same, but you now you must to pre-fill them\n    type mycell struct {}\n\n    g := grid.New[*mycell](image.Rect(0, 0, mapW, mapH))\n\n    // now grid is filled with nil's, so you need pre-fill it with some values,\n    // otherwise you will access those nil's with Get / MustGet methods.\n    g.Fill(func() *mycell {\n        return \u0026mycell{}\n    })\n}\n\nfunc usageExample() {\n    type mycell struct {\n        wall bool\n    }\n\n    g := grid.New[*mycell](image.Rect(0, 0, mapW, mapH))\n\n    g.Fill(func() *mycell {\n        return \u0026mycell{}\n    })\n\n    pt := image.Pt(10, 10)\n\n    // set new value\n    g.Set(pt, \u0026mycell{wall: true})\n\n    // update existing value\n    if v, ok := g.Get(pt); ok {\n        v.wall = false\n    }\n\n    // shorthand, for above, will panic on out-of-bounds access\n    g.MustGet(pt).wall = true\n\n    // iterate items\n    g.Iter(func(p image.Point, c *mycell) (next bool) {\n        if c.wall {\n            // wall found\n        }\n\n        return true\n    })\n}\n```\n\n# example\n\n[Here](https://github.com/s0rg/grid/blob/master/_example/main.go) is a full example.\n\nYou can run it with `go run _example/main.go` to see results.\n\n# benchmarks\n\nrun:\n\n```bash\nmake bench\n```\n\nresults:\n\n```\ngoos: linux\ngoarch: amd64\npkg: github.com/s0rg/grid\ncpu: AMD Ryzen 5 5500U with Radeon Graphics\nBenchmarkGrid/Set-12         \t1000000000\t        0.8108 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkGrid/Get-12         \t641611768\t        1.764 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkGrid/Neighbours-12  \t52243890\t       23.41 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkGrid/LineBresenham-12         \t4416172\t      269.0 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkGrid/CastRay-12               \t3829839\t      321.1 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkGrid/CastShadow-12            \t  32648\t    36950 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkGrid/LineOfSight-12           \t   9897\t   114576 ns/op\t      0 B/op\t      0 allocs/op\nBenchmarkGrid/DijkstraMap-12           \t   1029\t  1190195 ns/op\t  20656 B/op\t      3 allocs/op\nBenchmarkGrid/Path-12                  \t    372\t  3225325 ns/op\t 997588 B/op\t  13643 allocs/op\nPASS\nok  \tgithub.com/s0rg/grid\t12.098s\n```\n","funding_links":[],"categories":["Game Development","游戏开发"],"sub_categories":["Search and Analytic Databases","检索及分析资料库"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs0rg%2Fgrid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs0rg%2Fgrid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs0rg%2Fgrid/lists"}