feat: Implement note positioning logic and tests for position conversion

This commit is contained in:
2026-05-22 17:31:40 +02:00
parent cdfd4f9342
commit 729e575a60
6 changed files with 228 additions and 87 deletions
+46
View File
@@ -0,0 +1,46 @@
const int notePositionScale = 10;
const int notePositionStep = 1000 * notePositionScale;
const int notePositionRebalanceThreshold = 1;
int toStoredNotePosition(double position) {
return (position * notePositionScale).round();
}
double fromStoredNotePosition(int storedPosition) {
return storedPosition / notePositionScale;
}
int nextTopNotePosition(Iterable<int> storedPositions) {
int? highestPosition;
for (final int position in storedPositions) {
if (highestPosition == null || position > highestPosition) {
highestPosition = position;
}
}
if (highestPosition == null) {
return 0;
}
return highestPosition + notePositionStep;
}
int? midpointNotePosition({
required int higherPosition,
required int lowerPosition,
}) {
final int gap = higherPosition - lowerPosition;
if (gap <= notePositionRebalanceThreshold) {
return null;
}
return lowerPosition + (gap ~/ 2);
}
List<int> rebalanceNotePositions(int itemCount) {
return List<int>.generate(
itemCount,
(int index) => (itemCount - 1 - index) * notePositionStep,
);
}