Show opening/closing 9:16 stills from the same filtergraph, and let users drag a keep-region on a source frame to fill the crop insets.
101 lines
2.7 KiB
C#
101 lines
2.7 KiB
C#
using AmiReel.Models;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
namespace AmiReel.Tests.Models;
|
|
|
|
[TestClass]
|
|
public class SourceCropSelectionTests
|
|
{
|
|
[TestMethod]
|
|
public void FitUniform_WiderContainer_LetterboxesHorizontally()
|
|
{
|
|
// Act
|
|
(double offsetX, double offsetY, double width, double height) =
|
|
SourceCropSelection.FitUniform(400, 200, 100, 100);
|
|
|
|
// Assert
|
|
Assert.AreEqual(100, offsetX);
|
|
Assert.AreEqual(0, offsetY);
|
|
Assert.AreEqual(200, width);
|
|
Assert.AreEqual(200, height);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void FitUniform_TallerContainer_LetterboxesVertically()
|
|
{
|
|
// Act
|
|
(double offsetX, double offsetY, double width, double height) =
|
|
SourceCropSelection.FitUniform(200, 400, 100, 100);
|
|
|
|
// Assert
|
|
Assert.AreEqual(0, offsetX);
|
|
Assert.AreEqual(100, offsetY);
|
|
Assert.AreEqual(200, width);
|
|
Assert.AreEqual(200, height);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToInsets_FullFrameSelection_ReturnsEmptyInsets()
|
|
{
|
|
// Act
|
|
PixelInsets insets = SourceCropSelection.ToInsets(640, 512, 640, 512, 0, 0, 640, 512);
|
|
|
|
// Assert
|
|
Assert.IsTrue(insets.IsEmpty);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToInsets_CenteredSelection_ComputesAllFourEdges()
|
|
{
|
|
// Act
|
|
PixelInsets insets = SourceCropSelection.ToInsets(100, 100, 100, 100, 10, 20, 70, 50);
|
|
|
|
// Assert
|
|
Assert.AreEqual(10, insets.Left);
|
|
Assert.AreEqual(20, insets.Right);
|
|
Assert.AreEqual(20, insets.Top);
|
|
Assert.AreEqual(30, insets.Bottom);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToInsets_DraggedUpAndLeft_NormalizesTheRectangle()
|
|
{
|
|
// Act
|
|
PixelInsets insets = SourceCropSelection.ToInsets(100, 100, 100, 100, 80, 70, -70, -50);
|
|
|
|
// Assert
|
|
Assert.AreEqual(10, insets.Left);
|
|
Assert.AreEqual(20, insets.Right);
|
|
Assert.AreEqual(20, insets.Top);
|
|
Assert.AreEqual(30, insets.Bottom);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToDisplayRect_RoundTripsKnownInsets()
|
|
{
|
|
// Arrange
|
|
PixelInsets insets = new(20, 20, 10, 10);
|
|
|
|
// Act
|
|
(double x, double y, double width, double height) =
|
|
SourceCropSelection.ToDisplayRect(100, 100, 200, 200, insets);
|
|
|
|
// Assert
|
|
Assert.AreEqual(40, x);
|
|
Assert.AreEqual(20, y);
|
|
Assert.AreEqual(120, width);
|
|
Assert.AreEqual(160, height);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ClampToDisplay_OutsideBounds_ClampsToEdges()
|
|
{
|
|
// Act
|
|
(double x, double y) = SourceCropSelection.ClampToDisplay(-8, 90, 80, 60);
|
|
|
|
// Assert
|
|
Assert.AreEqual(0, x);
|
|
Assert.AreEqual(60, y);
|
|
}
|
|
}
|