homfen / bentley-ottmann-intersections

A module to check if a polygon self-intersects using the bentley-ottmann algorithm

Home Page:https://rowanwins.github.io/bentley-ottmann-intersections/debug/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

self-intersects

NOTE For a faster and smaller module I recommend checking out sweepline-intersections

A small module using the Bentley-Ottmann algorithm to detection self-intersections

Install

npm install self-intersects

Documentation

Valid inputs: Geojson Polygon, MultiPolygon

    const findIntersections = require('self-intersects')

    const box = {type: 'Polygon', coordinates: [[[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]]}
    findIntersections(box)
    // returns array os intersection points

Benchmarks

Tested against

// Switzerland with kinks
// gpsi x 36.78 ops/sec ±2.03% (49 runs sampled)
// bentleyOttmannIntersections x 2,047 ops/sec ±1.79% (89 runs sampled)
// isects x 14.22 ops/sec ±1.73% (40 runs sampled)
// - Fastest is bentleyOttmannIntersections

// Simple Case
// gpsi x 246,005 ops/sec ±1.54% (90 runs sampled)
// bentleyOttmann x 535,293 ops/sec ±1.73% (95 runs sampled)
// - Fastest is bentleyOttmannIntersections

Contributing

  • For a live dev server run npm run debug.
    • The geometry being tested can be modified in debug/src/App.vue
  • There are a couple of test suites
    • npm run test runs all tests
    • npm run test:e2e does a general test that the correct number of self-intersections are found in the test/fixtures folder
    • npm run test:unit is unit style tests to make sure functions & methods do the right thing
      • these need some love

Further Reading

About

A module to check if a polygon self-intersects using the bentley-ottmann algorithm

https://rowanwins.github.io/bentley-ottmann-intersections/debug/index.html

License:MIT License


Languages

Language:JavaScript 95.1%Language:Vue 4.3%Language:HTML 0.6%