Skip to content

Commit

Permalink
Fix {NaN, NaN} slider paths differently
Browse files Browse the repository at this point in the history
Previous fix simply accepts that startPoint can equal endPoint, which shouldn't ever be the case.

If two nodes are stacked, they would have no distance between them, and as such not form a path at all.

This fixes that too.
  • Loading branch information
Naxesss committed Mar 1, 2021
1 parent b9f0b6f commit 0965ae1
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions objects/hitobjects/Slider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ private Vector2 GetLinearPathPosition(double time)
int prevNodeIndex = 0;
foreach(double pathLength in pathLengths)
{
++prevNodeIndex;

if (fractionDistance > pathLength)
fractionDistance -= pathLength;
else
break;

++prevNodeIndex;
}

if (prevNodeIndex >= nodePositions.Count())
Expand All @@ -507,11 +507,6 @@ private Vector2 GetLinearPathPosition(double time)
double pointDistance = GetDistance(startPoint, endPoint);
double microFraction = fractionDistance / pointDistance;

if (pointDistance == 0)
// With no distance between points, we will simply end up with the start point.
// Note that `microFraction` is NaN in this case, so without this we would return {NaN, NaN}.
return startPoint;

return startPoint + new Vector2(
(endPoint - startPoint).X * (float)microFraction,
(endPoint - startPoint).Y * (float)microFraction
Expand Down

0 comments on commit 0965ae1

Please sign in to comment.