Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError in reTesselateCoplanarPolygons #1360

Open
kirevdokimov opened this issue Aug 27, 2024 · 5 comments
Open

Uncaught TypeError in reTesselateCoplanarPolygons #1360

kirevdokimov opened this issue Aug 27, 2024 · 5 comments

Comments

@kirevdokimov
Copy link

I use .union() to merge geometries, but when I do so, it causes errors.

Expected Behavior

Geometries are merged with no issues

Actual Behavior

.union() throws an exception

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'length')
    at reTesselateCoplanarPolygons (reTesselateCoplanarPolygons.js:176:40)
    at retessellate.js:25:44
    at Array.forEach (<anonymous>)
    at retessellate (retessellate.js:23:14)
    at union8 (unionGeom3.js:21:17)
    at union8 (union.js:42:35)

Steps to Reproduce the Problem

I assume this basic example works for everyone

const c1 = cylinder({ radius: 3, height: 12, center: [0, 0, 5], segments: 12 })
const c2 = cylinder({ radius: 3, height: 18, center: [0, 0, 5], segments: 12 })

const u = union(c1, c2)

Specifications

  • Version: "@jscad/core": "^2.6.9", "@jscad/modeling": "^2.12.2",
  • Platform: Windows 11, Brave Browser,
  • Environment: Node v16.15.1, esbuild, Brave Browser Version 1.69.153 Chromium: 128.0.6613.85 (Official Build) (64-bit)

Same issue for Google Chrome Version 127.0.6533.122 (Official Build) (64-bit)

@kirevdokimov
Copy link
Author

polygonindexKey is equal to "clear" or "remove" while we iterate over startingpolygonindexes, what causes vertices2d to be undefined.
image
image

If we check for Nan with if (isNaN(polygonindexKey)) continue line, other issue occurs:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '1')
    at interpolateBetween2DPointsForY (interpolateBetween2DPointsForY.js:11:16)
    at reTesselateCoplanarPolygons (reTesselateCoplanarPolygons.js:226:15)
    at retessellate.js:25:44
    at Array.forEach (<anonymous>)
    at retessellate (retessellate.js:23:14)
    at union8 (unionGeom3.js:21:17)
    at union8 (union.js:42:35)

@kirevdokimov
Copy link
Author

This is because activepolygonKey is equal to "clear" or "remove" sometimes as well.
image
Checking for NaN here with if (isNaN(activepolygonKey)) continue line solves the issue

kirevdokimov added a commit to kirevdokimov/OpenJSCAD.org that referenced this issue Aug 27, 2024
@z3dev
Copy link
Member

z3dev commented Aug 28, 2024

@kirevdokimov thanks for the excellent example, and the in-depth analysis.

there are lots of tests but not for this specific example. Given the similarity of the two cylinders, there's obviously something about the retellsation. Have you taken a look at the results of the Union before the retessellation? (Sorry for the spelling)

I'll look over the fix.

@kirevdokimov
Copy link
Author

Responded in a related merge request: #1361

@platypii
Copy link
Contributor

platypii commented Sep 4, 2024

I was not able to reproduce this issue with the example you gave. Maybe I'm missing something?

retess

@platypii platypii mentioned this issue Sep 6, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants