diff --git a/crates/fj-math/src/scalar.rs b/crates/fj-math/src/scalar.rs index 4a8cb6454..a977fcf54 100644 --- a/crates/fj-math/src/scalar.rs +++ b/crates/fj-math/src/scalar.rs @@ -92,6 +92,11 @@ impl Scalar { self.0.max(other.into().0).into() } + /// Compute the largest integer smaller than or equal to this scalar + pub fn floor(self) -> Self { + self.0.floor().into() + } + /// Compute the smallest integer larger than or equal to this scalar pub fn ceil(self) -> Self { self.0.ceil().into() @@ -180,66 +185,78 @@ impl ops::Neg for Scalar { } } -impl ops::Add for Scalar { +impl> ops::Add for Scalar { type Output = Self; - fn add(self, rhs: Self) -> Self::Output { - self.0.add(rhs.0).into() + fn add(self, rhs: T) -> Self::Output { + self.0.add(rhs.into().0).into() } } -impl ops::AddAssign for Scalar { - fn add_assign(&mut self, rhs: Self) { - self.0.add_assign(rhs.0); - *self = Self::from_f64(self.0); +impl> ops::Sub for Scalar { + type Output = Self; + + fn sub(self, rhs: T) -> Self::Output { + self.0.sub(rhs.into().0).into() } } -impl ops::Sub for Scalar { +impl> ops::Mul for Scalar { type Output = Self; - fn sub(self, rhs: Self) -> Self::Output { - self.0.sub(rhs.0).into() + fn mul(self, rhs: T) -> Self::Output { + self.0.mul(rhs.into().0).into() } } -impl ops::Mul for Scalar { +impl> ops::Div for Scalar { type Output = Self; - fn mul(self, rhs: Self) -> Self::Output { - self.0.mul(rhs.0).into() + fn div(self, rhs: T) -> Self::Output { + self.0.div(rhs.into().0).into() } } -impl ops::Mul for Scalar { +impl> ops::Rem for Scalar { type Output = Self; - fn mul(self, rhs: f64) -> Self::Output { - self.0.mul(rhs).into() + fn rem(self, rhs: T) -> Self::Output { + self.0.rem(rhs.into().0).into() } } -impl ops::Div for Scalar { - type Output = Self; - - fn div(self, rhs: Self) -> Self::Output { - self.0.div(rhs.0).into() +impl> ops::AddAssign for Scalar { + fn add_assign(&mut self, rhs: T) { + self.0.add_assign(rhs.into().0); + *self = self.0.into(); } } -impl ops::Div for Scalar { - type Output = Self; +impl> ops::SubAssign for Scalar { + fn sub_assign(&mut self, rhs: T) { + self.0.sub_assign(rhs.into().0); + *self = self.0.into(); + } +} - fn div(self, rhs: f64) -> Self::Output { - self.0.div(rhs).into() +impl> ops::MulAssign for Scalar { + fn mul_assign(&mut self, rhs: T) { + self.0.mul_assign(rhs.into().0); + *self = self.0.into(); } } -impl ops::Rem for Scalar { - type Output = Self; +impl> ops::DivAssign for Scalar { + fn div_assign(&mut self, rhs: T) { + self.0.div_assign(rhs.into().0); + *self = self.0.into(); + } +} - fn rem(self, rhs: Self) -> Self::Output { - self.0.rem(rhs.0).into() +impl> ops::RemAssign for Scalar { + fn rem_assign(&mut self, rhs: T) { + self.0.rem_assign(rhs.into().0); + *self = self.0.into(); } }