|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
use super::SVGUnit;
|
|
|
|
|
use derive_more::From;
|
|
|
|
|
use err_derive::Error;
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
use regex::Regex;
|
|
|
|
|
use std::cmp::Ordering;
|
|
|
|
@ -35,15 +35,18 @@ impl SVGMeasure {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(From, Debug)]
|
|
|
|
|
pub enum SVGUnitParseError {
|
|
|
|
|
ParseMeasure(ParseFloatError),
|
|
|
|
|
ParseUnit(ParseError),
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
|
pub enum SVGMeasureParseError {
|
|
|
|
|
#[error(display = "Failed to parse measure number")]
|
|
|
|
|
ParseMeasure(#[source] ParseFloatError),
|
|
|
|
|
#[error(display = "Failed to parse measure unit")]
|
|
|
|
|
ParseUnit(#[source] ParseError),
|
|
|
|
|
#[error(display = "Invalid measure format")]
|
|
|
|
|
Invalid,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl FromStr for SVGMeasure {
|
|
|
|
|
type Err = SVGUnitParseError;
|
|
|
|
|
type Err = SVGMeasureParseError;
|
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
|
|
|
if s == "0" {
|
|
|
|
|
return Ok(SVGMeasure::new(0.0, SVGUnit::Pixel));
|
|
|
|
@ -56,11 +59,19 @@ impl FromStr for SVGMeasure {
|
|
|
|
|
let unit = captures[2].parse::<SVGUnit>()?;
|
|
|
|
|
Ok(SVGMeasure::new(measure, unit))
|
|
|
|
|
} else {
|
|
|
|
|
Err(SVGUnitParseError::Invalid)
|
|
|
|
|
Err(SVGMeasureParseError::Invalid)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'s> TryFrom<&'s str> for SVGMeasure {
|
|
|
|
|
type Error = SVGMeasureParseError;
|
|
|
|
|
|
|
|
|
|
fn try_from(value: &'s str) -> Result<Self, Self::Error> {
|
|
|
|
|
Self::from_str(value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const EQ_TOLERANCE: f64 = 0.00001;
|
|
|
|
|
|
|
|
|
|
impl PartialEq for SVGMeasure {
|
|
|
|
|