{"id":19326649,"url":"https://github.com/miloyip/line","last_synced_at":"2025-04-22T20:32:55.147Z","repository":{"id":54308287,"uuid":"108725148","full_name":"miloyip/line","owner":"miloyip","description":"2D Line Drawing Samples in C","archived":false,"fork":false,"pushed_at":"2022-01-08T13:07:50.000Z","size":792,"stargazers_count":201,"open_issues_count":1,"forks_count":34,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-02T04:02:31.769Z","etag":null,"topics":["graphics-programming","graphics2d","rendering-2d-graphics"],"latest_commit_sha":null,"homepage":null,"language":"C","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/miloyip.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}},"created_at":"2017-10-29T10:37:48.000Z","updated_at":"2025-03-07T01:42:17.000Z","dependencies_parsed_at":"2022-08-13T11:40:14.282Z","dependency_job_id":null,"html_url":"https://github.com/miloyip/line","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/miloyip%2Fline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miloyip%2Fline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miloyip%2Fline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miloyip%2Fline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miloyip","download_url":"https://codeload.github.com/miloyip/line/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250318986,"owners_count":21411028,"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":["graphics-programming","graphics2d","rendering-2d-graphics"],"created_at":"2024-11-10T02:14:25.044Z","updated_at":"2025-04-22T20:32:54.738Z","avatar_url":"https://github.com/miloyip.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 2D Line Drawing Samples\n\nThis project contains C source code for drawing 2D lines by different techniques.\n\nAll samples output PNGs with [svpng](https://github.com/miloyip/svpng).\n\nLicense: public domain.\n\n## Bresenham\n\nThe fundamental line drawing algorithm by Bresenham [1], based on [rosetta code](https://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#C).\n\n![line_bresenham.c](line_bresenham.c)\n\n![ ](line_bresenham.png)\n![ ](line_bresenham_zoom.png)\n\n## Sampling\n\nRepresent lines as capsule shapes, in order to support real-valued coordinates and variable width.\n\n![line_sampling.c](line_sampling.c)\n\n![ ](line_sampling.png)\n![ ](line_sampling_zoom.png)\n\n## Anti-aliasing by super sampling\n\nSimple anti-aliasing with 5x5 super sampling.\n\n![line_supersampling.c](line_supersampling.c)\n\n![ ](line_supersampling.png)\n![ ](line_supersampling_zoom.png)\n\n## Anti-aliasing by signed distnace field\n\nUsing signed distnace field (SDF) of capsule shape to perform anti-aliasing with single sample per pixel.\n\n![line_sdf.c](line_sdf.c)\n\n![ ](line_sdf.png)\n![ ](line_sdf_zoom.png)\n\n## SDF optimization with AABB\n\nUse AABB of capsule to reduce the number of samples. Render shapes into the buffer individually with alpha blending.\n\n![line_sdfaabb.c](line_sdfaabb.c)\n\n![ ](line_sdfaabb.png)\n![ ](line_sdfaabb_zoom.png)\n\n## Visual comparison\n\n![ ](line_montage_zoom.png)\n\n## Performance comparison\n\n~~~\n$ make test\ngcc -Wall -O3 -o line_bresenham line_bresenham.c\ngcc -Wall -O3 -o line_sampling line_sampling.c\ngcc -Wall -O3 -o line_supersampling line_supersampling.c\ngcc -Wall -O3 -o line_sdf line_sdf.c\ngcc -Wall -O3 -o line_sdfaabb line_sdfaabb.c\ntime ./line_bresenham\n        0.03 real         0.02 user         0.00 sys\ntime ./line_sampling\n        1.93 real         1.91 user         0.00 sys\ntime ./line_supersampling\n       47.06 real        46.85 user         0.10 sys\ntime ./line_sdf\n        2.00 real         1.98 user         0.00 sys\ntime ./line_sdfaabb\n        0.03 real         0.03 user         0.00 sys\n~~~\n\n## Final notes\n\n1. These samples are only for illustrative purposes.\n2. Line clipping are not performed.\n3. The SDF AABB sample can be further optimized by tigther quaduraliteral bounds.\n\n## References\n\n[1] Bresenham, Jack E. \"Algorithm for computer control of a digital plotter.\" IBM Systems journal 4.1 (1965): 25-30.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiloyip%2Fline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiloyip%2Fline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiloyip%2Fline/lists"}