{"id":13828921,"url":"https://github.com/w8r/liang-barsky","last_synced_at":"2025-10-14T17:09:58.998Z","repository":{"id":19896918,"uuid":"88212125","full_name":"w8r/liang-barsky","owner":"w8r","description":"Liang-Barsky line-clipping algorithm","archived":false,"fork":false,"pushed_at":"2025-01-22T06:48:49.000Z","size":2189,"stargazers_count":33,"open_issues_count":6,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-14T17:09:57.708Z","etag":null,"topics":["algorithm","clipping","clipping-algorithm","geometry"],"latest_commit_sha":null,"homepage":"https://w8r.github.io/liang-barsky/","language":"TypeScript","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/w8r.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}},"created_at":"2017-04-13T22:39:54.000Z","updated_at":"2024-09-26T16:31:19.000Z","dependencies_parsed_at":"2025-01-30T23:12:05.858Z","dependency_job_id":"cb1bf07a-b516-4551-a233-1543bbeb2ec0","html_url":"https://github.com/w8r/liang-barsky","commit_stats":{"total_commits":35,"total_committers":2,"mean_commits":17.5,"dds":"0.22857142857142854","last_synced_commit":"f73dd63a6d936e1998be66d3709489e08b774344"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/w8r/liang-barsky","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w8r%2Fliang-barsky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w8r%2Fliang-barsky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w8r%2Fliang-barsky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w8r%2Fliang-barsky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w8r","download_url":"https://codeload.github.com/w8r/liang-barsky/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w8r%2Fliang-barsky/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020085,"owners_count":26086805,"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-10-14T02:00:06.444Z","response_time":60,"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":["algorithm","clipping","clipping-algorithm","geometry"],"created_at":"2024-08-04T09:03:20.408Z","updated_at":"2025-10-14T17:09:58.960Z","avatar_url":"https://github.com/w8r.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Liang-Barsky line-clipping algorithm [![npm](https://badge.fury.io/js/liang-barsky.svg)](https://www.npmjs.com/package/liang-barsky)\n\n![Preview](https://w8r.github.io/liang-barsky/thumbnail.png)\n\nFast, _destructive_ implemetation of [Liang-Barsky line clipping algorithm](https://en.wikipedia.org/wiki/Liang%E2%80%93Barsky_algorithm). It clips a 2D segment by a rectangle.\n\nThis is an adaptation of the [C++ code](http://hinjang.com/articles/04.html#eight)\nthat impressed me by its simplicity.\n\n## API\n\nDestructive\n\n```js\nconst a = [-10, -10],\n  b = [10, 10];\nclip(a, b, [-5, -5, 5, 5]); // returns 1 - \"clipped\"\nconsole.log(a); // [-5, -5]\nconsole.log(b); // [5, 5]\n```\n\nNon-destructive\n\n```js\nconst a = [-10, -10],\n  b = [10, 10];\nconst an = a.slice(),\n  bn = b.slice();\nclip(a, b, [-5, -5, 5, 5], an, bn); // returns 1 - \"clipped\"\nconsole.log(an); // [-5, -5]\nconsole.log(bn); // [5, 5]\nconsole.log(a); // [-10, -10]\nconsole.log(b); // [10, 10]\n```\n\nReturn value is `1` if the line was clipped, and `0` if it lies completely\noutside of the provided bounding box.\n\n## Install\n\n```\nnpm install -S liang-barsky\n```\n\n```js\nimport { clip } from 'liang-barsky';\n// or\nvar clip = require('liang-barsky');\n```\n\nOr just drop-in the file\n\n```html\n\u003cscript src=\"path/to/liang-barsky.umd.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  liangBarsky.clip([0, 0], [10, 10], [0, 0, 5, 5]);\n\u003c/script\u003e\n```\n\n## Performance\n\nI ran a check against the Cohen-Sutherland algorithm implemented by @mourner\nfor clipping just one segment. Though test include memory allocation, they are\nfair for the task at hand, since you can use the results in an equal manner after\nthe invocation of the clipper.\n\n```\nnpm run benchmark\n```\n\n```\nliang-barsky x 112,058,856 ops/sec ±6.46% (87 runs sampled)\nmapbox/lineclip x 27,754,592 ops/sec ±1.94% (98 runs sampled)\n- Fastest is liang-barsky\n```\n\n## Future plan\n\nImplement a sub-routine for polylines. Loop through pairs, tracking in-out\ntransitions.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw8r%2Fliang-barsky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw8r%2Fliang-barsky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw8r%2Fliang-barsky/lists"}