mirror of
https://github.com/osukey/osukey.git
synced 2025-07-03 01:09:57 +09:00
Merge branch 'master' into mods-effect-displays
This commit is contained in:
@ -73,7 +73,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
dependencies.Cache(new RealmRulesetStore(Realm));
|
||||
dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, dependencies.Get<AudioManager>(), Resources, dependencies.Get<GameHost>(), Beatmap.Default));
|
||||
dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get<RulesetStore>(), () => beatmapManager, LocalStorage, Realm, Scheduler, API));
|
||||
dependencies.Cache(scoreManager = new ScoreManager(dependencies.Get<RulesetStore>(), () => beatmapManager, LocalStorage, Realm, API));
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
return dependencies;
|
||||
|
@ -194,7 +194,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
AddStep("notification arrived", () => notificationOverlay.Verify(n => n.Post(It.IsAny<Notification>()), Times.Once));
|
||||
|
||||
AddStep("run notification action", () => lastNotification.Activated());
|
||||
AddStep("run notification action", () => lastNotification.Activated?.Invoke());
|
||||
|
||||
AddAssert("overlay shown", () => overlay.State.Value == Visibility.Visible);
|
||||
AddAssert("is resumed", () => overlay.CurrentScreen is ScreenUIScale);
|
||||
|
@ -259,7 +259,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
private void removeFacade()
|
||||
{
|
||||
trackingContainer.Remove(logoFacade);
|
||||
trackingContainer.Remove(logoFacade, false);
|
||||
visualBox.Colour = Color4.White;
|
||||
moveLogoFacade();
|
||||
}
|
||||
|
@ -1,33 +1,36 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Updater;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneNotificationOverlay : OsuTestScene
|
||||
{
|
||||
private NotificationOverlay notificationOverlay;
|
||||
private NotificationOverlay notificationOverlay = null!;
|
||||
|
||||
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
|
||||
|
||||
private SpriteText displayedCount;
|
||||
private SpriteText displayedCount = null!;
|
||||
|
||||
public double TimeToCompleteProgress { get; set; } = 2000;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
TimeToCompleteProgress = 2000;
|
||||
progressingNotifications.Clear();
|
||||
|
||||
Content.Children = new Drawable[]
|
||||
@ -43,10 +46,36 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
notificationOverlay.UnreadCount.ValueChanged += count => { displayedCount.Text = $"displayed count: {count.NewValue}"; };
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TestPresence()
|
||||
{
|
||||
AddAssert("tray not present", () => !notificationOverlay.ChildrenOfType<NotificationOverlayToastTray>().Single().IsPresent);
|
||||
AddAssert("overlay not present", () => !notificationOverlay.IsPresent);
|
||||
|
||||
AddStep(@"post notification", sendBackgroundNotification);
|
||||
|
||||
AddUntilStep("wait tray not present", () => !notificationOverlay.ChildrenOfType<NotificationOverlayToastTray>().Single().IsPresent);
|
||||
AddUntilStep("wait overlay not present", () => !notificationOverlay.IsPresent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestPresenceWithManualDismiss()
|
||||
{
|
||||
AddAssert("tray not present", () => !notificationOverlay.ChildrenOfType<NotificationOverlayToastTray>().Single().IsPresent);
|
||||
AddAssert("overlay not present", () => !notificationOverlay.IsPresent);
|
||||
|
||||
AddStep(@"post notification", sendBackgroundNotification);
|
||||
AddStep("click notification", () => notificationOverlay.ChildrenOfType<Notification>().Single().TriggerClick());
|
||||
|
||||
AddUntilStep("wait tray not present", () => !notificationOverlay.ChildrenOfType<NotificationOverlayToastTray>().Single().IsPresent);
|
||||
AddUntilStep("wait overlay not present", () => !notificationOverlay.IsPresent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCompleteProgress()
|
||||
{
|
||||
ProgressNotification notification = null;
|
||||
ProgressNotification notification = null!;
|
||||
|
||||
AddStep("add progress notification", () =>
|
||||
{
|
||||
notification = new ProgressNotification
|
||||
@ -59,12 +88,37 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
});
|
||||
|
||||
AddUntilStep("wait completion", () => notification.State == ProgressNotificationState.Completed);
|
||||
|
||||
AddAssert("Completion toast shown", () => notificationOverlay.ToastCount == 1);
|
||||
AddUntilStep("wait forwarded", () => notificationOverlay.ToastCount == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCompleteProgressSlow()
|
||||
{
|
||||
ProgressNotification notification = null!;
|
||||
|
||||
AddStep("Set progress slow", () => TimeToCompleteProgress *= 2);
|
||||
AddStep("add progress notification", () =>
|
||||
{
|
||||
notification = new ProgressNotification
|
||||
{
|
||||
Text = @"Uploading to BSS...",
|
||||
CompletionText = "Uploaded to BSS!",
|
||||
};
|
||||
notificationOverlay.Post(notification);
|
||||
progressingNotifications.Add(notification);
|
||||
});
|
||||
|
||||
AddUntilStep("wait completion", () => notification.State == ProgressNotificationState.Completed);
|
||||
|
||||
AddAssert("Completion toast shown", () => notificationOverlay.ToastCount == 1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCancelProgress()
|
||||
{
|
||||
ProgressNotification notification = null;
|
||||
ProgressNotification notification = null!;
|
||||
AddStep("add progress notification", () =>
|
||||
{
|
||||
notification = new ProgressNotification
|
||||
@ -81,6 +135,35 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
AddStep("cancel notification", () => notification.State = ProgressNotificationState.Cancelled);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUpdateNotificationFlow()
|
||||
{
|
||||
bool applyUpdate = false;
|
||||
|
||||
AddStep(@"post update", () =>
|
||||
{
|
||||
applyUpdate = false;
|
||||
|
||||
var updateNotification = new UpdateManager.UpdateProgressNotification
|
||||
{
|
||||
CompletionClickAction = () => applyUpdate = true
|
||||
};
|
||||
|
||||
notificationOverlay.Post(updateNotification);
|
||||
progressingNotifications.Add(updateNotification);
|
||||
});
|
||||
|
||||
checkProgressingCount(1);
|
||||
waitForCompletion();
|
||||
|
||||
UpdateManager.UpdateApplicationCompleteNotification? completionNotification = null;
|
||||
AddUntilStep("wait for completion notification",
|
||||
() => (completionNotification = notificationOverlay.ChildrenOfType<UpdateManager.UpdateApplicationCompleteNotification>().SingleOrDefault()) != null);
|
||||
AddStep("click notification", () => completionNotification?.TriggerClick());
|
||||
|
||||
AddUntilStep("wait for update applied", () => applyUpdate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasicFlow()
|
||||
{
|
||||
@ -112,7 +195,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
AddStep(@"simple #1", sendHelloNotification);
|
||||
|
||||
AddAssert("Is visible", () => notificationOverlay.State.Value == Visibility.Visible);
|
||||
AddAssert("toast displayed", () => notificationOverlay.ToastCount == 1);
|
||||
AddAssert("is not visible", () => notificationOverlay.State.Value == Visibility.Hidden);
|
||||
|
||||
checkDisplayedCount(1);
|
||||
|
||||
@ -178,14 +262,14 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
foreach (var n in progressingNotifications.FindAll(n => n.State == ProgressNotificationState.Active))
|
||||
{
|
||||
if (n.Progress < 1)
|
||||
n.Progress += (float)(Time.Elapsed / 2000);
|
||||
n.Progress += (float)(Time.Elapsed / TimeToCompleteProgress);
|
||||
else
|
||||
n.State = ProgressNotificationState.Completed;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDisplayedCount(int expected) =>
|
||||
AddAssert($"Displayed count is {expected}", () => notificationOverlay.UnreadCount.Value == expected);
|
||||
AddUntilStep($"Displayed count is {expected}", () => notificationOverlay.UnreadCount.Value == expected);
|
||||
|
||||
private void sendDownloadProgress()
|
||||
{
|
||||
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Platform;
|
||||
@ -39,8 +38,6 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
Dependencies.Cache(new RealmRulesetStore(Realm));
|
||||
Dependencies.Cache(beatmapManager = new BeatmapManager(LocalStorage, Realm, null, Audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@ -66,6 +63,9 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
}
|
||||
|
||||
beatmapSets.First().ToLive(Realm);
|
||||
|
||||
// Ensure all the initial imports are present before running any tests.
|
||||
Realm.Run(r => r.Refresh());
|
||||
});
|
||||
|
||||
[Test]
|
||||
@ -138,7 +138,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
AddStep("Add collection", () =>
|
||||
{
|
||||
Dependencies.Get<RealmAccess>().Write(r =>
|
||||
Realm.Write(r =>
|
||||
{
|
||||
r.RemoveAll<BeatmapCollection>();
|
||||
r.Add(new BeatmapCollection("wang"));
|
||||
|
@ -0,0 +1,94 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneSizePreservingSpriteText : OsuGridTestScene
|
||||
{
|
||||
private readonly List<Container> parentContainers = new List<Container>();
|
||||
private readonly List<UprightAspectMaintainingContainer> childContainers = new List<UprightAspectMaintainingContainer>();
|
||||
private readonly OsuSpriteText osuSpriteText = new OsuSpriteText();
|
||||
private readonly SizePreservingSpriteText sizePreservingSpriteText = new SizePreservingSpriteText();
|
||||
|
||||
public TestSceneSizePreservingSpriteText()
|
||||
: base(1, 2)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
UprightAspectMaintainingContainer childContainer;
|
||||
Container parentContainer = new Container
|
||||
{
|
||||
Origin = Anchor.BottomRight,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Rotation = 45,
|
||||
Y = -200,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Colour4.Red,
|
||||
},
|
||||
childContainer = new UprightAspectMaintainingContainer
|
||||
{
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = Colour4.Blue,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
Container cellInfo = new Container
|
||||
{
|
||||
Origin = Anchor.TopCentre,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Top = 100,
|
||||
},
|
||||
Child = new OsuSpriteText
|
||||
{
|
||||
Text = (i == 0) ? "OsuSpriteText" : "SizePreservingSpriteText",
|
||||
Font = OsuFont.GetFont(Typeface.Inter, weight: FontWeight.Bold, size: 40),
|
||||
Origin = Anchor.TopCentre,
|
||||
Anchor = Anchor.TopCentre,
|
||||
},
|
||||
};
|
||||
|
||||
parentContainers.Add(parentContainer);
|
||||
childContainers.Add(childContainer);
|
||||
Cell(i).Add(cellInfo);
|
||||
Cell(i).Add(parentContainer);
|
||||
}
|
||||
|
||||
childContainers[0].Add(osuSpriteText);
|
||||
childContainers[1].Add(sizePreservingSpriteText);
|
||||
osuSpriteText.Font = sizePreservingSpriteText.Font = OsuFont.GetFont(Typeface.Venera, weight: FontWeight.Bold, size: 20);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
osuSpriteText.Text = sizePreservingSpriteText.Text = DateTime.Now.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,244 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK.Graphics;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneUprightAspectMaintainingContainer : OsuGridTestScene
|
||||
{
|
||||
private const int rows = 3;
|
||||
private const int columns = 4;
|
||||
|
||||
private readonly ScaleMode[] scaleModeValues = { ScaleMode.NoScaling, ScaleMode.Horizontal, ScaleMode.Vertical };
|
||||
private readonly float[] scalingFactorValues = { 1.0f / 3, 1.0f / 2, 1.0f, 1.5f };
|
||||
|
||||
private readonly List<List<Container>> parentContainers = new List<List<Container>>(rows);
|
||||
private readonly List<List<UprightAspectMaintainingContainer>> childContainers = new List<List<UprightAspectMaintainingContainer>>(rows);
|
||||
|
||||
// Preferably should be set to (4 * 2^n)
|
||||
private const int rotation_step_count = 3;
|
||||
|
||||
private readonly List<int> flipStates = new List<int>();
|
||||
private readonly List<float> rotationSteps = new List<float>();
|
||||
private readonly List<float> scaleSteps = new List<float>();
|
||||
|
||||
public TestSceneUprightAspectMaintainingContainer()
|
||||
: base(rows, columns)
|
||||
{
|
||||
for (int i = 0; i < rows; i++)
|
||||
{
|
||||
parentContainers.Add(new List<Container>());
|
||||
childContainers.Add(new List<UprightAspectMaintainingContainer>());
|
||||
|
||||
for (int j = 0; j < columns; j++)
|
||||
{
|
||||
UprightAspectMaintainingContainer child;
|
||||
Container parent = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Height = 80,
|
||||
Width = 80,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new Color4(255, 0, 0, 160),
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "Parent",
|
||||
},
|
||||
child = new UprightAspectMaintainingContainer
|
||||
{
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
|
||||
// These are the parameters being Tested
|
||||
Scaling = scaleModeValues[i],
|
||||
ScalingFactor = scalingFactorValues[j],
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = new Color4(0, 0, 255, 160),
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "Text",
|
||||
Font = OsuFont.Numeric,
|
||||
Origin = Anchor.Centre,
|
||||
Anchor = Anchor.Centre,
|
||||
Padding = new MarginPadding
|
||||
{
|
||||
Horizontal = 4,
|
||||
Vertical = 4,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Container cellInfo = new Container
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "Scaling: " + scaleModeValues[i].ToString(),
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = "ScalingFactor: " + scalingFactorValues[j].ToString("0.00"),
|
||||
Margin = new MarginPadding
|
||||
{
|
||||
Top = 15,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Cell(i * columns + j).Add(cellInfo);
|
||||
Cell(i * columns + j).Add(parent);
|
||||
parentContainers[i].Add(parent);
|
||||
childContainers[i].Add(child);
|
||||
}
|
||||
}
|
||||
|
||||
flipStates.AddRange(new[] { 1, -1 });
|
||||
rotationSteps.AddRange(Enumerable.Range(0, rotation_step_count).Select(x => 360f * ((float)x / rotation_step_count)));
|
||||
scaleSteps.AddRange(new[] { 1, 0.3f, 1.5f });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExplicitlySizedParent()
|
||||
{
|
||||
var parentStates = from xFlip in flipStates
|
||||
from yFlip in flipStates
|
||||
from xScale in scaleSteps
|
||||
from yScale in scaleSteps
|
||||
from rotation in rotationSteps
|
||||
select new { xFlip, yFlip, xScale, yScale, rotation };
|
||||
|
||||
foreach (var state in parentStates)
|
||||
{
|
||||
Vector2 parentScale = new Vector2(state.xFlip * state.xScale, state.yFlip * state.yScale);
|
||||
float parentRotation = state.rotation;
|
||||
|
||||
AddStep("S: (" + parentScale.X.ToString("0.00") + ", " + parentScale.Y.ToString("0.00") + "), R: " + parentRotation.ToString("0.00"), () =>
|
||||
{
|
||||
foreach (List<Container> list in parentContainers)
|
||||
{
|
||||
foreach (Container container in list)
|
||||
{
|
||||
container.Scale = parentScale;
|
||||
container.Rotation = parentRotation;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AddAssert("Check if state is valid", () =>
|
||||
{
|
||||
foreach (int i in Enumerable.Range(0, parentContainers.Count))
|
||||
{
|
||||
foreach (int j in Enumerable.Range(0, parentContainers[i].Count))
|
||||
{
|
||||
if (!uprightAspectMaintainingContainerStateIsValid(parentContainers[i][j], childContainers[i][j]))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private bool uprightAspectMaintainingContainerStateIsValid(Container parent, UprightAspectMaintainingContainer child)
|
||||
{
|
||||
Matrix3 parentMatrix = parent.DrawInfo.Matrix;
|
||||
Matrix3 childMatrix = child.DrawInfo.Matrix;
|
||||
Vector3 childScale = childMatrix.ExtractScale();
|
||||
Vector3 parentScale = parentMatrix.ExtractScale();
|
||||
|
||||
// Orientation check
|
||||
if (!(isNearlyZero(MathF.Abs(childMatrix.M21)) && isNearlyZero(MathF.Abs(childMatrix.M12))))
|
||||
return false;
|
||||
|
||||
// flip check
|
||||
if (!(childMatrix.M11 * childMatrix.M22 > 0))
|
||||
return false;
|
||||
|
||||
// Aspect ratio check
|
||||
if (!isNearlyZero(childScale.X - childScale.Y))
|
||||
return false;
|
||||
|
||||
// ScalingMode check
|
||||
switch (child.Scaling)
|
||||
{
|
||||
case ScaleMode.NoScaling:
|
||||
if (!(isNearlyZero(childMatrix.M11 - 1.0f) && isNearlyZero(childMatrix.M22 - 1.0f)))
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
case ScaleMode.Vertical:
|
||||
if (!(checkScaling(child.ScalingFactor, parentScale.Y, childScale.Y)))
|
||||
return false;
|
||||
|
||||
break;
|
||||
|
||||
case ScaleMode.Horizontal:
|
||||
if (!(checkScaling(child.ScalingFactor, parentScale.X, childScale.X)))
|
||||
return false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool checkScaling(float scalingFactor, float parentScale, float childScale)
|
||||
{
|
||||
if (scalingFactor <= 1.0f)
|
||||
{
|
||||
if (!isNearlyZero(1.0f + (parentScale - 1.0f) * scalingFactor - childScale))
|
||||
return false;
|
||||
}
|
||||
else if (scalingFactor > 1.0f)
|
||||
{
|
||||
if (parentScale < 1.0f)
|
||||
{
|
||||
if (!isNearlyZero((parentScale * (1.0f / scalingFactor)) - childScale))
|
||||
return false;
|
||||
}
|
||||
else if (!isNearlyZero(parentScale * scalingFactor - childScale))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool isNearlyZero(float f, float epsilon = Precision.FLOAT_EPSILON)
|
||||
{
|
||||
return f < epsilon;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user