mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-26 07:28:11 +08:00
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:
co-authored by
Keavon Chambers
parent
3ddc052538
commit
8a1089938e
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user