alexbol99 / flatten-js

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

Polygon.cut: TypeError: Cannot read properties of undefined (reading 'edge_after') #176

Closed Fauny closed 1 month ago

Fauny commented 2 months ago
{
  let { Polygon, Multiline, segment } = Flatten
  let polygon = new Polygon([
  [
    { ps: { x: 310.1, y: 423.82, name: "point", },
      pe: { x: 310.1, y: 460.66, name: "point", },
      name: "segment", },
    { ps: { x: 310.1, y: 460.66, name: "point", },
      pe: { x: 189.98, y: 460.66, name: "point", },
      name: "segment", },
    { ps: { x: 189.98, y: 460.66, name: "point", },
      pe: { x: 189.98, y: 423.94, name: "point", },
      name: "segment", },
    { ps: { x: 189.98, y: 423.94, name: "point", },
      pe: { x: 210.5, y: 423.94, name: "point", },
      name: "segment", },
    { ps: { x: 210.5, y: 423.94, name: "point", },
      pe: { x: 210.5, y: 313.75, name: "point", },
      name: "segment", },
    { ps: { x: 210.5, y: 313.75, name: "point", },
      pe: { x: 272.66, y: 313.75, name: "point", },
      name: "segment", },
    { ps: { x: 272.66, y: 313.75, name: "point", },
      pe: { x: 272.66, y: 325.99, name: "point", },
      name: "segment", },
    { ps: { x: 272.66, y: 325.99, name: "point", },
      pe: { x: 291.38, y: 325.99, name: "point", },
      name: "segment", },
    { ps: { x: 291.38, y: 325.99, name: "point", },
      pe: { x: 291.38, y: 423.94, name: "point", },
      name: "segment", },
    { ps: { x: 291.38, y: 423.94, name: "point", },
      pe: { x: 310.1, y: 423.82, name: "point", },
      name: "segment", },
  ]])

  let ml = new Multiline([
    {
      ps: { x: 210.5, y: 460.66, name: "point" },
      pe: { x: 210.5, y: 423.94, name: "point" },
      name: "segment",
    }, { 
      ps: { x: 210.5, y: 423.94, name: "point", },
      pe: { x: 253.94, y: 423.94, name: "point", },
      name: "segment",
    },
    {
      ps: { x: 253.94, y: 423.94, name: "point", },
      pe: { x: 253.94, y: 442.3, name: "point", },
      name: "segment",
    },
    {
      ps: { x: 253.94, y: 442.3, name: "point", },
      pe: { x: 272.66, y: 442.3, name: "point", },
      name: "segment",
    },
    {
      ps: { x: 272.66, y: 442.3, name: "point", },
      pe: { x: 272.66, y: 460.66, name: "point", },
      name: "segment",
    },
  ].map(l=>segment(l)))

   let svg = polygon.svg()
    svg += ml.svg({stroke:'red'})
    let stage = d3.select(DOM.svg(1000, 600))
    stage.html(svg)

    let slices = polygon.cut(ml)

    if (slices.toArray().length != 3) {
      console.error('Cut fail.')
    }

    return stage.node();
}
Fauny commented 2 months ago

@alexbol99 another error.

alexbol99 commented 1 month ago

Hello @Fauny , I released a new patch v1.5.4, which fixes an error. But the result after cut is two faces, like in the image. I think this is the best that I can do for now.

image
Fauny commented 1 month ago

@alexbol99 Thanks !!!