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

Merge pull request #23938 from peppy/fix-distance-snap-grid-centering

Fix distance snap grid circles not correctly being centred on snap point
This commit is contained in:
Bartłomiej Dach 2023-06-19 21:36:33 +02:00 committed by GitHub
commit a600eb5f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View File

@ -185,7 +185,18 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
AddAssert("Ensure cursor is on a grid line", () => AddAssert("Ensure cursor is on a grid line", () =>
{ {
return grid.ChildrenOfType<CircularProgress>().Any(p => Precision.AlmostEquals(p.ScreenSpaceDrawQuad.TopRight.X, grid.ToScreenSpace(cursor.LastSnappedPosition).X)); return grid.ChildrenOfType<CircularProgress>().Any(ring =>
{
// the grid rings are actually slightly _larger_ than the snapping radii.
// this is done such that the snapping radius falls right in the middle of each grid ring thickness-wise,
// but it does however complicate the following calculations slightly.
// we want to calculate the coordinates of the rightmost point on the grid line, which is in the exact middle of the ring thickness-wise.
// for the X component, we take the entire width of the ring, minus one half of the inner radius (since we want the middle of the line on the right side).
// for the Y component, we just take 0.5f.
var rightMiddleOfGridLine = ring.ToScreenSpace(ring.DrawSize * new Vector2(1 - ring.InnerRadius / 2, 0.5f));
return Precision.AlmostEquals(rightMiddleOfGridLine.X, grid.ToScreenSpace(cursor.LastSnappedPosition).X);
});
}); });
} }

View File

@ -65,14 +65,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
for (int i = 0; i < requiredCircles; i++) for (int i = 0; i < requiredCircles; i++)
{ {
float diameter = (offset + (i + 1) * DistanceBetweenTicks) * 2; const float thickness = 4;
float diameter = (offset + (i + 1) * DistanceBetweenTicks + thickness / 2) * 2;
AddInternal(new Ring(ReferenceObject, GetColourForIndexFromPlacement(i)) AddInternal(new Ring(ReferenceObject, GetColourForIndexFromPlacement(i))
{ {
Position = StartPosition, Position = StartPosition,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(diameter), Size = new Vector2(diameter),
InnerRadius = 4 * 1f / diameter, InnerRadius = thickness * 1f / diameter,
}); });
} }
} }