{"id":17010978,"url":"https://github.com/rm-code/bresenham","last_synced_at":"2025-10-24T13:06:53.349Z","repository":{"id":92811606,"uuid":"69345110","full_name":"rm-code/bresenham","owner":"rm-code","description":"Bresenham's line algorithm written in Lua.","archived":false,"fork":false,"pushed_at":"2017-03-23T10:58:26.000Z","size":7,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T03:33:22.434Z","etag":null,"topics":["bresenham","lua"],"latest_commit_sha":null,"homepage":null,"language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rm-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-09-27T10:23:13.000Z","updated_at":"2025-02-02T10:42:05.000Z","dependencies_parsed_at":"2023-03-05T23:30:21.685Z","dependency_job_id":null,"html_url":"https://github.com/rm-code/bresenham","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-code%2Fbresenham","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-code%2Fbresenham/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-code%2Fbresenham/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rm-code%2Fbresenham/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rm-code","download_url":"https://codeload.github.com/rm-code/bresenham/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248539821,"owners_count":21121239,"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","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":["bresenham","lua"],"created_at":"2024-10-14T06:05:55.973Z","updated_at":"2025-10-24T13:06:48.331Z","avatar_url":"https://github.com/rm-code.png","language":"Lua","readme":"# Bresenham\nBresenham's line algorithm written in Lua.\n\n## Overview\n\n#### Arguments\nThe `Bresenham.line` function expects the following arguments:\n- __ox (number)__ The origin's x-coordinates. The line will start here.\n- __oy (number)__ The origin's y-coordinates. The line will start here.\n- __tx (number)__ The target's x-coordinates. The line will end here.\n- __ty (number)__ The target's y-coordinates. The line will end here.\n- __callback (function)__ A callback function being called for every tile the line passes. The line algorithm will stop if the callback returns false __(optional)__.\n- __... (varargs)__ Additional variables that should be passed to the callback function __(optional)__.\n\n#### Return values\n- __(boolean)__ True if the line has reached its target, false if it stopped early.\n- __(number)__ The number of tiles traversed by the line.\n\n## Usage\n\nIf you don't provide a callback function the line algorithm will always return `true` and can be used to count distances on the grid:\n\n```Lua\nlocal _, counter = Bresenham.line( 1, 1, 7, 7 )\n```\n\n\nBy providing a callback you can control how the line algorithm behaves on the grid. For example you could tell it to stop early if it hits certain tiles, objects, monsters and so on ...\n\n```lua\nlocal function callback( x, y, counter, ... )\n    -- Unpack the varargs passed after the callback.\n    local vararg1, vararg2 = ...;\n\n    -- Check if the line algorithm should stop early.\n    if not grid[x][y]:isPassable() then\n        return false\n    end\n    return true\nend\n\nBresenham.line( 1, 1, 10, 10, callback, 'foo', 'bar' )\n```\n\nComplete example:\n```Lua\nlocal Bresenham = require( 'Bresenham' )\n\nlocal grid = {\n    { '#', '#', '#', '#', '#', '#', '#', '#' },\n    { '#', '.', '.', '.', '.', '.', '.', '#' },\n    { '#', '.', '.', '.', '.', '.', '.', '#' },\n    { '#', '.', '.', '#', '#', '.', '.', '#' },\n    { '#', '.', '.', '#', '#', '.', '.', '#' },\n    { '#', '.', '.', '.', '.', '.', '.', '#' },\n    { '#', '.', '.', '.', '.', '.', '.', '#' },\n    { '#', '#', '#', '#', '#', '#', '#', '#' }\n}\n\nprint( 'Traverse grid if no obstacles are hit:' )\nlocal success, counter = Bresenham.line( 2, 2, 6, 2, function( x, y, counter )\n    print( string.format( 'x: %d, y: %d, steps: %d, tile: %s', x, y, counter, grid[x][y] ))\n    if grid[x][y] == '#' then\n        return false\n    end\n    return true\nend)\nprint( string.format( 'Reached target: %s after %d steps.\\n', tostring( success ), counter ))\n\nprint( 'Stop line early if obstacles are hit:' )\nlocal success, counter = Bresenham.line( 2, 2, 6, 6, function( x, y, counter )\n    print( string.format( 'x: %d, y: %d, steps: %d, tile: %s', x, y, counter, grid[x][y] ))\n    if grid[x][y] == '#' then\n        return false\n    end\n    return true\nend)\nprint( string.format( 'Reached target: %s after %d steps.\\n', tostring( success ), counter ))\n\nprint( 'Without a callback just count the steps from start to finish:' )\nlocal _, counter = Bresenham.line( 1, 1, 7, 7 )\nprint( counter )\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-code%2Fbresenham","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frm-code%2Fbresenham","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frm-code%2Fbresenham/lists"}