mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-12 18:26:00 +00:00
Improve error handling of Tolerance
This commit is contained in:
parent
518d51387d
commit
5f7ba6ae83
@ -184,11 +184,13 @@ impl Tolerance {
|
|||||||
/// Construct a `Tolerance` from a [`Scalar`]
|
/// Construct a `Tolerance` from a [`Scalar`]
|
||||||
///
|
///
|
||||||
/// Returns an error, if the passed scalar is not larger than zero.
|
/// Returns an error, if the passed scalar is not larger than zero.
|
||||||
pub fn from_scalar(scalar: impl Into<Scalar>) -> Result<Self, Scalar> {
|
pub fn from_scalar(
|
||||||
|
scalar: impl Into<Scalar>,
|
||||||
|
) -> Result<Self, InvalidTolerance> {
|
||||||
let scalar = scalar.into();
|
let scalar = scalar.into();
|
||||||
|
|
||||||
if scalar <= Scalar::ZERO {
|
if scalar <= Scalar::ZERO {
|
||||||
return Err(scalar);
|
return Err(InvalidTolerance(scalar));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Self(scalar))
|
Ok(Self(scalar))
|
||||||
@ -209,6 +211,10 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, thiserror::Error)]
|
||||||
|
#[error("Invalid tolerance ({0}); must be above zero")]
|
||||||
|
pub struct InvalidTolerance(Scalar);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use fj_math::{Point, Scalar};
|
use fj_math::{Point, Scalar};
|
||||||
|
Loading…
Reference in New Issue
Block a user