alexbol99 / flatten-js

Javascript library for 2d geometry
MIT License
551 stars 58 forks source link

Cannot cut polygon with MultiLine #159

Closed metehan-coone closed 6 months ago

metehan-coone commented 9 months ago

Edit: Fixed in v1.5.0 notebook example

I want to cut a polygon with a polyline, I tried to proceed similarly to the structure in your notebook example, but I am facing this problem

const polygon = new Polygon([
    point(20, 20),
    point(60, 20),
    point(60, 60),
    point(20, 60),
  ]);
  const segment = new Segment(point(20, 20), point(40, 40));
  const ip1 = segment.intersect(polygon);
  const ip_sorted1 = segment.sortPoints(ip1);

  const segment2 = new Segment(point(40, 40), point(50, 40));
  const ip2 = segment2.intersect(polygon);
  const ip_sorted2 = segment2.sortPoints(ip2);

  const segment3 = new Segment(point(50, 40), point(60, 60));
  const ip3 = segment3.intersect(polygon);
  const ip_sorted3 = segment3.sortPoints(ip3);

  // console.log(ip1, ip2);

  const multiLine = new Multiline([segment, segment2, segment3]).split([
    ...ip_sorted1,
    ...ip_sorted2,
    ...ip_sorted3,
  ]);
  const polygonParts = polygon.cut(multiLine);

image

alexbol99 commented 9 months ago

I reproduced this bug. Method cut is incomplete, I need to fix it.

metehan-coone commented 9 months ago

I reproduced this bug. Method cut is incomplete, I need to fix it.

Can you close this issue when you fix the bug so I can be notified

alexbol99 commented 6 months ago

Method cut fixed in v1.5.0 @metehan-coone