diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-22 17:16:42 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-22 17:16:42 +0100 |
| commit | ac788f2082711161ec8208eede04d9a2bae02241 (patch) | |
| tree | b139e41d327af906163c0b177d402b855c04507e /src/geom | |
| parent | 0de4f3ed7bb20a94fd58f93b0793d3b5a8e13972 (diff) | |
Many more expressions 🥗
Boolean, equality, comparison and assignment expression parsing and evaluation.
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/length.rs | 5 | ||||
| -rw-r--r-- | src/geom/linear.rs | 6 | ||||
| -rw-r--r-- | src/geom/relative.rs | 7 |
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 { |
