Skip to content

Commit

Permalink
optimze GetVisbleTimelines_DesignMode()
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Dec 28, 2023
1 parent 28e0a8d commit d572473
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,8 @@ public static double ConvertAudioTimeToY_PreviewMode(TimeSpan audioTime, FumenVi
?? ConvertYToTGrid_DesignMode(minVisibleCanvasY + judgeLineOffsetY, soflans, bpmList, 1);

var timeSignatures = meterList.GetCachedAllTimeSignatureUniformPositionList(bpmList);
var currentTimeSignatureIndex = 0;
//快速定位,尽量避免计算完全不用画的timesignature(
for (int i = 0; i < timeSignatures.Count; i++)
{
var cur = timeSignatures[i];
if (cur.startTGrid > minVisibleCanvasTGrid)
break;
currentTimeSignatureIndex = i;
}
var currentTimeSignatureIndex = timeSignatures.LastOrDefaultIndexByBinarySearch(minVisibleCanvasTGrid, x => x.startTGrid);

//钦定好要画的起始timeSignatrue
(TimeSpan audioTime, TGrid startTGrid, MeterChange meter, BPMChange bpm) currentTimeSignature = timeSignatures[currentTimeSignatureIndex];
Expand Down
8 changes: 7 additions & 1 deletion OngekiFumenEditor/Utils/LinqExtensionMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,16 @@ private static int BinarySearchBy<T, X>(this IReadOnlyList<T> insertable, X valu
/// <param name="keySelect"></param>
/// <returns></returns>
public static T LastOrDefaultByBinarySearch<T, X>(this IList<T> source, X value, Func<T, X> keySelect) where X : IComparable<X>
{
var idx = source.LastOrDefaultIndexByBinarySearch(value, keySelect);
return source[idx];
}

public static int LastOrDefaultIndexByBinarySearch<T, X>(this IList<T> source, X value, Func<T, X> keySelect) where X : IComparable<X>
{
var idx = source.BinarySearchBy(value, keySelect);
var i = Math.Max(0, idx < 0 ? ((~idx) - 1) : idx);
return source[i];
return i;
}

public static T LastOrDefaultByBinarySearch<T, X>(this IReadOnlyList<T> source, X value, Func<T, X> keySelect) where X : IComparable<X>
Expand Down

0 comments on commit d572473

Please sign in to comment.