summaryrefslogtreecommitdiff
path: root/src/geom/relative.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-08 15:08:26 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-08 15:45:14 +0200
commit712c00ecb72b67da2c0788e5d3eb4dcc6366b2a7 (patch)
treef5d7ef4341a4728c980d020cc173fa6bb70feaff /src/geom/relative.rs
parent977ac77e6a3298be2644a8231e93acbef9f7f396 (diff)
Em units
Diffstat (limited to 'src/geom/relative.rs')
-rw-r--r--src/geom/relative.rs33
1 files changed, 21 insertions, 12 deletions
diff --git a/src/geom/relative.rs b/src/geom/relative.rs
index 066b8c15..fc77fb9f 100644
--- a/src/geom/relative.rs
+++ b/src/geom/relative.rs
@@ -27,12 +27,17 @@ impl<T: Numeric> Relative<T> {
/// Whether both parts are zero.
pub fn is_zero(self) -> bool {
- self.rel.is_zero() && self.abs.is_zero()
+ self.rel.is_zero() && self.abs == T::zero()
}
- /// Resolve this relative to the given `whole`.
- pub fn resolve(self, whole: T) -> T {
- self.rel.resolve(whole) + self.abs
+ /// Whether the relative part is one and the absolute part is zero.
+ pub fn is_one(self) -> bool {
+ self.rel.is_one() && self.abs == T::zero()
+ }
+
+ /// Evaluate this relative to the given `whole`.
+ pub fn relative_to(self, whole: T) -> T {
+ self.rel.of(whole) + self.abs
}
/// Map the absolute part with `f`.
@@ -120,27 +125,31 @@ impl<T: Numeric> Div<f64> for Relative<T> {
}
}
-impl<T: Numeric> AddAssign for Relative<T> {
+impl<T: Numeric + AddAssign> AddAssign for Relative<T> {
fn add_assign(&mut self, other: Self) {
- *self = *self + other;
+ self.rel += other.rel;
+ self.abs += other.abs;
}
}
-impl<T: Numeric> SubAssign for Relative<T> {
+impl<T: Numeric + SubAssign> SubAssign for Relative<T> {
fn sub_assign(&mut self, other: Self) {
- *self = *self - other;
+ self.rel -= other.rel;
+ self.abs -= other.abs;
}
}
-impl<T: Numeric> MulAssign<f64> for Relative<T> {
+impl<T: Numeric + MulAssign<f64>> MulAssign<f64> for Relative<T> {
fn mul_assign(&mut self, other: f64) {
- *self = *self * other;
+ self.rel *= other;
+ self.abs *= other;
}
}
-impl<T: Numeric> DivAssign<f64> for Relative<T> {
+impl<T: Numeric + DivAssign<f64>> DivAssign<f64> for Relative<T> {
fn div_assign(&mut self, other: f64) {
- *self = *self * other;
+ self.rel /= other;
+ self.abs /= other;
}
}