Fix non-integer array indexing in line drawing algorithm #2
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.
Summary
This pull request addresses an issue with non-integer array indexing in the line drawing algorithm within
ect.py
.Changes Made
image2[y, x] = color
withimage2[int(round(y)), int(round(x))] = color
.Reason for Change
The original indexing method using
image2[y, x] = color
can lead to runtime errors when non-integer values are provided fory
andx
. This is especially problematic when the coordinates are calculated from floating-point operations, which can result in non-integer values.By changing the indexing to
image2[int(round(y)), int(round(x))] = color
, we ensure that the coordinates are rounded to the nearest integers before being used for indexing. This modification prevents runtime errors and guarantees that the drawing function behaves consistently with the expected integer index requirements. The new method is more robust and handles various input scenarios better.Testing
To verify the changes, you can run the drawing function with both integer and non-integer inputs to ensure it behaves as expected without raising errors.