{"id":17364444,"url":"https://github.com/mbullington/turf-diameter","last_synced_at":"2026-01-20T12:33:08.696Z","repository":{"id":44132158,"uuid":"190692262","full_name":"mbullington/turf-diameter","owner":"mbullington","description":"An unofficial Turf function for calculating the polygon diameter of a Feature.","archived":false,"fork":false,"pushed_at":"2023-01-03T23:36:13.000Z","size":1688,"stargazers_count":1,"open_issues_count":16,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-11-20T11:03:00.167Z","etag":null,"topics":["algorithm","geojson","javascript","turfjs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbullington.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-07T05:23:07.000Z","updated_at":"2023-03-10T10:59:24.000Z","dependencies_parsed_at":"2023-02-01T13:47:24.595Z","dependency_job_id":null,"html_url":"https://github.com/mbullington/turf-diameter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mbullington/turf-diameter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbullington%2Fturf-diameter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbullington%2Fturf-diameter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbullington%2Fturf-diameter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbullington%2Fturf-diameter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbullington","download_url":"https://codeload.github.com/mbullington/turf-diameter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbullington%2Fturf-diameter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28603392,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T12:01:53.233Z","status":"ssl_error","status_checked_at":"2026-01-20T12:01:46.545Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","geojson","javascript","turfjs"],"created_at":"2024-10-15T20:42:20.510Z","updated_at":"2026-01-20T12:33:08.680Z","avatar_url":"https://github.com/mbullington.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# turf-diameter\n\nAn unofficial Turf module for calculating the [polygon diameter](http://mathworld.wolfram.com/PolygonDiameter.html) of\na Feature or FeatureCollection.\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n-   [dtheta](#dtheta)\n    -   [Parameters](#parameters)\n-   [diameter](#diameter)\n    -   [Parameters](#parameters-1)\n    -   [Examples](#examples)\n\n### dtheta\n\nReturns the counter-clockwise angle between\n`{ coords[a], coords[a + 1] }` to `{ coords[b], coords[b + 1] }`\n\n#### Parameters\n\n-   `coords` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\u0026lt;\\[[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)]\u003e** List of GeoJSON coordinates\n-   `a` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** starting index of the first ray\n-   `b` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** starting index of the second ray\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** counter-clockwise angle between 0 and `2 * pi`\n\n### diameter\n\nTakes a [Feature](Feature) or [FeatureCollection](FeatureCollection) and returns the\n[polygon diameter](http://mathworld.wolfram.com/PolygonDiameter.html).\n\nInternally, this uses the rotating calipers method and pseudocode\ndescribed [here](https://www.tvhoang.com/articles/2018/12/rotating-calipers).\nThe concepts from the article are based off of the following paper:\nShamos, Michael (1978). \"Computational Geometry\" (PDF). Yale University. pp. 76–81.\n\nThe rotating calipers method requires a convex hull so we use mapbox's concaveman,\nwhich runs in `O(n * log n)` time as stated [here](https://github.com/mapbox/concaveman).\n\nThe algorithm in the paper runs in about O(n) time, making this entire algorithm\nrun in `O(n)` + `O(n * log n)` = `O(n * log n)` time.\n\n#### Parameters\n\n-   `geojson` **GeoJSON** input Feature or FeatureCollection\n\n#### Examples\n\n```javascript\nconst points = turf.featureCollection([\n  turf.point([10.195312, 43.755225]),\n  turf.point([10.404052, 43.8424511]),\n  turf.point([10.579833, 43.659924]),\n  turf.point([10.360107, 43.516688]),\n  turf.point([10.14038, 43.588348]),\n  turf.point([10.195312, 43.755225])\n]);\n\nconst len = diameter(points);\n```\n\nReturns **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the polygon diameter of the GeoJSON\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbullington%2Fturf-diameter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbullington%2Fturf-diameter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbullington%2Fturf-diameter/lists"}