jscad / OpenJSCAD.org

JSCAD is an open source set of modular, browser and command line tools for creating parametric 2D and 3D designs with JavaScript code. It provides a quick, precise and reproducible method for generating 3D models, and is especially useful for 3D printing applications.
https://openjscad.xyz/
MIT License
2.68k stars 516 forks source link

Vertices get merged unexpectedly #1312

Open hrj opened 11 months ago

hrj commented 11 months ago

Expected Behavior

The rectangular slits should retain their shape.

Actual Behavior

The vertices in some of the slits merge, creating triangles instead of rectangular slits.

Steps to Reproduce the Problem

Open the attached file in online editor V 2.6.5. jsCadError2.txt

Changing the diameter to 51 will remove the bug.

Specifications

z3dev commented 11 months ago

@hrj thanks for the nice example. hopefully, we can sort out the issues, and get you moving again.

i tried the example, and the results definitely change when setting diameter to 50 and 51. i then added a short circuit, returning the 2D objects, and found out that the cbc() function may have some issues with the calculations. Can you double check?

z3dev commented 11 months ago

issue

hrj commented 11 months ago

Thanks for looking @z3dev

I can't notice any error in the cdc function. Those thin rectangles which are getting truncated abnormally are just a simple array of rectangles. The union of those with the other set of polygons (lfChopped) is somehow converting them into unclosed polygons.

Since all polygons are being created through primitives or through boolean operations, I don't think there can be any error in the supplied code, unless I am misusing the API in some way. For example, if I am using union in an unexpected way. But since the code works for a different diameter, I don't think that would be a suspect.

z3dev commented 11 months ago

@hrj strange things are happening with the intersect(), so i changed the code a little to...

  cut = subtract(square({size: 10 * radius}), rectangle({ size: chopSize, center: [rb2 + pb4, -rb2-pb4] }))
  const lfChopped = subtract(
    union(lf), cut
  )
  return [verticals, lfChopped]
hrj commented 11 months ago

@z3dev Thanks, that workaround works :) I am unblocked for now.