Skip to content

Commit 8faa941

Browse files
committed
refactor: Improve readability by adding parentheses in mathematical expressions
1 parent e3e38f3 commit 8faa941

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

src/Render/NodeRenderer.Layout.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private static (float Main, float Cross) ResolveStackContentSize(List<(float Mai
6767
}
6868

6969
float contentMain = lineSizes.Max(l => l.Main);
70-
float contentCross = lineSizes.Sum(l => l.Cross) + Math.Max(0, lineSizes.Count - 1) * runSpacing;
70+
float contentCross = lineSizes.Sum(l => l.Cross) + (Math.Max(0, lineSizes.Count - 1) * runSpacing);
7171
return (contentMain, contentCross);
7272
}
7373

@@ -81,11 +81,11 @@ private static (float Start, float Between) ResolveMainAxisLayout(StackJustifyCo
8181
StackJustifyContent.Start => (0, baseSpacing),
8282
StackJustifyContent.Center => (remaining / 2, baseSpacing),
8383
StackJustifyContent.End => (remaining, baseSpacing),
84-
StackJustifyContent.SpaceBetween when itemCount > 1 => (0, baseSpacing + distributable / (itemCount - 1)),
84+
StackJustifyContent.SpaceBetween when itemCount > 1 => (0, baseSpacing + (distributable / (itemCount - 1))),
8585
StackJustifyContent.SpaceAround when itemCount > 0 => (distributable / (itemCount * 2),
86-
baseSpacing + distributable / itemCount),
86+
baseSpacing + (distributable / itemCount)),
8787
StackJustifyContent.SpaceEvenly when itemCount > 0 => (distributable / (itemCount + 1),
88-
baseSpacing + distributable / (itemCount + 1)),
88+
baseSpacing + (distributable / (itemCount + 1))),
8989
_ => (0, baseSpacing)
9090
};
9191
}

src/Render/NodeRenderer.Measurement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ private static Size MeasureGridNode(GridNode grid, AssetProvider assets, AssetPr
126126
rowHeights[r] = Math.Max(rowHeights[r], size.Height);
127127
}
128128

129-
int width = colWidths.Sum() + Math.Max(0, columns - 1) * grid.ColumnGap;
130-
int height = rowHeights.Sum() + Math.Max(0, rows - 1) * grid.RowGap;
129+
int width = colWidths.Sum() + (Math.Max(0, columns - 1) * grid.ColumnGap);
130+
int height = rowHeights.Sum() + (Math.Max(0, rows - 1) * grid.RowGap);
131131
return new(grid.Width ?? width, grid.Height ?? height);
132132
}
133133

src/Render/NodeRenderer.Rendering.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ private static void RenderGridNode(Image canvas, GridNode grid, AssetProvider as
222222
rowY[r] = rowY[r - 1] + rowHeights[r - 1] + grid.RowGap;
223223
}
224224

225-
int contentWidth = colWidths.Sum() + Math.Max(0, columns - 1) * grid.ColumnGap;
226-
int contentHeight = rowHeights.Sum() + Math.Max(0, rows - 1) * grid.RowGap;
225+
int contentWidth = colWidths.Sum() + (Math.Max(0, columns - 1) * grid.ColumnGap);
226+
int contentHeight = rowHeights.Sum() + (Math.Max(0, rows - 1) * grid.RowGap);
227227
int containerWidth = grid.Width ?? desiredSize?.Width ?? contentWidth;
228228
int containerHeight = grid.Height ?? desiredSize?.Height ?? contentHeight;
229229
int gridOffsetX = ResolveStartCenterEndOffset(grid.JustifyContent, containerWidth, contentWidth);

