Enhance pixel color detection in SensorsBlocks.js with improved error handling and additional utility methods#4545
Conversation
… handling and additional utility methods
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
I think these changes are good but a couple of questions. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
✅ All Jest tests passed! This PR is ready to merge. |
|
@walterbender |
… handling and additional utility methods (sugarlabs#4545) * fix localization strings for motion-y and get-protein in Arabic * Refactor text cleaning and translation retrieval in utils.js * Fix comment formatting in getTranslationWithCase function * Enhance pixel color detection in SensorsBlocks.js with improved error handling and additional utility methods * fix Eslint warnings * Add tests for the new methods in SensorsBlocks.js * fix eslint warning


Description
This PR refactors the
GetColorPixelBlockclass injs/blocks/SensorsBlocks.jsto improve its readability, robustness, and maintainability. These changes enhance the block’s color detection functionality and lay a foundation for future extensions.Changes Made
argmethod into helper functions (getTurtleSafely,getPixelData,detectColor,getBackgroundColor,getFallbackColor) for better readability and testability.try-catchblock to handle failures (e.g., missing turtle or canvas context), with a fallback to a default gray color (searchColors(128, 128, 128)).