Fix bug where rasterize() hangs on Apple silicon #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
Thanks for writing fauxgl, I've found it very useful. I ran into a problem when running my project on an Apple silicon laptop. Please consider this patch which fixes the problem.
If any edges of the triangle are horizontal or vertical, it's possible
for the raXX variables, and thus d, to get a division by zero leading
to +Inf. On Intel, when +Inf is converted to int and back with
d = float64(int(d))
the result is a very large negative number which the existing check
converts to zero. On ARM (or at least on Apple Silicon which is where I
ran into the problem) the result is a very large positive number,
causing the function to hang.
You can verify this with the following small fragment of code:
var one float64 = 1
var zero float64 = 0
var divZero float64 = one / zero
var castAndCastBack = float64(int(divZero))
fmt.Printf("%f\n", castAndCastBack)
On an Intel CPU that will print a very large negative number, on Apple silicon a very large positive number.