diff options
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/length.rs | 10 | ||||
| -rw-r--r-- | src/geom/relative.rs | 7 | ||||
| -rw-r--r-- | src/geom/size.rs | 10 |
3 files changed, 26 insertions, 1 deletions
diff --git a/src/geom/length.rs b/src/geom/length.rs index f4d8682e..bfb1d668 100644 --- a/src/geom/length.rs +++ b/src/geom/length.rs @@ -81,6 +81,16 @@ impl Length { Self { raw: self.raw.max(other.raw) } } + /// Whether the length is finite. + pub fn is_finite(self) -> bool { + self.raw.is_finite() + } + + /// Whether the length is infinite. + pub fn is_infinite(self) -> bool { + self.raw.is_infinite() + } + /// Whether the length is `NaN`. pub fn is_nan(self) -> bool { self.raw.is_nan() diff --git a/src/geom/relative.rs b/src/geom/relative.rs index 8fd430af..d39ead3a 100644 --- a/src/geom/relative.rs +++ b/src/geom/relative.rs @@ -26,7 +26,12 @@ impl Relative { /// Resolve this relative to the given `length`. pub fn resolve(self, length: Length) -> Length { - self.get() * length + // Zero wins over infinity. + if self.0 == 0.0 { + Length::ZERO + } else { + self.get() * length + } } } diff --git a/src/geom/size.rs b/src/geom/size.rs index 1dfc8b97..caba3d8b 100644 --- a/src/geom/size.rs +++ b/src/geom/size.rs @@ -31,6 +31,16 @@ impl Size { self.width >= other.width && self.height >= other.height } + /// Whether both components are finite. + pub fn is_finite(self) -> bool { + self.width.is_finite() && self.height.is_finite() + } + + /// Whether any of the two components is infinite. + pub fn is_infinite(self) -> bool { + self.width.is_infinite() || self.height.is_infinite() + } + /// Whether any of the two components is `NaN`. pub fn is_nan(self) -> bool { self.width.is_nan() || self.height.is_nan() |
