summaryrefslogtreecommitdiff
path: root/src/geom
diff options
context:
space:
mode:
Diffstat (limited to 'src/geom')
-rw-r--r--src/geom/length.rs5
-rw-r--r--src/geom/linear.rs6
-rw-r--r--src/geom/relative.rs7
3 files changed, 14 insertions, 4 deletions
diff --git a/src/geom/length.rs b/src/geom/length.rs
index 1a45c63c..db28761b 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -81,6 +81,11 @@ impl Length {
Self { raw: self.raw.max(other.raw) }
}
+ /// Whether the length is zero.
+ pub fn is_zero(self) -> bool {
+ self.raw == 0.0
+ }
+
/// Whether the length is finite.
pub fn is_finite(self) -> bool {
self.raw.is_finite()
diff --git a/src/geom/linear.rs b/src/geom/linear.rs
index 5638517b..05990096 100644
--- a/src/geom/linear.rs
+++ b/src/geom/linear.rs
@@ -26,9 +26,9 @@ impl Linear {
self.rel.resolve(length) + self.abs
}
- /// Whether this linear's relative part is zero.
- pub fn is_absolute(self) -> bool {
- self.rel == Relative::ZERO
+ /// Whether both parts are zero.
+ pub fn is_zero(self) -> bool {
+ self.rel.is_zero() && self.abs.is_zero()
}
}
diff --git a/src/geom/relative.rs b/src/geom/relative.rs
index e91ea672..cea7e4e3 100644
--- a/src/geom/relative.rs
+++ b/src/geom/relative.rs
@@ -27,12 +27,17 @@ impl Relative {
/// Resolve this relative to the given `length`.
pub fn resolve(self, length: Length) -> Length {
// Zero wins over infinity.
- if self.0 == 0.0 {
+ if self.is_zero() {
Length::ZERO
} else {
self.get() * length
}
}
+
+ /// Whether the ratio is zero.
+ pub fn is_zero(self) -> bool {
+ self.0 == 0.0
+ }
}
impl Display for Relative {