Closed Hermann-SW closed 4 months ago
Fix is available on my fork: https://github.com/jscad/OpenJSCAD.org/compare/master...Hermann-SW:OpenJSCAD.org:master
Only problem is that this single testcase fails after fix, but that is likely because because of incorrect plane.fromPoints() a point too much was returned, and now is not. So likely 863 is correct:
pi@raspberrypi5:~/OpenJSCAD.org/packages/modeling/src/operations/expansions $ ../../../../../node_modules/.bin/ava expand.test.js
expand: expanding of a geom3 produces expected changes to polygons
src/operations/expansions/expand.test.js:133
132: t.notThrows.skip(() => geom3.validate(obs2))
133: t.is(pts2.length, 864)
134: })
Difference:
- 863
+ 864
› expand.test.js:133:5
─
1 test failed
pi@raspberrypi5:~/OpenJSCAD.org/packages/modeling/src/operations/expansions $
It is not only that single point difference, I did outpus pts2 in both cases, and there are much more (minimal) differences:
pi@raspberrypi5:~/old/OpenJSCAD.org/packages/modeling/src/operations/expansions $ diff out ~/OpenJSCAD.org/packages/modeling/src/operations/expansions/out | head
20c20
< - -1.7870337216829664,
---
> - -1.7870337216829657,
25c25
< - -1.7870337216829664,
---
> - -1.7870337216829657,
30c30
< - -5.322567627615704,
pi@raspberrypi5:~/old/OpenJSCAD.org/packages/modeling/src/operations/expansions $ diff out ~/OpenJSCAD.org/packages/modeling/src/operations/expansions/out | wc --lines
23983
pi@raspberrypi5:~/old/OpenJSCAD.org/packages/modeling/src/operations/expansions $
Yeah. This is the issue that I mentioned about the ordering of the points. The points have to create a valid polygon, i.e. non-crossing edges.
I completed an implementation of a best-fit algorithm. See #1322 for the code changes. I believe this would be a better choice for the general use cases.
Yeah. This is the issue that I mentioned about the ordering of the points. The points have to create a valid polygon, i.e. non-crossing edges.
@z3dev Interesting, and you are right, my example above in this issue was with intersection of 2 of the 4 edges:
fromPoints(obs1, [-1, -1, -1], [1, -1, -1], [-1, 1, -1], [1, 1, -1])
*--*
\/
/\
*--*
I did rewrite for no intersection ...
console.log(plane.fromPoints([], [-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1]))
*--*
| |
| |
*--*
... and indeed non-null normal gets returned in first three components:
[
0,
0,
1,
-1
]
With your new function for the general case a wontfix for this function would be OK. But only with updating doc stating that no "intersections" in the plane are allowed: https://jscad.app/docs/module-modeling_maths_plane.html#.fromPoints
@Hermann-SW thanks again for the feedback, and great discussion.
Expected Behavior
For new testcase
all pointes lie on plane z==-1, and the normalized normal vector returned should be either [0,0,-1] or [0,0,1].
Actual Behavior
Instead [0,0,0] is returned which cannot be a normal vector. Reason is that two times normal vector computed in loop is [0,0,1], and two times it is [0,0,-1], and summation cancels them 0 as [0,0,0]. Summaion is just wrong.
Steps to Reproduce the Problem
run
use "t.is(obs5, [0, 0, 1, -1])" instead to see that indeed invalid [0,0,0] is returned as normal
Specifications