Always use the local coordinate space

This commit is contained in:
smoogipoo 2019-10-11 15:46:11 +09:00
parent 9ecec806c2
commit 050d86a741
2 changed files with 11 additions and 11 deletions

View File

@ -101,12 +101,12 @@ namespace osu.Game.Tests.Visual.Editor
{
createGrid();
Vector2 screenSpacePosition = Vector2.Zero;
AddStep("get first tick position", () => screenSpacePosition = grid.ToScreenSpace(grid_position + new Vector2((float)beat_length, 0)));
AddAssert("snap time is 1 beat away", () => Precision.AlmostEquals(beat_length, grid.GetSnapTime(screenSpacePosition), 0.01));
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));
createGrid(g => g.Velocity = 2, "with velocity = 2");
AddAssert("snap time is now 0.5 beats away", () => Precision.AlmostEquals(beat_length / 2, grid.GetSnapTime(screenSpacePosition), 0.01));
AddAssert("snap time is now 0.5 beats away", () => Precision.AlmostEquals(beat_length / 2, grid.GetSnapTime(snapPosition), 0.01));
}
private void createGrid(Action<TestBeatSnapGrid> func = null, string description = null)

View File

@ -112,18 +112,18 @@ namespace osu.Game.Screens.Edit.Compose.Components
protected abstract float GetVelocity(double time, ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty);
/// <summary>
/// Snaps a screen-space position to this grid.
/// Snaps a position to this grid.
/// </summary>
/// <param name="screenSpacePosition">The original screen-space position.</param>
/// <returns>The snapped screen-space position.</returns>
public abstract Vector2 GetSnapPosition(Vector2 screenSpacePosition);
/// <param name="position">The original position in coordinate space local to this <see cref="BeatSnapGrid"/>.</param>
/// <returns>The snapped position in coordinate space local to this <see cref="BeatSnapGrid"/>.</returns>
public abstract Vector2 GetSnapPosition(Vector2 position);
/// <summary>
/// Retrieves the time at a snapped screen-space position.
/// Retrieves the time at a snapped position.
/// </summary>
/// <param name="screenSpacePosition">The snapped screen-space position.</param>
/// <param name="position">The snapped position in coordinate space local to this <see cref="BeatSnapGrid"/>.</param>
/// <returns>The time at the snapped position.</returns>
public double GetSnapTime(Vector2 screenSpacePosition) => startTime + (ToLocalSpace(screenSpacePosition) - CentrePosition).Length / Velocity;
public double GetSnapTime(Vector2 position) => startTime + (position - CentrePosition).Length / Velocity;
/// <summary>
/// Retrieves the applicable colour for a beat index.