Skip to content

Added arithmetic safety and unit tests to Plotters Backend#738

Open
RPG-Alex wants to merge 25 commits intoplotters-rs:masterfrom
RPG-Alex:master
Open

Added arithmetic safety and unit tests to Plotters Backend#738
RPG-Alex wants to merge 25 commits intoplotters-rs:masterfrom
RPG-Alex:master

Conversation

@RPG-Alex
Copy link
Copy Markdown

@RPG-Alex RPG-Alex commented May 5, 2026

I started looking at what needed to be done to rectify issue #709 , and realized this bug was possible in pretty much every part of the crate, as there is a lot of unchecked math happening.

In the plotters_backend module, I have added math_guard, and math_error, for trying to simplify the most common arithmetic operations. I also cleaned up the errors for the backend, as there were 2 enums and 1 struct with the same name, so abstracted all to a single error enum and converted instances of the struct version to the correct enum.

Before applying the math_guard to the whole crate I wanted to see if the shape and implementation would be acceptable.

I also added unit tests to all modules, to help make sure I wasn't breaking anything with the refactor.

Right now the backend should be in a position where it will handle errors around unsafe math rather than panicking. If this looks acceptable please merge the PR and let me know so I can continue with the refactor for the rest of the crate to use math_guard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant