Path Bool library code cleanup (#2000)

* Remove log statements

* Add feature gates to functions in path.rs

* Fix infinite parsing loop and add new test

* License tweaks

* Remove trailing zero in whole number floats

* Flatten visual-tests directory

* Code review

* Clean up printlines

* Add error handling to path parsing

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert
2024-09-23 12:16:31 +02:00
committed by GitHub
co-authored by Keavon Chambers
parent 3ddc052538
commit 8a1089938e
175 changed files with 442 additions and 346 deletions
+7 -5
View File
@@ -1,9 +1,10 @@
use crate::path::{path_from_commands, path_to_commands, Path};
use crate::path_command::{AbsolutePathCommand, PathCommand, RelativePathCommand};
use crate::BooleanError;
use glam::DVec2;
use regex::Regex;
pub fn commands_from_path_data(d: &str) -> Vec<PathCommand> {
pub fn commands_from_path_data(d: &str) -> Result<Vec<PathCommand>, BooleanError> {
let re_float = Regex::new(r"^\s*,?\s*(-?\d*(?:\d\.|\.\d|\d)\d*(?:[eE][+\-]?\d+)?)").unwrap();
let re_cmd = Regex::new(r"^\s*([MLCSQTAZHVmlhvcsqtaz])").unwrap();
let re_bool = Regex::new(r"^\s*,?\s*([01])").unwrap();
@@ -24,6 +25,7 @@ pub fn commands_from_path_data(d: &str) -> Vec<PathCommand> {
match last_cmd {
'M' => Some('L'),
'm' => Some('l'),
'z' | 'Z' => None,
_ => Some(last_cmd),
}
}
@@ -111,15 +113,15 @@ pub fn commands_from_path_data(d: &str) -> Vec<PathCommand> {
get_float(&mut i),
get_float(&mut i),
))),
_ => panic!("Invalid command: {}", cmd),
_ => return Err(BooleanError::InvalidPathCommand(cmd)),
}
}
commands
Ok(commands)
}
pub fn path_from_path_data(d: &str) -> Path {
path_from_commands(commands_from_path_data(d)).collect()
pub fn path_from_path_data(d: &str) -> Result<Path, BooleanError> {
Ok(path_from_commands(commands_from_path_data(d)?).collect())
}
pub fn path_to_path_data(path: &Path, eps: f64) -> String {