Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:
- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Small bug in hexToColor (Evan Reese Utility)
photinos_design
Member Posts: 3 PRO
I found a small bug in @EvanReese's hexToColor FS. Seeing as it is linked over 5000 times, I think it's worth sharing.
Steps to reproduce:
- Using a simple Part Color custom feature, which takes in a hex value, converts the hex to a color using hexToColor, and applies the color to a part.
- Attempt to set a part to #0000FF
- Part gets set to #0000FE (very slightly off)
Why this happens:
- Hex values range from 00-FF, which in decimal is 0-255.
- Color type expects values from 0-1 (inclusive)
- To map [0, 255] → [0,1], values should be divided by 255
- hexToColor divides values by 256 instead, which results in FF being represented as 255/256, or 0.99609375 (not quite 1)
- This affects red and green channels as well, not just blue.
How to fix it:
- Replace 6 instances of 256 with 255, on lines 35-37 and 56-58 in V52
Thank you Evan for a very useful utility library, and I hope this small bug gets fixed soon!
Tagged:
0