Ultimaker / CuraEngine

Powerful, fast and robust engine for converting 3D models into g-code instructions for 3D printers. It is part of the larger open source project Cura.
https://ultimaker.com/en/products/cura-software
GNU Affero General Public License v3.0
1.69k stars 887 forks source link

refactor-improve-math-functions #2135

Closed 0x5844 closed 2 months ago

0x5844 commented 3 months ago

Description

This pull request addresses a critical issue in the math.h utility functions related to incorrect rounding behavior in the ceil_divide_signed function. Specifically, it fixes a bug where the function would incorrectly round up even when the division was exact, such as returning 31 instead of 30 for ceil_divide_signed(90, 3) -> (https://github.com/Ultimaker/CuraEngine/issues/2005)

Additionally, the PR includes the following improvements:

Type of change

How Has This Been Tested?

Test Configuration:

Checklist:

0x5844 commented 2 months ago

Thanks for this! You know the current team-size, so we really appreciate these PR's 😄

--

I've made a few changes, most notably, I've removed the exception throwing after a discussion with Erwan:

Throwing exceptions means you rely on the code around that to be set up for that, which it currently is not. If we only want to know where it crashed, then we can just rely on SIGFPE to be signalled on division-by-zero (which is almost the only case where FPE happens anyway).

If we want to use exceptions in the code in general, we should have that discussion, but introducing this into a PR that fixes other stuff is not a good idea (especially in the same commit). -- Even then I'm on the fence on these particular functions, which should be basic math-ops.

That sounds great! I was on the fence about throwing exceptions but I went forward with it. I updated the tests under https://github.com/Ultimaker/CuraEngine/pull/2135/commits/953714c469fba494f6e21df85cb77f734560b4d6 and removed the exception expectation from them.

rburema commented 2 months ago

That sounds great! I was on the fence about throwing exceptions but I went forward with it.

That's what we have reviews for!

Dumping some info here since I'm off until next Tuesday:

0x5844 commented 2 months ago

Dumping some info here since I'm off until next Tuesday:

Let me know if I can help with anything!