{"id":31730841,"url":"https://github.com/afternoon2/webgpu-clip","last_synced_at":"2025-10-09T07:42:21.176Z","repository":{"id":315633188,"uuid":"892858212","full_name":"afternoon2/webgpu-clip","owner":"afternoon2","description":"POC of (poly)line clipping using WebGPU's compute shaders","archived":false,"fork":false,"pushed_at":"2025-09-19T17:31:34.000Z","size":1237,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-19T19:55:34.687Z","etag":null,"topics":["compute-shaders","geometry","line-clipping","plotter-art","typescript","webgpu"],"latest_commit_sha":null,"homepage":"https://afternoon2.github.io/webgpu-clip/","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/afternoon2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2024-11-22T23:12:51.000Z","updated_at":"2025-09-19T17:31:23.000Z","dependencies_parsed_at":"2025-09-19T20:12:31.926Z","dependency_job_id":null,"html_url":"https://github.com/afternoon2/webgpu-clip","commit_stats":null,"previous_names":["afternoon2/webgpu-clip"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/afternoon2/webgpu-clip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afternoon2%2Fwebgpu-clip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afternoon2%2Fwebgpu-clip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afternoon2%2Fwebgpu-clip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afternoon2%2Fwebgpu-clip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afternoon2","download_url":"https://codeload.github.com/afternoon2/webgpu-clip/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afternoon2%2Fwebgpu-clip/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000980,"owners_count":26082974,"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-09T02:00:07.460Z","response_time":59,"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":["compute-shaders","geometry","line-clipping","plotter-art","typescript","webgpu"],"created_at":"2025-10-09T07:42:16.581Z","updated_at":"2025-10-09T07:42:21.171Z","avatar_url":"https://github.com/afternoon2.png","language":"TypeScript","readme":"# webgpu-clip (POC)\n\n![Demo image](public/demo.png \"Title\")\n\nClipping lines and polylines is especially useful in pen plotter art, where, if you want to fill a shape with color, you need to hatch it with lines. In other words: to create a bunch of lines covering the bounding box of a polygon, and then to clip them.\n\nClipping lines and polylines on CPU is feasible, but might be slow, especially when having many shapes to fill. That's why I created this POC.\n\nThis repository contains 2 utility classes, one for clipping lines (2-points long arrays), which is useful for fast shape filling with color. The second one is for complex polylines, such as patterns that intersect given shape.\n\n**Both utilities are not fully tested and might produce incorrect results**\n\nEdge cases like curved (spirals) or really complex polygons with hundreds of edges are not well handled yet.\n\n### Line clipping\n\n```ts\nconst polygon = [\n  /* a polygon as a bunch of rings filled with points in { X: number, Y: number } format */\n];\n\nconst lines = [\n  [{ X: 10, Y: 10 }, { 1000, 10 },]  /* etc. */\n];\n\nconst device = await getGPUDevice();\nconst clipper = new LineClipper({ device, polygon });\n\nconst result = await clipper.lineClip(lines);\n```\n\n### Polyline clipping\n\n```ts\nconst device = await getGPUDevice();\n\nconst polygon = [\n  /* a polygon as a bunch of rings filled with points in { X: number, Y: number } format */\n];\nconst polylines = [[\n  { X: 10, Y: 10 },\n  { X: 30, Y: 39 },\n  { X: 21, Y: 37 } /* array of arrays of connected points */,\n]];\n\nconst clipper = new PolylineClipper({ device, polygon })\n\nconst result = await clipper.clip(polylines));\n```\n\n### Point format\n\nPoint format (`{ X: number; Y: number; }`) is the same as the format of famous and briliant [Javascript Clipper library](https://sourceforge.net/p/jsclipper/wiki/documentation/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafternoon2%2Fwebgpu-clip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafternoon2%2Fwebgpu-clip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafternoon2%2Fwebgpu-clip/lists"}