alexbol99 / flatten-js

Javascript library for 2d geometry
MIT License
535 stars 56 forks source link

[help] polygon.cut error: TypeError: Cannot set properties of undefined (setting 'prev') #175

Closed Fauny closed 1 month ago

Fauny commented 2 months ago

version: latest

code:

{
  let { point, segment, circle, arc, Polygon, multiline } = Flatten;

  // Create polygon from json
  let json = [
    [
      {
        ps: { x: 641.64, y: 118.32, name: "point" },
        pe: { x: 641.64, y: 151.74, name: "point" },
        name: "segment"
      },
      {
        ps: { x: 641.64, y: 151.74, name: "point" },
        pe: { x: 504.66, y: 151.74, name: "point" },
        name: "segment"
      },
      {
        ps: { x: 504.66, y: 151.74, name: "point" },
        pe: { x: 504.66, y: 118.32, name: "point" },
        name: "segment"
      },
      {
        ps: { x: 504.66, y: 118.32, name: "point" },
        pe: { x: 641.64, y: 118.32, name: "point" },
        name: "segment"
      }
    ]
  ];

  let polygon = new Polygon(json);
  let svg = polygon.svg();

  // Create Multiline
  let mlj = [
    {
      ps: { x: 576.48, y: 118.32, name: "point" },
      pe: { x: 576.48, y: 274.14, name: "point" },
      name: "segment"
    },
    {
      ps: { x: 576.48, y: 274.14, name: "point" },
      pe: { x: 641.64, y: 274.14, name: "point" },
      name: "segment"
    }
  ];
  let ml = multiline(mlj.map((s) => segment(s)));

  return polygon.cut(ml);
}
Fauny commented 2 months ago

@alexbol99 help me, pls.

alexbol99 commented 2 months ago

Dear @Fauny , I see a problem, but I don't have a fix yet. Working on it

alexbol99 commented 2 months ago

Bug fixed in v1.5.3 Now it can cut correctly. I used polygon.toArray() to get both parts as polygon instances.

image
Fauny commented 2 months ago

Thank u !!