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

Horrible hack to work around bug in OCCT7.7.2 #15931

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

bgbsww
Copy link
Contributor

@bgbsww bgbsww commented Aug 17, 2024

Fix #15599.

The failure is actually in cone, and represents a bug in 7.7.2 but not 7.6.3 and not 7.8.x. Angle values of 360.0 fail completely, 359.9999 and 359.999 partially, and 359.99 results in an ugly fix.

If it isn't clear, I hate this code, but it seems like the pragmatic best choice; the alternative is FreeCADs with 7.7.2 don't work with cones of 360 degrees. I'm gonna take a bath now.

@github-actions github-actions bot added the Mod: Part Related to the Part Workbench label Aug 17, 2024
@maxwxyz maxwxyz added this to the 1.0 milestone Aug 18, 2024
@@ -665,7 672,7 @@ App::DocumentObjectExecReturn *Cone::execute()
BRepPrimAPI_MakeCone mkCone(Radius1.getValue(),
Radius2.getValue(),
Height.getValue(),
Angle.getValue()/180.0f*M_PI);
angle/180.0f*M_PI);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: maybe use Base::toRadians, as elsewhere in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely a legitimate point, but M_PI / 180 appears about 68 times, and 180 / M_PI appears 10 times, and 180 * M_PI appears 9 times and 180.0f*M_PI appears 9 times (8 in this very file) ... you get the point. I think that should be somebody's separate PR to clean up all the angle/radian conversions, and not part of this extremely narrowly focused piece of nastiness, since there isn't a clear line on where to stop. Just this one? This one and the one in the clause above it? All of them in this file? All of them in App?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point and I agree that this very OCCT workaround should not be mixed with general cleanup.
However, if I touch a line of code anyway, I can "touch it for the better". -- Your mileage may vary and I accept that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are quite right, and I appreciate the review. I value consistency over prettiness, and since this specific improvement would work against consistency unless at a minimum the other M_PI usage in the same method were changed, that means (to me) that "better" is relative. Again, I do think that an en-mass change of all of these, or at least a file-by-file change of all of these makes sense, and I might even do it - just not as part of this one very narrow PR. There are a lot of M_PI in combination with constants of 2, 3 ,4 ,12 and 180 that look ripe for improvement to me, and at the very least, not enough M_PI2. This conversation is more about what principles apply and make sense and not the specific change, and I'm glad you triggered it. As you point out, it is a varying perspectives kind of thing. Thanks! I could definitely see a non-critical bug filed for "Refactor PI times a constant math expressions out of the source code". In fact, the general category of code beautification bugs makes sense to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbaehr can you make an Issue for that? We can discuss in tomorrow's review meeting, but I'm inclined to merge this as-is and then promote a bigger-picture refactor to make the suggested change.

@yorikvanhavre yorikvanhavre merged commit 60640fa into FreeCAD:main Aug 26, 2024
9 checks passed
@bgbsww bgbsww deleted the bgbsww-toponamingFixBug15599 branch August 26, 2024 17:39
@wwmayer
Copy link
Contributor

wwmayer commented Oct 16, 2024

Such ugly workarounds should really be avoided because they don't fix anything but move problems from A to B. Only because a cone with an angle of 359.99 seems to work here doesn't mean that the cone feature (or the BRepPrimAPI_MakeCone algorithm, respectively) is to blame. After all it's still the boolean operation that causes the problem.

Now the first regressions of this workaround can be seen here:

@yorikvanhavre
Copy link
Member

Do you feel we should revert this one, @wwmayer ?

@wwmayer
Copy link
Contributor

wwmayer commented Oct 16, 2024

Yes.

The problem reported in #15599. is not because of a bug in the cone creation but in the boolean operation. And when reading further this problem doesn't only occur with OCC 7.7.2 but also with 7.8.1.

And as Syres916 correctly figured out it's a problem with co-planar faces. And this is a general problem with OCC we very frequently see with boolean operations.

Btw , a much better workaround than using an angle of 359.99 is to rotate the cone around its main axis. It suffices to rotate it a tiny bit but I recommend to rotate it by 90 deg because then the seam edge is not so visible. And the nice side-effect is that even the geometry checker doesn't find any defects in the shape any more while with this PR it still finds defects.

@wwmayer
Copy link
Contributor

wwmayer commented Oct 16, 2024

Here is an interesting reading about the failure of boolean operations: https://wiki.mcneel.com/rhino/booleanfaq
The problems are the same in OCC.

@FlachyJoe
Copy link
Contributor

FlachyJoe commented Oct 16, 2024

OCC can't merge coplanar face but can fill a hole between them (see fuzzy value) so we could create a hole.
Maybe we should hack all shapes to reduce their size and set the Fuzzy equal to the shrink, we can get the correct result size next by setting its Tolerance.

EDIT: @wwmayer OCC have interesting doc too: https://dev.opencascade.org/doc/overview/html/specification__boolean_operations.html#autotoc_md293

@yorikvanhavre
Copy link
Member

Here is an interesting reading about the failure of boolean operations: https://wiki.mcneel.com/rhino/booleanfaq

That's a very interesting document!! We should link that in our FAQ somewhere...

Ok I'll prepare a PR to revert this one.

Btw , a much better workaround than using an angle of 359.99 is to rotate the cone around its main axis. It suffices to rotate it a tiny bit but I recommend to rotate it by 90 deg because then the seam edge is not so visible. And the nice side-effect is that even the geometry checker doesn't find any defects in the shape any more while with this PR it still finds defects.

Can you make a PR for that? Otherwise I can try too, but not sure where it should be done... Not at cone creation ,right?

@wwmayer
Copy link
Contributor

wwmayer commented Oct 17, 2024

Can you make a PR for that? Otherwise I can try too, but not sure where it should be done... Not at cone creation ,right?

This isn't something that should be coded but it must be done by the user. As explained in the Rhino FAQ the user must be aware of the problems with boolean operations and he has to help the kernel to do its job right.

@yorikvanhavre
Copy link
Member

Ok I see... You mean if there are problems with coinciding faces/edges. the user should move something, change something or as in your example, rotate the cone slightly. But it's not us who should arbitrarily rotate a cone to hypothetically prevent a possible boolean problem. Indeed that makes sense to me too. In most other cases which don't involve booleans, the user will expect the topology to be correctly aligned by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Mod: Part Related to the Part Workbench
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Regression] Boolean failures with OCC 7.7.2
8 participants