{"id":28586182,"url":"https://github.com/herrstrietzel/poly-simplify","last_synced_at":"2026-03-07T21:32:33.173Z","repository":{"id":294350689,"uuid":"986671308","full_name":"herrstrietzel/poly-simplify","owner":"herrstrietzel","description":"Simplify/reduce polylines/polygon vertices in JS","archived":false,"fork":false,"pushed_at":"2025-06-28T15:45:43.000Z","size":3647,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-10T08:14:46.293Z","etag":null,"topics":["javascript","pathdata","polygon","polyline","simplification","svg"],"latest_commit_sha":null,"homepage":"https://herrstrietzel.github.io/poly-simplify/","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/herrstrietzel.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}},"created_at":"2025-05-20T00:49:49.000Z","updated_at":"2025-06-28T15:45:47.000Z","dependencies_parsed_at":"2025-06-28T16:34:41.262Z","dependency_job_id":"c92bc2fa-9b2e-4c31-b399-3ff96ca8034c","html_url":"https://github.com/herrstrietzel/poly-simplify","commit_stats":null,"previous_names":["herrstrietzel/poly-simplify"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/herrstrietzel/poly-simplify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2Fpoly-simplify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2Fpoly-simplify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2Fpoly-simplify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2Fpoly-simplify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/herrstrietzel","download_url":"https://codeload.github.com/herrstrietzel/poly-simplify/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/herrstrietzel%2Fpoly-simplify/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30231636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"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":["javascript","pathdata","polygon","polyline","simplification","svg"],"created_at":"2025-06-11T06:31:02.759Z","updated_at":"2026-03-07T21:32:33.138Z","avatar_url":"https://github.com/herrstrietzel.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![npm version](https://img.shields.io/npm/v/poly-simplify)](https://www.npmjs.com/package/poly-simplify)\n[![gzipped size](https://img.shields.io/bundlephobia/minzip/poly-simplify)](https://bundlephobia.com/result?p=poly-simplify)\n[![minified size](https://img.shields.io/bundlephobia/min/poly-simplify)](https://bundlephobia.com/result?p=poly-simplify)\n[![license](https://img.shields.io/npm/l/poly-simplify)](https://www.npmjs.com/package/poly-simplify)\n[![CDN](https://img.shields.io/badge/CDN-jsDelivr-E84D3D?style=flat)](https://cdn.jsdelivr.net/npm/poly-simplify@latest/+esm)\n\n\u003cp align=\"center\" style=\"text-align:center\"\u003e\n\u003cimg width=\"100\" height=\"100\" style=\"display:inline-block\" src=\"./favicon.svg\"\u003e\n\u003ch1 align=\"center\"\u003epoly-simplify\u003c/h1\u003e\n\u003c/p\u003e \n\nDependancy free JS library to simplify polyline or polygon vertices. \n\nThis library is *obviously* heavily inspired by Volodymyr Agafonkin's brilliant [»simplify.js«](https://github.com/mourner/simplify-js) library which has become kind of a standard.  \nWhile most polygon simplification libraries are focused on geodata/map applications, »poly-simplify« aims at a more versatile concept e.g by providing a variety of inputs and including multiple methods for SVG graphic applications.\n\n* [Features](#features)\n* [Simplification methods](#simplification-methods)\n* [1. Usage](#1-usage)\n  + [1.1. IIFE](#11-iife)\n  + [1.2. ESM](#12-esm)\n  + [1.3 Node.js](#13-nodejs)\n* [2. Options](#2-options)\n* [3. Quality control](#3-quality-control)\n  + [3.1 Relative Quality thresholds](#31-relative-quality-thresholds)\n  + [3.2 Absolute thresholds](#32-absolute-thresholds)\n* [4. Demos: Simplifier Webapp](#4-demos-simplifier-webapp)\n* [Changelog, Updates and rollback](#changelog-updates-and-rollback)\n  + [Rollback](#rollback)\n  + [Changelog](#changelog)\n* [Bug reporting](#bug-reporting)\n* [Credits and further reading](#credits-and-further-reading)\n\n\n## Features\n* **input normalisation:** you can pass pretty much any reasonable polygon notation such as: \n  * **point-object arrays** – so `[{x:0, y:10}, {x:1, y:20}]`  \n  * **stringified point data** (as provided by SVG `\u003cpolygon\u003e` `point` attributes – `0 10 1 20`  \n  * **nested arrays** like `[[0 10], [1 20]]`  \n  * **JSON** stringified presentations of point arrays like `[{\"x\":0,\"y\":10},{\"x\":1,\"y\":20}]`  \n  * **SVG** pathdata: `M0 0 100 200z`\n\n* **Relative or absolute quality threshold:** simplification is controlled via a *relative* quality parameter similar to raster image compression logics – super tiny geoData polygons won't get distorted\n\n* **SVG**: node property data (e.g SVG polygons) – constructors like SVGPoint are normalized to get a \"decoupled\" point array  \n\n* **Supports compound shapes/paths** intersecting polygons interpreted as cut-out shapes\n\n* **Dynamic decimal rounding** by default decimals are adjusted to match tiny polygon's dimensions \n\n* **scaling and alignment:** tiny polygons can be scaled to a reasonable size for demonstration purposes. You can also realign coordinates to zero origin\n\n\n## Simplification methods\n* \"RC\" - remove colinear: removes only colinear or zero-length segments. This method can be concidered \"lossless\" and is ideal for polygons with a lot of excessive point added by a graphic editor (e.g due too shape merging)\n* \"RD\" - simplify by radial distance: removes short segments. Ideal for more aggressive simplifications\n* \"RDP\" – Ramer-Douglas-Peucker algorithm\n* \"VW\" – Visvalingam-Whyatt algorithm\n* max vertices simplification: simply omits vertices to get the desired point count – very fast but sloppy\n\n\n## 1. Usage\n\n### 1.1. IIFE\n```\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/poly-simplify@latest/dist/poly-simplify.min.js\"\u003e\u003c/script\u003e\n\n\u003cscript\u003e\n  let pts = [{x:0, y:10}, {x:1, y:20}, {x:2, y:30}];\n  let polyPtsSimplified = polySimplify(pts);\n\u003c/script\u003e\n```\n\n### 1.2. ESM\n```\n\u003cscript type=\"module\"\u003e\n  import {polySimplify} from 'https://cdn.jsdelivr.net/npm/poly-simplify@latest/+esm';\n\n  let pts = [{x:0, y:10}, {x:1, y:20}, {x:2, y:30}];\n  let polyPtsSimplified = polySimplify(pts)\n\u003c/script\u003e\n```\n\n### 1.3 Node.js\n\nInstall\n```\nnpm install poly-simplify\n```\n\nUsage \n``` \nimport polySimplify from 'poly-simplify';\nconst simplified = polySimplify('M0 0 h10 h10 v10 v10');\nconsole.log(simplified);\n```\n\n## 2. Options\n\n| param | default | type | effect |\n| -- | -- | -- | -- |\n| quality | `0.5` | number/string | simplification tolerance: accepts numeric value from 0-1 for relative quality, absolute pixel thresholds adding px unit to string `1px` or maximum vertices specified via `v` unit like so `150v` |\n| RDP | `true` | Boolean | Applies Ramer-Douglas-Peucker simplification |  \n| VW | `true` |  Boolean | Visvalingam-Whyatt simplification |  \n| RD | `true` | Boolean | Radial Distance simplification |  \n| output | `points` | string | output result: 1. \"points\"= point object array  2. \"path\"= SVG path data string 3. \"pathdata\" = pathdata array 4. \"json\"= JSON string 5. \"pointString\" = flat point string (as used for polygon points attribute) |\n| skipPoints | `false`  | Boolean | simplify by reducing number of vertices to a max limit | \n| maxPoints | `0` | Number | Max points limit for `useMax` option |\n| scale | `1` | Number | scale polygon |  \n| scaleToWidth, scaleToHeight | `0` | Number | fit polygon into specified max dimensions |  \n| alignToZero | `false` | Boolean | align weird starting coordinates to x/y=0 |  \n| translateX, translateY | `0` | Number | set manual x/y offsets to realign polygon |  \n| decimals | `-1` | Number | round coordinates to decimals. `-1` won't apply rounding. Too small floating point accuracy is auto-adjusted to avoid distortions |\n| toRelative | `false`  | Boolean | **SVG** converts commands to relative – more compact |  \n| toShorthands | `false`  | Boolean | **SVG** applies shorthand commands where possible `h`, `v` – more compact |  \n| minifyString | `false`  | Boolean | **SVG** applies string based minification e.g omitting leading zeroes or concatenating subsequent floats `.123.456` – more compact |  \n| meta | `false`  | Boolean | return additional data like: vertices counts (original and simplified) – this option is mostly for debugging e.g for integrety checks  |\n\n\n## 3. Quality control\n### 3.1 Relative Quality thresholds  \nBy default poly-simplify expects a value between 0–1.   \nThis concept tries to achieve a relative quality similar to raster image compression settings such as Jpg quality levels:  \n* `1` - we only apply \"lossless\" simplification by removing only colinear points. More aggressive simplification algorithms like Radial-distance, Ramer-Douglas-Peucker or Visvalingam-Whyatt are disabled\n* `0.5 – 1` – tries to find a ballance between visual fidelity and point reduction\n* `\u003c0.5` – adjusts thresholds for more aggressive simplification\nThis approach will auto-detect **reasonable thresholds** by approximating the total dimensions of a polygon. So geoData polys that may be smaller than 1px/unit can be simplified without the need to know a suitable tolerance7threshold that might be `0.00001px`\n\n### 3.2 Absolute thresholds  \nYou can also enter an absolute threshold via string input:  \n`1px` – sets the simplification threshold to absolute 1 units – bear in mind this may lead to heavy distortions if your polygon is way smaller than the threshold value\n`150v` – the `v`(vertices) unit will add a maximum point limit to the simplification. In this example: reduce to a maximum of 150 points/vertices.\n\n\n\n##  4. Demos: Simplifier Webapp\nYou can easily test poly-simplify using the [**webapp**](https://herrstrietzel.github.io/poly-simplify/)  \n\n![Webapp](demo/img/app.png )\n\nYou can test all settings and generate sample SVG files for demo purposes:\n* output object (point array, nested array, SVG or JSON)\n* SVG snippet\n* JS code snippet\n\n## Changelog, Updates and rollback\n### Rollback\nIf you encounter any issues with the recent versions you can rollback to a previous version.  \nSee all versions on \n* [npm](https://www.npmjs.com/package/poly-simplify)  \n* [jsdelivr](https://www.jsdelivr.com/package/npm/poly-simplify)\n\n### Changelog\n* 0.1.4 fixed problems with linear polylines\n\n\n## Bug reporting\nIf you found a bug - feel free to file an [issue](https://github.com/herrstrietzel/poly-simplify/issues).   \nFor debugging you may also test your example in the [webapp](https://herrstrietzel.github.io/poly-simplify). \nYou can also post in the [discussions](https://github.com/herrstrietzel/poly-simplify/discussions) if you have ideas for missing features.\n\n## Credits and further reading\n* Volodymyr Agafonkin for [»simplify.js«](https://github.com/mourner/simplify-js)\n* Mike Bostock (d3.js) on [Line Simplification](https://bost.ocks.org/mike/simplify/)\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherrstrietzel%2Fpoly-simplify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fherrstrietzel%2Fpoly-simplify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fherrstrietzel%2Fpoly-simplify/lists"}