1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 22:22:54 +08:00

Rename grid snapping methods

This commit is contained in:
smoogipoo 2019-10-24 18:17:54 +09:00
parent f45f17339c
commit d83b9ef0e4
5 changed files with 12 additions and 12 deletions

View File

@ -142,7 +142,7 @@ namespace osu.Game.Rulesets.Osu.Tests
private void assertSnappedDistance(float expectedDistance) => AddAssert($"snap distance = {expectedDistance}", () =>
{
Vector2 snappedPosition = grid.GetSnapPosition(grid.ToLocalSpace(InputManager.CurrentState.Mouse.Position));
Vector2 snappedPosition = grid.GetSnappedPosition(grid.ToLocalSpace(InputManager.CurrentState.Mouse.Position));
float distance = Vector2.Distance(snappedPosition, grid_position);
return Precision.AlmostEquals(expectedDistance, distance);
@ -160,7 +160,7 @@ namespace osu.Game.Rulesets.Osu.Tests
Colour = Color4.SlateGray
},
grid = new TestOsuDistanceSnapGrid(new HitCircle { Position = grid_position }),
new SnappingCursorContainer { GetSnapPosition = v => grid.GetSnapPosition(grid.ToLocalSpace(v)) }
new SnappingCursorContainer { GetSnapPosition = v => grid.GetSnappedPosition(grid.ToLocalSpace(v)) }
};
});
}

View File

@ -106,10 +106,10 @@ namespace osu.Game.Tests.Visual.Editor
Vector2 snapPosition = Vector2.Zero;
AddStep("get first tick position", () => snapPosition = grid_position + new Vector2((float)beat_length, 0));
AddAssert("snap time is 1 beat away", () => Precision.AlmostEquals(beat_length, grid.GetSnapTime(snapPosition), 0.01));
AddAssert("snap time is 1 beat away", () => Precision.AlmostEquals(beat_length, grid.GetSnappedTime(snapPosition), 0.01));
createGrid(g => g.Velocity = 2, "with velocity = 2");
AddAssert("snap time is now 0.5 beats away", () => Precision.AlmostEquals(beat_length / 2, grid.GetSnapTime(snapPosition), 0.01));
AddAssert("snap time is now 0.5 beats away", () => Precision.AlmostEquals(beat_length / 2, grid.GetSnappedTime(snapPosition), 0.01));
}
private void createGrid(Action<TestDistanceSnapGrid> func = null, string description = null)
@ -206,7 +206,7 @@ namespace osu.Game.Tests.Visual.Editor
protected override float GetVelocity(double time, ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
=> Velocity;
public override Vector2 GetSnapPosition(Vector2 screenSpacePosition)
public override Vector2 GetSnappedPosition(Vector2 screenSpacePosition)
=> Vector2.Zero;
}
}

View File

@ -257,11 +257,11 @@ namespace osu.Game.Rulesets.Edit
public void Delete(HitObject hitObject) => EditorBeatmap.Remove(hitObject);
public override Vector2 GetSnappedPosition(Vector2 position) => distanceSnapGrid?.GetSnapPosition(position) ?? position;
public override Vector2 GetSnappedPosition(Vector2 position) => distanceSnapGrid?.GetSnappedPosition(position) ?? position;
public override double GetSnappedTime(double startTime, Vector2 position) => distanceSnapGrid?.GetSnapTime(position) ?? startTime;
public override double GetSnappedTime(double startTime, Vector2 position) => distanceSnapGrid?.GetSnappedTime(position) ?? startTime;
public override float GetSnappedDistance(float distance) => distanceSnapGrid?.GetSnapDistance(distance) ?? distance;
public override float GetSnappedDistance(float distance) => distanceSnapGrid?.GetSnappedDistance(distance) ?? distance;
protected override void Dispose(bool isDisposing)
{

View File

@ -63,7 +63,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
}
}
public override Vector2 GetSnapPosition(Vector2 position)
public override Vector2 GetSnappedPosition(Vector2 position)
{
Vector2 direction = position - CentrePosition;

View File

@ -119,21 +119,21 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary>
/// <param name="position">The original position in coordinate space local to this <see cref="DistanceSnapGrid"/>.</param>
/// <returns>The snapped position in coordinate space local to this <see cref="DistanceSnapGrid"/>.</returns>
public abstract Vector2 GetSnapPosition(Vector2 position);
public abstract Vector2 GetSnappedPosition(Vector2 position);
/// <summary>
/// Retrieves the time at a snapped position.
/// </summary>
/// <param name="position">The snapped position in coordinate space local to this <see cref="DistanceSnapGrid"/>.</param>
/// <returns>The time at the snapped position.</returns>
public double GetSnapTime(Vector2 position) => startTime + (position - CentrePosition).Length / Velocity;
public double GetSnappedTime(Vector2 position) => startTime + (position - CentrePosition).Length / Velocity;
/// <summary>
/// Snaps a distance by the snap distance of this grid.
/// </summary>
/// <param name="distance">The distance to snap.</param>
/// <returns>The snapped distance.</returns>
public float GetSnapDistance(float distance) => (int)(distance / DistanceSpacing) * DistanceSpacing;
public float GetSnappedDistance(float distance) => (int)(distance / DistanceSpacing) * DistanceSpacing;
/// <summary>
/// Retrieves the applicable colour for a beat index.