added various From<_> implementations

This commit is contained in:
MaxOhn
2021-11-13 20:46:23 +01:00
parent 1a7127be7f
commit 0a0dd025f7
6 changed files with 103 additions and 6 deletions
+8 -6
View File
@@ -161,11 +161,13 @@ impl Curve {
let mut cumulative_len = Vec::with_capacity(path.len());
cumulative_len.push(0.0);
for (&curr, &next) in path.iter().zip(path.iter().skip(1)) {
let diff = next - curr;
calculated_len += diff.length() as f64;
cumulative_len.push(calculated_len);
}
let length_iter = path.iter().zip(path.iter().skip(1)).map(|(&curr, &next)| {
calculated_len += (next - curr).length() as f64;
calculated_len
});
cumulative_len.extend(length_iter);
if (expected_len - calculated_len).abs() > f64::EPSILON {
// * In osu-stable, if the last two control points of a slider are equal, extension is not performed
@@ -319,7 +321,7 @@ impl Curve {
let p = points.len();
let mut to_flatten = Vec::new();
let mut free_bufs = Vec::with_capacity(1);
let mut free_bufs = Vec::new();
// In osu!lazer's code, `p` is always 0 so the first big `if` can be omitted
+6
View File
@@ -661,6 +661,12 @@ impl FruitsPerformanceAttributes {
}
}
impl From<FruitsPerformanceAttributes> for FruitsDifficultyAttributes {
fn from(attributes: FruitsPerformanceAttributes) -> Self {
attributes.attributes
}
}
#[test]
// #[ignore]
fn custom_fruits() {
+71
View File
@@ -321,6 +321,34 @@ impl DifficultyAttributes {
}
}
#[cfg(feature = "fruits")]
impl From<fruits::FruitsDifficultyAttributes> for DifficultyAttributes {
fn from(attributes: fruits::FruitsDifficultyAttributes) -> Self {
Self::Fruits(attributes)
}
}
#[cfg(feature = "mania")]
impl From<mania::ManiaDifficultyAttributes> for DifficultyAttributes {
fn from(attributes: mania::ManiaDifficultyAttributes) -> Self {
Self::Mania(attributes)
}
}
#[cfg(feature = "osu")]
impl From<osu::OsuDifficultyAttributes> for DifficultyAttributes {
fn from(attributes: osu::OsuDifficultyAttributes) -> Self {
Self::Osu(attributes)
}
}
#[cfg(feature = "taiko")]
impl From<taiko::TaikoDifficultyAttributes> for DifficultyAttributes {
fn from(attributes: taiko::TaikoDifficultyAttributes) -> Self {
Self::Taiko(attributes)
}
}
/// The result of a performance calculation based on the mode.
#[derive(Clone, Debug)]
pub enum PerformanceAttributes {
@@ -380,6 +408,49 @@ impl PerformanceAttributes {
}
}
impl From<PerformanceAttributes> for DifficultyAttributes {
fn from(attributes: PerformanceAttributes) -> Self {
match attributes {
#[cfg(feature = "fruits")]
PerformanceAttributes::Fruits(attributes) => Self::Fruits(attributes.attributes),
#[cfg(feature = "mania")]
PerformanceAttributes::Mania(attributes) => Self::Mania(attributes.attributes),
#[cfg(feature = "osu")]
PerformanceAttributes::Osu(attributes) => Self::Osu(attributes.attributes),
#[cfg(feature = "taiko")]
PerformanceAttributes::Taiko(attributes) => Self::Taiko(attributes.attributes),
}
}
}
#[cfg(feature = "fruits")]
impl From<fruits::FruitsPerformanceAttributes> for PerformanceAttributes {
fn from(attributes: fruits::FruitsPerformanceAttributes) -> Self {
Self::Fruits(attributes)
}
}
#[cfg(feature = "mania")]
impl From<mania::ManiaPerformanceAttributes> for PerformanceAttributes {
fn from(attributes: mania::ManiaPerformanceAttributes) -> Self {
Self::Mania(attributes)
}
}
#[cfg(feature = "osu")]
impl From<osu::OsuPerformanceAttributes> for PerformanceAttributes {
fn from(attributes: osu::OsuPerformanceAttributes) -> Self {
Self::Osu(attributes)
}
}
#[cfg(feature = "taiko")]
impl From<taiko::TaikoPerformanceAttributes> for PerformanceAttributes {
fn from(attributes: taiko::TaikoPerformanceAttributes) -> Self {
Self::Taiko(attributes)
}
}
#[cfg(any(feature = "osu", feature = "taiko"))]
#[inline]
fn difficulty_range(val: f64, max: f64, avg: f64, min: f64) -> f64 {
+6
View File
@@ -197,3 +197,9 @@ impl ManiaPerformanceAttributes {
self.pp
}
}
impl From<ManiaPerformanceAttributes> for ManiaDifficultyAttributes {
fn from(attributes: ManiaPerformanceAttributes) -> Self {
attributes.attributes
}
}
+6
View File
@@ -587,6 +587,12 @@ impl OsuPerformanceAttributes {
}
}
impl From<OsuPerformanceAttributes> for OsuDifficultyAttributes {
fn from(attributes: OsuPerformanceAttributes) -> Self {
attributes.attributes
}
}
#[inline]
fn difficulty_range_od(od: f64) -> f64 {
super::difficulty_range(od, 20.0, 50.0, 80.0)
+6
View File
@@ -291,3 +291,9 @@ impl TaikoPerformanceAttributes {
self.pp
}
}
impl From<TaikoPerformanceAttributes> for TaikoDifficultyAttributes {
fn from(attributes: TaikoPerformanceAttributes) -> Self {
attributes.attributes
}
}