-
Notifications
You must be signed in to change notification settings - Fork 469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An unexpected situation occurred when using path. toSVG(), where NaN caused text rendering errors #673
Comments
Thanks for reporting this! |
Hi - This happens when a number very close above an integer is given as input, e.g. the float version of the number 18: const roundedDecimalPart =
+(Math.round(decimalPart * (Math.pow(10, places))) *
(Math.pow(10, -places))); |
@Connum have we looked into this? |
Recently, while testing the file again, I accidentally encountered several rendering failures after using toSVG() for text. The path data is shown in the figure:
![Snipaste_2024-02-04_15-14-05](https://private-user-images.githubusercontent.com/151488259/302085485-35b60461-7bde-4c9a-a21b-996c7b5ef6a0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyMjY4MDksIm5iZiI6MTcyMTIyNjUwOSwicGF0aCI6Ii8xNTE0ODgyNTkvMzAyMDg1NDg1LTM1YjYwNDYxLTdiZGUtNGM5YS1hMjFiLTk5NmM3YjVlZjZhMC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxN1QxNDI4MjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lZTA3NTIzOTgwYTczYjJlODQ4OGNkYjVjZWI1ODYwZDlmNzU5YzdmZDc2ZTc1MDhiNmI4Y2I2ZWUzYTBhNTk1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.RmtirIS_W9xRtUgn2Eg45R7K7YO1UWFm0EHB-wXun5s)
Then I briefly analyzed the problem and its corresponding source code, and found out where the problem lies:
![Snipaste_2024-02-04_15-18-11](https://private-user-images.githubusercontent.com/151488259/302085546-58633705-1996-4fb3-b28f-177a822cf089.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyMjY4MDksIm5iZiI6MTcyMTIyNjUwOSwicGF0aCI6Ii8xNTE0ODgyNTkvMzAyMDg1NTQ2LTU4NjMzNzA1LTE5OTYtNGZiMy1iMjhmLTE3N2E4MjJjZjA4OS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxN1QxNDI4MjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zMDc1OTAzYzQwMjhjYzVkZDAwYjMwOWMxYjM4NDhmMDVjOTcwOWZiNDhjNDkwZGUwMzc3Y2IyZTQ1ZDIzN2U4JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.eCeQz-HIRoroAD9NvzOO7ldD88BpHBI_PJh3KAJ9LRU)
![Snipaste_2024-02-04_15-19-12](https://private-user-images.githubusercontent.com/151488259/302085696-d85881f3-fa4f-48c3-8dfe-063309c3a535.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyMjY4MDksIm5iZiI6MTcyMTIyNjUwOSwicGF0aCI6Ii8xNTE0ODgyNTkvMzAyMDg1Njk2LWQ4NTg4MWYzLWZhNGYtNDhjMy04ZGZlLTA2MzMwOWMzYTUzNS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxN1QxNDI4MjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1kNTY5N2VjNWI2MzNjMDM2OTFlZDFjNzdmNTQwZWY4NmQwNzAzNTE3YzU3YWJjYjczMGQyNDg1NzFiZWYyMjFiJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.qkgaY46Sg4-F7XKHjaCEpA0UkHzuePTCAB5XbN_NTZw)
Because JS uses Scientific notation by default for floating point numbers with large numbers of digits, according to the previous code writing method, a NaN will be returned here, resulting in an error in the path. I think that although the probability of this situation is relatively low, it should also be considered.
My personal suggestion is that if I want to solve this problem without refactoring the original code, I try to use tofix () to prevent js from using Scientific notation, and the accuracy parameters are controlled by the user to ensure correctness. After my simple test, I found that this problem can be effectively solved.
![Snipaste_2024-02-04_15-19-28](https://private-user-images.githubusercontent.com/151488259/302085811-1f628427-286a-49e2-ae9b-bbb172511470.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjEyMjY4MDksIm5iZiI6MTcyMTIyNjUwOSwicGF0aCI6Ii8xNTE0ODgyNTkvMzAyMDg1ODExLTFmNjI4NDI3LTI4NmEtNDllMi1hZTliLWJiYjE3MjUxMTQ3MC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzE3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxN1QxNDI4MjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xZWQxOWE3NjI0OGIxNzY4ZTE1N2Q3NzFlNGM5ZTBmYWU0MTdhYjFhNWQzYTg1ZGIwNTc0MTIxOGNlY2Q2MGQyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.Zdpv3t2OEGxNkO4GyFIe-26XXnDsblsK9MBUQgv4sPM)
So, does anyone have better suggestions or methods?
The text was updated successfully, but these errors were encountered: