{"id":47732626,"url":"https://github.com/hallojoe/circular-sector","last_synced_at":"2026-04-18T12:06:35.429Z","repository":{"id":96140506,"uuid":"420627054","full_name":"hallojoe/circular-sector","owner":"hallojoe","description":"A set of functions computing cartesian coordinates, describing circular and annular sectors.","archived":false,"fork":false,"pushed_at":"2026-04-01T18:49:32.000Z","size":103,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-03T06:49:20.071Z","etag":null,"topics":["annular","circle","circular","sector"],"latest_commit_sha":null,"homepage":"","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/hallojoe.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-10-24T08:24:43.000Z","updated_at":"2026-03-30T10:07:17.000Z","dependencies_parsed_at":"2023-04-12T19:04:53.871Z","dependency_job_id":null,"html_url":"https://github.com/hallojoe/circular-sector","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/hallojoe/circular-sector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hallojoe%2Fcircular-sector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hallojoe%2Fcircular-sector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hallojoe%2Fcircular-sector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hallojoe%2Fcircular-sector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hallojoe","download_url":"https://codeload.github.com/hallojoe/circular-sector/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hallojoe%2Fcircular-sector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31968013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"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":["annular","circle","circular","sector"],"created_at":"2026-04-02T21:55:28.984Z","updated_at":"2026-04-18T12:06:35.422Z","avatar_url":"https://github.com/hallojoe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Circular Sector\n\nUtilities for calculating the geometry needed to draw circular sectors and annular circular sectors.\n\nThe package is aimed at rendering workflows where you need coordinates and path data rather than a UI framework. It works well for SVG, Canvas, charting, dashboards, gauges, progress arcs, radial menus, and other circular visualizations.\n\n## Features\n\n- Create geometry for solid circular sectors\n- Create geometry for annular sectors using `height`\n- Apply linear gaps between sectors\n- Build SVG path data for sectors and annular sectors\n- Calculate centroids for both sector types\n- Use small geometry helpers independently when needed\n\n## Installation\n\n```bash\nnpm install @casko/circular-sector\n```\n\n## Importing\n\nThe current package layout exposes the compiled modules directly from `dist`, so import the specific files you need:\n\n```ts\nimport { createCircularSectorViewModel } from \"@casko/circular-sector/dist/createCircularSectorViewModel\"\nimport { buildCircularSectorPath } from \"@casko/circular-sector/dist/buildCircularSectorPath\"\n```\n\n## Core Concepts\n\n### Circular sector\n\nA wedge shape defined by:\n\n- `center`\n- `radius`\n- `ratio`\n- `theta`\n\n### Annular circular sector\n\nA ring-shaped sector defined by the same settings plus:\n\n- `height`\n\nThe inner radius is derived as:\n\n```ts\ninnerRadius = radius - height\n```\n\n### Gap\n\n`gap` is treated as a linear distance along the outer arc. The library converts that into an angular trim and recalculates the geometry.\n\n## Main API\n\n### `createCircularSectorViewModel(input)`\n\nCreates the derived geometry for a circular or annular sector.\n\nImportant input fields:\n\n- `center`: `{ x, y }`\n- `radius`: outer radius\n- `ratio`: portion of a full circle, where `1` means a full circle\n- `theta`: start angle in radians\n- `gap`: linear gap distance along the arc\n- `height`: thickness of an annular sector\n- `borderRadius`: optional setting stored in the model, not currently used by the path builder\n\nReturns a view model containing:\n\n- `source`\n- `ratio`\n- `radius`\n- `center`\n- `angles`\n- `anchors.outer`\n- `anchors.middle`\n- `anchors.inner`\n- `anchors.centroid`\n\n### `buildCircularSectorPath(sector, pathRadius?)`\n\nBuilds an SVG path string from a sector view model.\n\n- `pathRadius = 0` builds a normal sharp-cornered path\n- `pathRadius \u003e 0` builds a rounded path\n\n## Example: Build SVG Path Data\n\n```ts\nimport { createCircularSectorViewModel } from \"@casko/circular-sector/dist/createCircularSectorViewModel\"\nimport { buildCircularSectorPath } from \"@casko/circular-sector/dist/buildCircularSectorPath\"\n\nconst sector = createCircularSectorViewModel({\n  center: { x: 150, y: 150 },\n  radius: 100,\n  ratio: 0.25,\n  theta: -Math.PI / 2,\n  gap: 8,\n  height: 40,\n  borderRadius: 0\n})\n\nconst path = buildCircularSectorPath(sector, 8)\n```\n\nExample SVG usage:\n\n```html\n\u003csvg viewBox=\"0 0 300 300\"\u003e\n  \u003cpath d=\"...\" fill=\"tomato\"\u003e\u003c/path\u003e\n\u003c/svg\u003e\n```\n\nReplace `d=\"...\"` with the generated `path` string.\n\n## Example: Access Calculated Geometry\n\n```ts\nimport { createCircularSectorViewModel } from \"@casko/circular-sector/dist/createCircularSectorViewModel\"\n\nconst sector = createCircularSectorViewModel({\n  center: { x: 0, y: 0 },\n  radius: 120,\n  ratio: 0.2,\n  theta: 0,\n  gap: 6,\n  height: 0\n})\n\nconsole.log(sector.angles)\nconsole.log(sector.anchors.outer.start)\nconsole.log(sector.anchors.outer.mid)\nconsole.log(sector.anchors.outer.end)\nconsole.log(sector.anchors.centroid)\n```\n\n## Helper Functions\n\nThe package also includes focused helpers for common geometry tasks:\n\n- `calculateSectorAngles`\n- `calculateArcPoints`\n- `calculateSectorCentroid`\n- `calculateAnnularSectorCentroid`\n- `calculateLineIntersection`\n- `calculateDistanceBetweenPoints`\n- `calculateMidpoint`\n- `calculateEndPointOfLine`\n- `calculateCircleArea`\n- `calculateCircleCircumference`\n- `calculateSectorLengthInRadians`\n- `calculateIsoscelesTriangleHeight`\n- `calculatePolarToCartesian`\n\n## Angles\n\nAngles are expressed in radians.\n\nCommon values:\n\n- `0` points to the right\n- `Math.PI / 2` points down\n- `Math.PI` points left\n- `-Math.PI / 2` points up\n\nThis follows the normal screen-coordinate convention used by SVG and Canvas, where positive `y` goes downward.\n\n## Development\n\nBuild:\n\n```bash\nnpm run build\n```\n\nRun tests:\n\n```bash\nnpm test\n```\n\nWatch tests:\n\n```bash\nnpm run test:watch\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhallojoe%2Fcircular-sector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhallojoe%2Fcircular-sector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhallojoe%2Fcircular-sector/lists"}