Skip to content

TypeError: Cannot read properties of undefined (reading 'depth') #155

@platypii

Description

@platypii

I think I found a bug that results in an exception being thrown. It happens when doing a union of two polygons. The polygons in this example have a co-linear edge, although I don't know if that's relevant.

martinez

I made a test case which demonstrates the problem. Add this under test/genericTestCases/colinear.json:

{
  "features": [
    {
      "geometry": {
        "coordinates": [
          [
            [ -5, 0 ],
            [ 4.707106781186547, 0.7071067811865477 ],
            [ 3.477592250072517, 0.7836116248912244 ],
            [ 4, 1 ],
            [ -5, 0 ]
          ]
        ],
        "type": "Polygon"
      },
      "properties": {},
      "type": "Feature"
    },
    {
      "geometry": {
        "coordinates": [
          [
            [ 4.707106781186547, 0.7071067811865477 ],
            [ 4, 1 ],
            [ 0, 1 ],
            [ 4.707106781186547, 0.7071067811865477 ]
          ]
        ],
        "type": "Polygon"
      },
      "properties": {},
      "type": "Feature"
    },
    {
      "geometry": {
        "coordinates": [
          [
            [
              [ -5, 0 ],
              [ 4.707106781186547, 0.7071067811865477 ],
              [ 4, 1 ],
              [ 0, 1 ],
              [ 2.564081902288895, 0.8404535446987661 ],
              [ -5, 0 ]
            ]
          ]
        ],
        "type": "MultiPolygon"
      },
      "properties": {"operation": "union"},
      "type": "Feature"
    }
  ],
  "type": "FeatureCollection"
}

Running npm test then gives the exception:

/code/martinez/src/connect_edges.js:121
      contour.depth = contours[lowerContourId].depth;
                                               ^

TypeError: Cannot read properties of undefined (reading 'depth')
    at initializeContourFromContext (/code/martinez/src/connect_edges.js:121:48)
    at connectEdges (/code/martinez/src/connect_edges.js:150:21)
    at boolean (/code/martinez/src/index.js:76:20)
    at Object.union [as op] (/code/martinez/index.js:10:10)

The exception happens on connect_edges.js line 121 here.

Tracing the error backwards reveals that lowerContourId is set to -1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions