Use redundancy test

This commit is contained in:
Alchyr
2020-04-08 01:42:35 -07:00
parent 66a474619c
commit 65823fb2e1
7 changed files with 32 additions and 10 deletions

View File

@ -25,6 +25,14 @@ namespace osu.Game.Beatmaps.ControlPoints
/// <returns>Whether equivalent.</returns>
public abstract bool EquivalentTo(ControlPoint other);
/// <summary>
/// Whether this control point results in a meaningful change when placed after another.
/// </summary>
/// <param name="other">Another control point to compare with.</param>
/// <param name="time">The time this timing point will be placed at.</param>
/// <returns>Whether redundant.</returns>
public abstract bool IsRedundant(ControlPoint other, double time);
public bool Equals(ControlPoint other) => Time == other?.Time && EquivalentTo(other);
}
}

View File

@ -247,7 +247,7 @@ namespace osu.Game.Beatmaps.ControlPoints
break;
}
return existing?.EquivalentTo(newPoint) == true;
return newPoint.IsRedundant(existing, time);
}
private void groupItemAdded(ControlPoint controlPoint)

View File

@ -29,5 +29,6 @@ namespace osu.Game.Beatmaps.ControlPoints
public override bool EquivalentTo(ControlPoint other) =>
other is DifficultyControlPoint otherTyped && otherTyped.SpeedMultiplier.Equals(SpeedMultiplier);
public override bool IsRedundant(ControlPoint other, double time) => EquivalentTo(other);
}
}

View File

@ -38,5 +38,6 @@ namespace osu.Game.Beatmaps.ControlPoints
public override bool EquivalentTo(ControlPoint other) =>
other is EffectControlPoint otherTyped &&
KiaiMode == otherTyped.KiaiMode && OmitFirstBarLine == otherTyped.OmitFirstBarLine;
public override bool IsRedundant(ControlPoint other, double time) => !OmitFirstBarLine && EquivalentTo(other);
}
}

View File

@ -71,5 +71,6 @@ namespace osu.Game.Beatmaps.ControlPoints
public override bool EquivalentTo(ControlPoint other) =>
other is SampleControlPoint otherTyped &&
SampleBank == otherTyped.SampleBank && SampleVolume == otherTyped.SampleVolume;
public override bool IsRedundant(ControlPoint other, double time) => EquivalentTo(other);
}
}

View File

@ -50,6 +50,10 @@ namespace osu.Game.Beatmaps.ControlPoints
public override bool EquivalentTo(ControlPoint other) =>
other is TimingControlPoint otherTyped
&& Time == otherTyped.Time && TimeSignature == otherTyped.TimeSignature && BeatLength.Equals(otherTyped.BeatLength);
&& TimeSignature == otherTyped.TimeSignature && BeatLength.Equals(otherTyped.BeatLength);
public override bool IsRedundant(ControlPoint other, double time) =>
EquivalentTo(other)
&& other.Time == time;
}
}