USe MathF in all applicable places

This commit is contained in:
Henry Lin
2022-04-11 14:15:08 +08:00
parent 3bebc88306
commit 72cb3d6ad6
2 changed files with 10 additions and 10 deletions

View File

@ -174,11 +174,11 @@ namespace osu.Game.Rulesets.Osu.Utils
/// <returns>The rotated vector.</returns> /// <returns>The rotated vector.</returns>
private static Vector2 rotateVector(Vector2 vector, float rotation) private static Vector2 rotateVector(Vector2 vector, float rotation)
{ {
float angle = (float)Math.Atan2(vector.Y, vector.X) + rotation; float angle = MathF.Atan2(vector.Y, vector.X) + rotation;
float length = vector.Length; float length = vector.Length;
return new Vector2( return new Vector2(
length * (float)Math.Cos(angle), length * MathF.Cos(angle),
length * (float)Math.Sin(angle) length * MathF.Sin(angle)
); );
} }
} }

View File

@ -38,7 +38,7 @@ namespace osu.Game.Rulesets.Osu.Utils
foreach (OsuHitObject hitObject in hitObjects) foreach (OsuHitObject hitObject in hitObjects)
{ {
Vector2 relativePosition = hitObject.Position - previousPosition; Vector2 relativePosition = hitObject.Position - previousPosition;
float absoluteAngle = (float)Math.Atan2(relativePosition.Y, relativePosition.X); float absoluteAngle = MathF.Atan2(relativePosition.Y, relativePosition.X);
float relativeAngle = absoluteAngle - previousAngle; float relativeAngle = absoluteAngle - previousAngle;
ObjectPositionInfo positionInfo; ObjectPositionInfo positionInfo;
@ -141,15 +141,15 @@ namespace osu.Game.Rulesets.Osu.Utils
{ {
Vector2 earliestPosition = beforePrevious?.HitObject.EndPosition ?? playfield_centre; Vector2 earliestPosition = beforePrevious?.HitObject.EndPosition ?? playfield_centre;
Vector2 relativePosition = previous.HitObject.Position - earliestPosition; Vector2 relativePosition = previous.HitObject.Position - earliestPosition;
previousAbsoluteAngle = (float)Math.Atan2(relativePosition.Y, relativePosition.X); previousAbsoluteAngle = MathF.Atan2(relativePosition.Y, relativePosition.X);
} }
} }
float absoluteAngle = previousAbsoluteAngle + current.PositionInfo.RelativeAngle; float absoluteAngle = previousAbsoluteAngle + current.PositionInfo.RelativeAngle;
var posRelativeToPrev = new Vector2( var posRelativeToPrev = new Vector2(
current.PositionInfo.DistanceFromPrevious * (float)Math.Cos(absoluteAngle), current.PositionInfo.DistanceFromPrevious * MathF.Cos(absoluteAngle),
current.PositionInfo.DistanceFromPrevious * (float)Math.Sin(absoluteAngle) current.PositionInfo.DistanceFromPrevious * MathF.Sin(absoluteAngle)
); );
Vector2 lastEndPosition = previous?.EndPositionModified ?? playfield_centre; Vector2 lastEndPosition = previous?.EndPositionModified ?? playfield_centre;
@ -161,13 +161,13 @@ namespace osu.Game.Rulesets.Osu.Utils
if (!(current.HitObject is Slider slider)) if (!(current.HitObject is Slider slider))
return; return;
absoluteAngle = (float)Math.Atan2(posRelativeToPrev.Y, posRelativeToPrev.X); absoluteAngle = MathF.Atan2(posRelativeToPrev.Y, posRelativeToPrev.X);
Vector2 centreOfMassOriginal = calculateCentreOfMass(slider); Vector2 centreOfMassOriginal = calculateCentreOfMass(slider);
Vector2 centreOfMassModified = rotateVector(centreOfMassOriginal, current.PositionInfo.Rotation + absoluteAngle - getSliderRotation(slider)); Vector2 centreOfMassModified = rotateVector(centreOfMassOriginal, current.PositionInfo.Rotation + absoluteAngle - getSliderRotation(slider));
centreOfMassModified = RotateAwayFromEdge(current.PositionModified, centreOfMassModified); centreOfMassModified = RotateAwayFromEdge(current.PositionModified, centreOfMassModified);
float relativeRotation = (float)Math.Atan2(centreOfMassModified.Y, centreOfMassModified.X) - (float)Math.Atan2(centreOfMassOriginal.Y, centreOfMassOriginal.X); float relativeRotation = MathF.Atan2(centreOfMassModified.Y, centreOfMassModified.X) - MathF.Atan2(centreOfMassOriginal.Y, centreOfMassOriginal.X);
if (!Precision.AlmostEquals(relativeRotation, 0)) if (!Precision.AlmostEquals(relativeRotation, 0))
RotateSlider(slider, relativeRotation); RotateSlider(slider, relativeRotation);
} }
@ -346,7 +346,7 @@ namespace osu.Game.Rulesets.Osu.Utils
private static float getSliderRotation(Slider slider) private static float getSliderRotation(Slider slider)
{ {
var endPositionVector = slider.Path.PositionAt(1); var endPositionVector = slider.Path.PositionAt(1);
return (float)Math.Atan2(endPositionVector.Y, endPositionVector.X); return MathF.Atan2(endPositionVector.Y, endPositionVector.X);
} }
public class ObjectPositionInfo public class ObjectPositionInfo