Skip to content

Commit

Permalink
Update usage of MathUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Mar 6, 2024
1 parent 6455c05 commit b53b752
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Mods/OsuModSpunOut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void onSpinnerUpdate(Drawable drawable)
// multiply the SPM by 1.01 to ensure that the spinner is completed. if the calculation is left exact,
// some spinners may not complete due to very minor decimal loss during calculation
float rotationSpeed = (float)(1.01 * spinner.HitObject.SpinsRequired / spinner.HitObject.Duration);
spinner.RotationTracker.AddRotation(MathUtils.RadiansToDegrees((float)rateIndependentElapsedTime * rotationSpeed * MathF.PI * 2.0f));
spinner.RotationTracker.AddRotation(float.RadiansToDegrees((float)rateIndependentElapsedTime * rotationSpeed * MathF.PI * 2.0f));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void UpdateSnakingPosition(Vector2 start, Vector2 end)
break;
}

float aimRotation = MathUtils.RadiansToDegrees(MathF.Atan2(aimRotationVector.Y - Position.Y, aimRotationVector.X - Position.X));
float aimRotation = float.RadiansToDegrees(MathF.Atan2(aimRotationVector.Y - Position.Y, aimRotationVector.X - Position.X));
while (Math.Abs(aimRotation - Arrow.Rotation) > 180)
aimRotation += aimRotation < Arrow.Rotation ? 360 : -360;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Replays/OsuAutoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private void addHitObjectClickFrames(OsuHitObject h, Vector2 startPosition, floa
// 0.05 rad/ms, or ~477 RPM, as per stable.
// the redundant conversion from RPM to rad/ms is here for ease of testing custom SPM specs.
const float spin_rpm = 0.05f / (2 * MathF.PI) * 60000;
float radsPerMillisecond = MathUtils.DegreesToRadians(spin_rpm * 360) / 60000;
float radsPerMillisecond = float.DegreesToRadians(spin_rpm * 360) / 60000;

switch (h)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected override void Update()

if (mousePosition is Vector2 pos)
{
float thisAngle = -MathUtils.RadiansToDegrees(MathF.Atan2(pos.X - DrawSize.X / 2, pos.Y - DrawSize.Y / 2));
float thisAngle = -float.RadiansToDegrees(MathF.Atan2(pos.X - DrawSize.X / 2, pos.Y - DrawSize.Y / 2));
float delta = lastAngle == null ? 0 : thisAngle - lastAngle.Value;

// Normalise the delta to -180 .. 180
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Osu/Statistics/AccuracyHeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ protected void AddPoint(Vector2 start, Vector2 end, Vector2 hitPoint, float radi
// Likewise sin(pi/2)=1 and sin(3pi/2)=-1, whereas we actually want these values to appear on the bottom/top respectively, so the y-coordinate also needs to be inverted.
//
// We also need to apply the anti-clockwise rotation.
double rotatedAngle = finalAngle - MathUtils.DegreesToRadians(rotation);
double rotatedAngle = finalAngle - float.DegreesToRadians(rotation);
var rotatedCoordinate = -1 * new Vector2((float)Math.Cos(rotatedAngle), (float)Math.Sin(rotatedAngle));

Vector2 localCentre = new Vector2(points_per_dimension - 1) / 2;
Expand Down
3 changes: 1 addition & 2 deletions osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.IO;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Beatmaps.Legacy;
using osu.Game.IO;
using osu.Game.Storyboards;
Expand Down Expand Up @@ -230,7 +229,7 @@ private void handleEvents(string line)
{
float startValue = Parsing.ParseFloat(split[4]);
float endValue = split.Length > 5 ? Parsing.ParseFloat(split[5]) : startValue;
timelineGroup?.Rotation.Add(easing, startTime, endTime, MathUtils.RadiansToDegrees(startValue), MathUtils.RadiansToDegrees(endValue));
timelineGroup?.Rotation.Add(easing, startTime, endTime, float.RadiansToDegrees(startValue), float.RadiansToDegrees(endValue));
break;
}

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Graphics/Cursor/MenuCursorContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected override bool OnMouseMove(MouseMoveEvent e)
if (dragRotationState == DragRotationState.Rotating && distance > 0)
{
Vector2 offset = e.MousePosition - positionMouseDown;
float degrees = MathUtils.RadiansToDegrees(MathF.Atan2(-offset.X, offset.Y)) + 24.3f;
float degrees = float.RadiansToDegrees(MathF.Atan2(-offset.X, offset.Y)) + 24.3f;

// Always rotate in the direction of least distance
float diff = (degrees - activeCursor.Rotation) % 360;
Expand Down
4 changes: 1 addition & 3 deletions osu.Game/Graphics/UserInterface/OsuNumberBox.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Extensions;

namespace osu.Game.Graphics.UserInterface
{
public partial class OsuNumberBox : OsuTextBox
{
protected override bool AllowIme => false;

protected override bool CanAddCharacter(char character) => character.IsAsciiDigit();
protected override bool CanAddCharacter(char character) => char.IsAsciiDigit(character);
}
}
3 changes: 1 addition & 2 deletions osu.Game/IO/Archives/ZipArchiveReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.IO;
using System.Linq;
using Microsoft.Toolkit.HighPerformance;
using osu.Framework.Extensions;
using osu.Framework.IO.Stores;
using SharpCompress.Archives.Zip;
using SixLabors.ImageSharp.Memory;
Expand Down Expand Up @@ -36,7 +35,7 @@ public override Stream GetStream(string name)
var owner = MemoryAllocator.Default.Allocate<byte>((int)entry.Size);

using (Stream s = entry.OpenEntryStream())
s.ReadToFill(owner.Memory.Span);
s.ReadExactly(owner.Memory.Span);

return new MemoryOwnerMemoryStream(owner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Input.Handlers.Tablet;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
Expand Down Expand Up @@ -196,7 +195,7 @@ private void checkBounds()
var matrix = Matrix3.Identity;

MatrixExtensions.TranslateFromLeft(ref matrix, offset);
MatrixExtensions.RotateFromLeft(ref matrix, MathUtils.DegreesToRadians(rotation.Value));
MatrixExtensions.RotateFromLeft(ref matrix, float.DegreesToRadians(rotation.Value));

usableAreaQuad *= matrix;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Settings/SettingsNumberBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private partial class OutlinedNumberBox : OutlinedTextBox
{
protected override bool AllowIme => false;

protected override bool CanAddCharacter(char character) => character.IsAsciiDigit();
protected override bool CanAddCharacter(char character) => char.IsAsciiDigit(character);

public new void NotifyInputError() => base.NotifyInputError();
}
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/Screens/Menu/LogoVisualisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ protected override void Draw(IRenderer renderer)
if (audioData[i] < amplitude_dead_zone)
continue;

float rotation = MathUtils.DegreesToRadians(i / (float)bars_per_visualiser * 360 + j * 360 / visualiser_rounds);
float rotation = float.DegreesToRadians(i / (float)bars_per_visualiser * 360 + j * 360 / visualiser_rounds);
float rotationCos = MathF.Cos(rotation);
float rotationSin = MathF.Sin(rotation);
// taking the cos and sin to the 0..1 range
var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * size;

var barSize = new Vector2(size * MathF.Sqrt(2 * (1 - MathF.Cos(MathUtils.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * audioData[i]);
var barSize = new Vector2(size * MathF.Sqrt(2 * (1 - MathF.Cos(float.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * audioData[i]);
// The distance between the position and the sides of the bar.
var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2);
// The distance between the bottom side of the bar and the top side.
Expand Down
5 changes: 2 additions & 3 deletions osu.Game/Utils/GeometryUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Utils;
using osu.Game.Rulesets.Objects.Types;
using osuTK;

Expand All @@ -28,8 +27,8 @@ public static Vector2 RotatePointAroundOrigin(Vector2 point, Vector2 origin, flo
point.Y -= origin.Y;

Vector2 ret;
ret.X = point.X * MathF.Cos(MathUtils.DegreesToRadians(angle)) + point.Y * MathF.Sin(MathUtils.DegreesToRadians(angle));
ret.Y = point.X * -MathF.Sin(MathUtils.DegreesToRadians(angle)) + point.Y * MathF.Cos(MathUtils.DegreesToRadians(angle));
ret.X = point.X * MathF.Cos(float.DegreesToRadians(angle)) + point.Y * MathF.Sin(float.DegreesToRadians(angle));
ret.Y = point.X * -MathF.Sin(float.DegreesToRadians(angle)) + point.Y * MathF.Cos(float.DegreesToRadians(angle));

ret.X += origin.X;
ret.Y += origin.Y;
Expand Down

0 comments on commit b53b752

Please sign in to comment.