{"id":16386484,"url":"https://github.com/rowanwins/kwc-lineclip","last_synced_at":"2025-03-23T04:31:28.769Z","repository":{"id":66017590,"uuid":"118527703","full_name":"rowanwins/kwc-lineclip","owner":"rowanwins","description":"Line clipping based on the algorithm by Kodituwakka, Wijeweera \u0026 Chamikara","archived":false,"fork":false,"pushed_at":"2018-03-12T21:52:35.000Z","size":223,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T17:43:54.301Z","etag":null,"topics":["algorithm","clipping","geometry"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/rowanwins.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":"2018-01-22T23:09:51.000Z","updated_at":"2022-01-01T16:31:58.000Z","dependencies_parsed_at":"2023-05-06T08:01:51.856Z","dependency_job_id":null,"html_url":"https://github.com/rowanwins/kwc-lineclip","commit_stats":{"total_commits":14,"total_committers":3,"mean_commits":4.666666666666667,"dds":0.1428571428571429,"last_synced_commit":"ba806d25b357b24fdca0a7ccbb3b47c13105ca58"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fkwc-lineclip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fkwc-lineclip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fkwc-lineclip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fkwc-lineclip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rowanwins","download_url":"https://codeload.github.com/rowanwins/kwc-lineclip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245056889,"owners_count":20553855,"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":["algorithm","clipping","geometry"],"created_at":"2024-10-11T04:17:25.002Z","updated_at":"2025-03-23T04:31:28.408Z","avatar_url":"https://github.com/rowanwins.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## kwc-lineclip\nA small javascript lib for clipping polylines by a bounding box.\n\n### Install\n````\nnpm install kwc-lineclip\n````\n\n### API\n```js\nlineclip(\n    [[-10, 10], [10, 10], [10, -10]], // polyline\n    [0, 0, 20, 20]); // bbox\n// returns [[[0, 10], [10, 10], [10, 0]]]\n```\n\n### Algorithm\nThis library is an implementation of the approach described in ['An Efficient Algorithm for Line Clipping in Computer Graphics Programming'](http://www.academia.edu/2491960/An_Efficient_Algorithm_for_Line_Clipping_in_Computer_Graphics_Programming) by Kodituwakka, Wijeweera \u0026 Chamikara. Some adjustments have been made to the algorithm in the paper to cater for lines with multiple segments.\n\n### Performance\nI've checked the performance of this algorithm against implementations of the [Cohen-Sutherland](https://github.com/mapbox/lineclip) and a [Liang-barsky](https://github.com/w8r/liang-barsky) algorithms for clipping just one segment. Liang-barsky currently only supports a single segment clip.\n````\nSINGLE SEGMENT TEST\nkwc x 9,542,273 ops/sec ±1.78% (100 runs sampled)\nliang-barsky (non-destructive) x 17,583,416 ops/sec ±2.89% (99 runs sampled)\nmapbox/lineclip x 7,022,569 ops/sec ±8.14% (95 runs sampled)\n- Fastest is liang-barsky (non-destructive)\n\nMULTIPLE SEGMENT MULTIPLE OUTPUT TEST\nkwc x 4,974,886 ops/sec ±6.84% (82 runs sampled)\nmapbox/lineclip x 3,788,980 ops/sec ±0.70% (88 runs sampled)\n- Fastest is kwc\n\nLONGER LINE\nkwc x 800,189 ops/sec ±0.79% (93 runs sampled)\nmapbox/lineclip x 704,052 ops/sec ±2.53% (88 runs sampled)\n- Fastest is kwc\n````\n\nkwc-lineclip was initially faster than liang-barsky until I amended the algorithm to support multiple segments.\n\nMemory usage is also slightly less in with this module compared with `lineclip`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowanwins%2Fkwc-lineclip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frowanwins%2Fkwc-lineclip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowanwins%2Fkwc-lineclip/lists"}