src/ScoreFilter/LockScoreFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public sealed class LockScoreFilter : IScoreFilter
88
{
99
public Func<CommonRecord, bool> GetFilter(string? condition) => x =>
1010
{
11-
float sumScore = (x.Chart.Notes.Tap + x.Chart.Notes.Touch + x.Chart.Notes.Hold * 2 + x.Chart.Notes.Slide * 3 +
12-
x.Chart.Notes.Break * 5) * 5;
13-
float minScore = Math.Min((1 - (sumScore - 1) / sumScore) * 100,
11+
float sumScore = (x.Chart.Notes.Tap + x.Chart.Notes.Touch + (x.Chart.Notes.Hold * 2) + (x.Chart.Notes.Slide * 3) +
12+
(x.Chart.Notes.Break * 5)) * 5;
13+
float minScore = Math.Min((1 - ((sumScore - 1) / sumScore)) * 100,
1414
x.Chart.Notes.Break > 0 ? 1f / x.Chart.Notes.Break / 2 : 101);
1515
(float minAcc, _, _) = ConstantMap.GetRatingFactors(x.Rank);
1616
float maxAcc = minAcc + minScore;

src/ScoreFilter/SunScoreFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ public sealed class SunScoreFilter : IScoreFilter
88
{
99
public Func<CommonRecord, bool> GetFilter(string? condition) => x =>
1010
{
11-
float sumScore = (x.Chart.Notes.Tap + x.Chart.Notes.Touch + x.Chart.Notes.Hold * 2 + x.Chart.Notes.Slide * 3 +
12-
x.Chart.Notes.Break * 5) * 5;
13-
float minScore = Math.Min((1 - (sumScore - 1) / sumScore) * 100,
11+
float sumScore = (x.Chart.Notes.Tap + x.Chart.Notes.Touch + (x.Chart.Notes.Hold * 2) + (x.Chart.Notes.Slide * 3) +
12+
(x.Chart.Notes.Break * 5)) * 5;
13+
float minScore = Math.Min((1 - ((sumScore - 1) / sumScore)) * 100,
1414
x.Chart.Notes.Break > 0 ? 1f / x.Chart.Notes.Break / 2 : 101);
1515
(float maxAcc, _, _) = ConstantMap.GetRatingFactors(x.Rank);
1616
float minAcc = maxAcc - minScore;

src/ScoreProcesser/StdDevScoreProcesser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed class StdDevScoreProcesser : IScoreProcesser
2222
}
2323

2424
record.ExtraInfo = (float)stdDev;
25-
double score = record.DXRating * (1 + stdDev / 10) * (1 + fitLevel / (fitLevel > 0 ? 10 : 1));
25+
double score = record.DXRating * (1 + (stdDev / 10)) * (1 + (fitLevel / (fitLevel > 0 ? 10 : 1)));
2626
return (Record: record, Score: score);
2727
}).OrderByDescending(x => x.Score).ThenByDescending(x => x.Record.Chart.LevelValue)
2828
.ThenByDescending(x => x.Record.Achievements).Select(x => x.Record).ToArray();

src/Utils/Union.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ public override bool Equals(object? obj)
113113
{
114114
if (obj is not Union<T1, T2> value)
115115
{
116-
return Value?.Equals(obj) ?? obj is null;
116+
return Value?.Equals(obj) ?? (obj is null);
117117
}
118118

119119
if (value._valueState != _valueState)
120120
{
121121
return false;
122122
}
123123

124-
return Value?.Equals(value.Value) ?? value.Value is null;
124+
return Value?.Equals(value.Value) ?? (value.Value is null);
125125
}
126126

127127
public override int GetHashCode() => Value?.GetHashCode() ?? 0;
@@ -719,8 +719,8 @@ private static bool IsObjectLike(Type t)
719719
}
720720

721721
return (from i in t.GetInterfaces()
722-
where i.IsGenericType && i.GetGenericTypeDefinition() is IEnumerable
723-
select i.GetGenericArguments()[0]).FirstOrDefault();
722+
where i.IsGenericType && i.GetGenericTypeDefinition() is IEnumerable
723+
select i.GetGenericArguments()[0]).FirstOrDefault();
724724
}
725725
}
726726
}

0 commit comments

Comments
 (0)