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