From 0c06709fefc53630b9a9667db30b5f010e89e28f Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Mon, 15 Jul 2024 13:35:01 -0500 Subject: [PATCH] update --- core/src/ops/absmod.rs | 45 ----------------- core/src/ops/arith.rs | 84 +++++++++++++++++++++++++++++++ core/src/ops/mod.rs | 2 + core/src/pitch/impls/pitch_ops.rs | 4 +- core/src/pitch/pitch.rs | 9 ++-- 5 files changed, 94 insertions(+), 50 deletions(-) create mode 100644 core/src/ops/arith.rs diff --git a/core/src/ops/absmod.rs b/core/src/ops/absmod.rs index a8d3ddc..0604f04 100644 --- a/core/src/ops/absmod.rs +++ b/core/src/ops/absmod.rs @@ -59,51 +59,6 @@ where use core::ops::{Add, Rem}; use num::traits::{Num, Signed}; -pub trait Floor { - type Output; - - fn floor(self) -> Self::Output; -} - -pub trait FloorDiv { - type Output; - - fn floor_div(self, rhs: Rhs) -> Self::Output; -} - -macro_rules! impl_floor_div { - (@float $t:ty) => { - impl FloorDiv for $t where $t: ::core::ops::Div { - type Output = O; - - fn floor_div(self, rhs: T) -> Self::Output { - (self / rhs).floor() - } - } - }; - (@impl f32) => { - impl_floor_div!(@float f32); - }; - (@impl f64) => { - impl_floor_div!(@float f64); - }; - (@impl $t:ty) => { - impl FloorDiv for $t where $t: ::core::ops::Div { - type Output = O; - - fn floor_div(self, rhs: T) -> Self::Output { - self / rhs - } - } - }; - ($($t:ty),*) => { - $( - impl_floor_div!(@impl $t); - )* - }; -} - -impl_floor_div!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64); impl PyMod for T where diff --git a/core/src/ops/arith.rs b/core/src/ops/arith.rs new file mode 100644 index 0000000..b250321 --- /dev/null +++ b/core/src/ops/arith.rs @@ -0,0 +1,84 @@ +/* + Appellation: arith + Contrib: FL03 +*/ + +pub trait Floor { + type Output; + + fn floor(self) -> Self::Output; +} + +pub trait FloorDiv { + type Output; + + fn floor_div(self, rhs: Rhs) -> Self::Output; +} + + +macro_rules! impl_floor { + (@base $t:ty) => { + impl Floor for $t { + type Output = $t; + + fn floor(self) -> Self::Output { + <$t>::floor(self) + } + } + }; + (@impl f32) => { + impl_floor!(@base f32); + }; + (@impl f64) => { + impl_floor!(@base f64); + }; + (@impl $t:ty) => { + impl Floor for $t { + type Output = $t; + + fn floor(self) -> Self::Output { + self + } + } + }; + ($($t:ty),*) => { + $( + impl_floor!(@impl $t); + )* + }; +} + +macro_rules! impl_floor_div { + (@float $t:ty) => { + impl FloorDiv for $t where $t: ::core::ops::Div { + type Output = O; + + fn floor_div(self, rhs: T) -> Self::Output { + (self / rhs).floor() + } + } + }; + (@impl f32) => { + impl_floor_div!(@float f32); + }; + (@impl f64) => { + impl_floor_div!(@float f64); + }; + (@impl $t:ty) => { + impl FloorDiv for $t where $t: ::core::ops::Div { + type Output = O; + + fn floor_div(self, rhs: T) -> Self::Output { + self / rhs + } + } + }; + ($($t:ty),*) => { + $( + impl_floor_div!(@impl $t); + )* + }; +} + +impl_floor!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64); +impl_floor_div!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64); \ No newline at end of file diff --git a/core/src/ops/mod.rs b/core/src/ops/mod.rs index 1c59191..8de19eb 100644 --- a/core/src/ops/mod.rs +++ b/core/src/ops/mod.rs @@ -6,9 +6,11 @@ pub use self::prelude::*; pub mod absmod; +pub mod arith; pub mod distance; pub(crate) mod prelude { pub use super::absmod::*; + pub use super::arith::*; pub use super::distance::*; } diff --git a/core/src/pitch/impls/pitch_ops.rs b/core/src/pitch/impls/pitch_ops.rs index 2f69eb8..8da7226 100644 --- a/core/src/pitch/impls/pitch_ops.rs +++ b/core/src/pitch/impls/pitch_ops.rs @@ -2,7 +2,7 @@ Appellation: pitch_ops Contrib: FL03 */ -use crate::{Pitch, PitchMod, PitchTy}; +use crate::{Pitch, PitchMod, PitchTy, PyMod}; use num::{Num, One, Zero}; macro_rules! impl_interval_method { @@ -33,7 +33,7 @@ impl PitchMod for Pitch { type Output = Self; fn pitchmod(&self) -> Self::Output { - Self(self.0.pitchmod()) + Self(self.0.pymod(Self::MOD)) } } diff --git a/core/src/pitch/pitch.rs b/core/src/pitch/pitch.rs index 158fa43..14e2d64 100644 --- a/core/src/pitch/pitch.rs +++ b/core/src/pitch/pitch.rs @@ -3,7 +3,7 @@ Contrib: FL03 */ use super::{PitchTy, Pitches}; -use crate::PitchMod; +use crate::PyMod; /// A [pitch](Pitch) is a discrete tone with an individual frequency that may be /// classified as a [pitch class](Pitches). @@ -13,12 +13,15 @@ use crate::PitchMod; pub struct Pitch(pub(crate) PitchTy); impl Pitch { + const MOD: PitchTy = crate::MODULUS; + pub fn new(pitch: impl Into) -> Self { - Self(pitch.into().pitchmod()) + let val: PitchTy = pitch.into(); + Self(val.pymod(Self::MOD)) } /// Returns the absolute value of the remainder of the pitch divided by the modulus. pub fn abs(&self) -> Self { - self.pitchmod() + Self(self.0.pymod(Self::MOD).abs()) } /// Returns a new instance of the class representing the given pitch. pub fn class(&self) -> Pitches {