{"id":16386497,"url":"https://github.com/rowanwins/shamos-hoey","last_synced_at":"2025-03-21T02:31:24.018Z","repository":{"id":57357824,"uuid":"165592909","full_name":"rowanwins/shamos-hoey","owner":"rowanwins","description":"A module to check if a polygon self-intersects","archived":false,"fork":false,"pushed_at":"2020-05-03T12:36:09.000Z","size":778,"stargazers_count":29,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-10T08:02:06.428Z","etag":null,"topics":["geometry","intersection","polygon","shamos-hoey"],"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":"CHANGES.md","contributing":null,"funding":"FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["rowanwins"],"custom":["https://paypal.me/rowanwinsemius"]}},"created_at":"2019-01-14T04:00:45.000Z","updated_at":"2024-06-26T14:07:31.000Z","dependencies_parsed_at":"2022-09-26T16:33:22.404Z","dependency_job_id":null,"html_url":"https://github.com/rowanwins/shamos-hoey","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fshamos-hoey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fshamos-hoey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fshamos-hoey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rowanwins%2Fshamos-hoey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rowanwins","download_url":"https://codeload.github.com/rowanwins/shamos-hoey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244102712,"owners_count":20398386,"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":["geometry","intersection","polygon","shamos-hoey"],"created_at":"2024-10-11T04:17:26.315Z","updated_at":"2025-03-21T02:31:23.601Z","avatar_url":"https://github.com/rowanwins.png","language":"JavaScript","funding_links":["https://github.com/sponsors/rowanwins","https://paypal.me/rowanwinsemius"],"categories":[],"sub_categories":[],"readme":"# shamos-hoey\nA fast module for checking if segment intersections exist using the Shamos-Hoey algorithm. \nCan be used for \n- detecting if a geometry has self-intersections, or\n- if multiple geometries have segments which intersect\n\n**Note:** This module only detects if an intersection does exist, not where, or how many. If you need to find the points of intersection I suggest using the [sweepline-intersections module](https://github.com/rowanwins/sweepline-intersections).\n## Documentation\n\n### Install\n````\nnpm install shamos-hoey\n````\n\n### Basic Use\nValid inputs: Geojson `Feature` or `Geometry` including `Polygon`, `LineString`, `MultiPolygon`, `MultiLineString`, as well as `FeatureCollection`'s.\n\nReturns `true` if there are no intersections\n\nReturns `false` if there are intersections\n\n````js\n    const noIntersections = require('shamos-hoey')\n\n    const box = {type: 'Polygon', coordinates: [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]}\n    noIntersections(box)\n    // =\u003e true\n````\n\n### Complex Use\nThis library also provide a class-based approach which is helpful if you need to check multiple geometries against a single geometry. This allows you to save the state of the initial event queue with the primary geometry.\n\n````js\n    import ShamosHoeyClass from 'shamos-hoey/dist/ShamosHoeyClass'\n\n    // create the base instance\n    const sh = new ShamosHoeyClass()\n    // populate the event queue with your primary geometry\n    sh.addData(largeGeoJson)\n    // clone the event queue in the original state so you can reuse it\n    const origQueue = sh.cloneEventQueue()\n\n    // now you can iterate through some other set of features saving\n    // the overhead of having to populate the complete queue multiple times\n    someOtherFeatureCollection.features.forEach(feature =\u003e {\n        // add another feature to test against your original data\n        sh.addData(feature, origQueue)\n        // check if those two features intersect\n        sh.noIntersections()\n    })\n````\n\n#### API\n`new ShamosHoeyClass()` - creates a new instance\n\n`.addData(geojson, existingQueue)` - add geojson to the event queue. The second argument for an `existingQueue` is optional, and takes a queue generated from `.cloneEventQueue()`\n\n`.cloneEventQueue()` - clones the state of the existing event queue that's been populated with geojson. Returns a queue that you can pass to the `addData` method\n\n`.noIntersections()` - Checks for segment intersections. Returns `true` if there are no segment intersections or `false` if there are intersections.\n\n\n\n## Similar modules\nIf you need to find the points of self-intersection I suggest using the [sweepline-intersections module](https://github.com/rowanwins/sweepline-intersections). The sweeline-intersections module is also smaller (4kb vs 12kb) and very fast for most use cases. It uses alot of the same logic although doesn't inlude a tree structure which makes up the major dependency for this library.\n\n\n## Benchmarks\nDetecting an intersection in a polygon with roughly 700 vertices. Note that the other libraries report the intersection point/s.\n````\n// Has intersections\n// ShamosHoey x 4,132 ops/sec ±0.60% (95 runs sampled)\n// SweeplineIntersections x 2,124 ops/sec ±0.70% (92 runs sampled)\n// GPSI x 36.85 ops/sec ±1.06% (64 runs sampled)\n// - Fastest is ShamosHoey\n````\nFor the class-based module vs the basic use on a very large geojson file (approx. 14,000 vertices)\n````\n// Class-based reuse vs Basic\n// ShamosHoey x 1,011 ops/sec ±8.12% (89 runs sampled)\n// ShamosHoeyClass x 2,066 ops/sec ±0.60% (93 runs sampled)\n// - Fastest is ShamosHoeyClass\n````\n\n\n## Further Reading\n[Original Paper](https://github.com/rowanwins/shamos-hoey/blob/master/ShamosHoey.pdf)\n\n[Article on Geom algorithms website](http://geomalgorithms.com/a09-_intersect-3.html#Shamos-Hoey-Algorithm)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowanwins%2Fshamos-hoey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frowanwins%2Fshamos-hoey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frowanwins%2Fshamos-hoey/lists"}