unmess-poly

polygon self-intersection removal algorithm. turns complex self-intersecting polygons into non-complex non-self-intersecting polygons, optionally with holes

Try below:

Usage

  <script src="https://unmess-poly.glitch.me/unmess.js"></script>
  <script>
    let polygon = [[100,100], [300,100], [200,300], [250,120], [250,155]];
    let polygons = unmess.unmess(polygon,{
      hole_policy:unmess.HOLE_NONZERO, // or HOLE_NONE, HOLE_EVENODD, HOLE_AGGRESSIVE
      epsilon:0.0001,
    });
    console.log('outline:', polygons[0]);
    console.log('holes:', polygons.slice(1));
  </script>