Fix crash when attempting to scale two hitobjects on the same axis

This commit is contained in:
Dean Herbert 2020-12-22 12:52:30 +09:00
parent 78a53bf245
commit 87176edca1
1 changed files with 10 additions and 4 deletions

View File

@ -157,10 +157,16 @@ public override bool HandleScale(Vector2 scale, Anchor reference)
foreach (var h in hitObjects)
{
h.Position = new Vector2(
quad.TopLeft.X + (h.X - quad.TopLeft.X) / quad.Width * (quad.Width + scale.X),
quad.TopLeft.Y + (h.Y - quad.TopLeft.Y) / quad.Height * (quad.Height + scale.Y)
);
var newPosition = h.Position;
// guard against no-ops and NaN.
if (scale.X != 0 && quad.Width > 0)
newPosition.X = quad.TopLeft.X + (h.X - quad.TopLeft.X) / quad.Width * (quad.Width + scale.X);
if (scale.Y != 0 && quad.Height > 0)
newPosition.Y = quad.TopLeft.Y + (h.Y - quad.TopLeft.Y) / quad.Height * (quad.Height + scale.Y);
h.Position = newPosition;
}
}