mirror of
https://github.com/ppy/osu
synced 2025-01-12 00:59:35 +00:00
fix incorrect rotated bound checking
This commit is contained in:
parent
0797d942ae
commit
4165ded813
@ -80,12 +80,32 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
changeHandler?.BeginChange();
|
||||
|
||||
objectsInScale = selectedMovableObjects.ToDictionary(ho => ho, ho => new OriginalHitObjectState(ho));
|
||||
OriginalSurroundingQuad = objectsInScale.Count == 1 && objectsInScale.First().Key is Slider slider
|
||||
? GeometryUtils.GetSurroundingQuad(slider.Path.ControlPoints.Select(p => slider.Position + p.Position))
|
||||
: GeometryUtils.GetSurroundingQuad(objectsInScale.Keys);
|
||||
OriginalSurroundingQuad = getOriginalSurroundingQuad()!;
|
||||
defaultOrigin = OriginalSurroundingQuad.Value.Centre;
|
||||
}
|
||||
|
||||
private Quad? getOriginalSurroundingQuad(float axisRotation = 0)
|
||||
{
|
||||
if (objectsInScale == null)
|
||||
return null;
|
||||
|
||||
return objectsInScale.Count == 1 && objectsInScale.First().Value.PathControlPointPositions != null
|
||||
? GeometryUtils.GetSurroundingQuad(objectsInScale.First().Value.PathControlPointPositions!.Select(p => objectsInScale.First().Value.Position + p), axisRotation)
|
||||
: GeometryUtils.GetSurroundingQuad(objectsInScale.Values.SelectMany(s =>
|
||||
{
|
||||
if (s.EndPosition.HasValue)
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
s.Position,
|
||||
s.Position + s.EndPosition.Value
|
||||
};
|
||||
}
|
||||
|
||||
return new[] { s.Position };
|
||||
}), axisRotation);
|
||||
}
|
||||
|
||||
public override void Update(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both, float axisRotation = 0)
|
||||
{
|
||||
if (!OperationInProgress.Value)
|
||||
@ -213,10 +233,23 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
scale = clampScaleToAdjustAxis(scale, adjustAxis);
|
||||
Vector2 actualOrigin = origin ?? defaultOrigin.Value;
|
||||
var selectionQuad = OriginalSurroundingQuad.Value;
|
||||
var selectionQuad = axisRotation == 0 ? OriginalSurroundingQuad.Value : getOriginalSurroundingQuad(axisRotation)!.Value;
|
||||
var points = new[]
|
||||
{
|
||||
selectionQuad.TopLeft,
|
||||
selectionQuad.TopRight,
|
||||
selectionQuad.BottomLeft,
|
||||
selectionQuad.BottomRight
|
||||
};
|
||||
|
||||
scale = clampToBound(scale, selectionQuad.BottomRight, OsuPlayfield.BASE_SIZE);
|
||||
scale = clampToBound(scale, selectionQuad.TopLeft, Vector2.Zero);
|
||||
float cos = MathF.Cos(float.DegreesToRadians(-axisRotation));
|
||||
float sin = MathF.Sin(float.DegreesToRadians(-axisRotation));
|
||||
|
||||
foreach (var point in points)
|
||||
{
|
||||
scale = clampToBound(scale, point, Vector2.Zero);
|
||||
scale = clampToBound(scale, point, OsuPlayfield.BASE_SIZE);
|
||||
}
|
||||
|
||||
return Vector2.ComponentMax(scale, new Vector2(Precision.FLOAT_EPSILON));
|
||||
|
||||
@ -226,19 +259,17 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
p -= actualOrigin;
|
||||
bound -= actualOrigin;
|
||||
float cos = MathF.Cos(float.DegreesToRadians(-axisRotation));
|
||||
float sin = MathF.Sin(float.DegreesToRadians(-axisRotation));
|
||||
var a = new Vector2(cos * cos * p.X - sin * cos * p.Y, -sin * cos * p.X + sin * sin * p.Y);
|
||||
var b = new Vector2(sin * sin * p.X + sin * cos * p.Y, sin * cos * p.X + cos * cos * p.Y);
|
||||
|
||||
switch (adjustAxis)
|
||||
{
|
||||
case Axes.X:
|
||||
s.X = MathF.Min(scale.X, minPositiveComponent(Vector2.Divide(bound - b, a)));
|
||||
s.X = MathF.Min(s.X, minPositiveComponent(Vector2.Divide(bound - b, a)));
|
||||
break;
|
||||
|
||||
case Axes.Y:
|
||||
s.Y = MathF.Min(scale.Y, minPositiveComponent(Vector2.Divide(bound - a, b)));
|
||||
s.Y = MathF.Min(s.Y, minPositiveComponent(Vector2.Divide(bound - a, b)));
|
||||
break;
|
||||
|
||||
case Axes.Both:
|
||||
@ -275,12 +306,14 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
public Vector2 Position { get; }
|
||||
public Vector2[]? PathControlPointPositions { get; }
|
||||
public PathType?[]? PathControlPointTypes { get; }
|
||||
public Vector2? EndPosition { get; }
|
||||
|
||||
public OriginalHitObjectState(OsuHitObject hitObject)
|
||||
{
|
||||
Position = hitObject.Position;
|
||||
PathControlPointPositions = (hitObject as IHasPath)?.Path.ControlPoints.Select(p => p.Position).ToArray();
|
||||
PathControlPointTypes = (hitObject as IHasPath)?.Path.ControlPoints.Select(p => p.Type).ToArray();
|
||||
EndPosition = (hitObject as IHasPath)?.Path.PositionAt(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,8 @@ namespace osu.Game.Utils
|
||||
/// Returns a quad surrounding the provided points.
|
||||
/// </summary>
|
||||
/// <param name="points">The points to calculate a quad for.</param>
|
||||
public static Quad GetSurroundingQuad(IEnumerable<Vector2> points)
|
||||
/// <param name="axisRotation">The rotation in degrees of the axis to align the quad to.</param>
|
||||
public static Quad GetSurroundingQuad(IEnumerable<Vector2> points, float axisRotation = 0)
|
||||
{
|
||||
if (!points.Any())
|
||||
return new Quad();
|
||||
@ -124,20 +125,25 @@ namespace osu.Game.Utils
|
||||
// Go through all hitobjects to make sure they would remain in the bounds of the editor after movement, before any movement is attempted
|
||||
foreach (var p in points)
|
||||
{
|
||||
minPosition = Vector2.ComponentMin(minPosition, p);
|
||||
maxPosition = Vector2.ComponentMax(maxPosition, p);
|
||||
var pr = RotateVector(p, axisRotation);
|
||||
minPosition = Vector2.ComponentMin(minPosition, pr);
|
||||
maxPosition = Vector2.ComponentMax(maxPosition, pr);
|
||||
}
|
||||
|
||||
Vector2 size = maxPosition - minPosition;
|
||||
var p1 = RotateVector(minPosition, -axisRotation);
|
||||
var p2 = RotateVector(new Vector2(minPosition.X, maxPosition.Y), -axisRotation);
|
||||
var p3 = RotateVector(maxPosition, -axisRotation);
|
||||
var p4 = RotateVector(new Vector2(maxPosition.X, minPosition.Y), -axisRotation);
|
||||
|
||||
return new Quad(minPosition.X, minPosition.Y, size.X, size.Y);
|
||||
return new Quad(p1, p2, p3, p4);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a gamefield-space quad surrounding the provided hit objects.
|
||||
/// </summary>
|
||||
/// <param name="hitObjects">The hit objects to calculate a quad for.</param>
|
||||
public static Quad GetSurroundingQuad(IEnumerable<IHasPosition> hitObjects) =>
|
||||
/// <param name="axisRotation">The rotation in degrees of the axis to align the quad to.</param>
|
||||
public static Quad GetSurroundingQuad(IEnumerable<IHasPosition> hitObjects, float axisRotation = 0) =>
|
||||
GetSurroundingQuad(hitObjects.SelectMany(h =>
|
||||
{
|
||||
if (h is IHasPath path)
|
||||
@ -151,6 +157,6 @@ namespace osu.Game.Utils
|
||||
}
|
||||
|
||||
return new[] { h.Position };
|
||||
}));
|
||||
}), axisRotation);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user