Remove trailing zeros in rendered SVG path output

This commit is contained in:
Keavon Chambers
2025-01-13 02:56:33 -08:00
parent 8dfdc2b98f
commit 1e62af88cd
4 changed files with 44 additions and 17 deletions
+13
View File
@@ -2,6 +2,7 @@ use crate::consts::{MAX_ABSOLUTE_DIFFERENCE, STRICT_MAX_ABSOLUTE_DIFFERENCE};
use crate::{ManipulatorGroup, Subpath};
use glam::{BVec2, DMat2, DVec2};
use std::fmt::Write;
#[derive(Copy, Clone, PartialEq)]
/// A structure which can be used to reference a particular point along a `Bezier`.
@@ -294,6 +295,18 @@ pub fn compute_circular_subpath_details<PointId: crate::Identifier>(left: DVec2,
)
}
pub fn format_point(svg: &mut String, prefix: &str, x: f64, y: f64) -> std::fmt::Result {
write!(svg, "{prefix}{:.6}", x)?;
let trimmed_length = svg.trim_end_matches('0').trim_end_matches('.').len();
svg.truncate(trimmed_length);
write!(svg, ",{:.6}", y)?;
let trimmed_length = svg.trim_end_matches('0').trim_end_matches('.').len();
svg.truncate(trimmed_length);
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;