public void BezierPositionMapper_GetPointOnBezierCurve()
        {
            // Arrange
            uint  amount = 60;
            float x1     = 0.25f;
            float y1     = 0.25f;
            float x2     = 0.75f;
            float y2     = 0.75f;

            // Act
            var mapper = new BezierPositionMapper(amount, x1, y1, x2, y2);

            // Assert
            Assert.AreEqual(new Tuple <float, float>(0, 0), mapper.GetPointOnBezierCurve(0));
            Assert.AreEqual(new Tuple <float, float>(1, 1), mapper.GetPointOnBezierCurve(1));
            Assert.AreEqual(new Tuple <float, float>(0.5f, 0.5f), mapper.GetPointOnBezierCurve(0.5f));

            float duration = 0;

            for (uint i = 0; i < amount; i++)
            {
                duration += mapper.GetMappedPosition(i);
            }
            Assert.AreEqual(3000, Convert.ToInt32(duration));
        }
Exemple #2
0
        /// <inheritdoc/>
        protected override async Task AbstractWriteAsync(
            string destinationPath,
            string destinationFilename,
            string sourcePath,
            string[] sourceFilenames,
            BezierPositionMapper mapper,
            CancellationToken ct)
        {
            if (string.IsNullOrWhiteSpace(destinationPath))
            {
                throw new ArgumentNullException(nameof(destinationPath));
            }

            if (string.IsNullOrWhiteSpace(destinationFilename))
            {
                throw new ArgumentNullException(nameof(destinationFilename));
            }

            if (string.IsNullOrWhiteSpace(sourcePath))
            {
                throw new ArgumentNullException(nameof(sourcePath));
            }

            if (sourceFilenames == null)
            {
                throw new ArgumentNullException(nameof(sourceFilenames));
            }

            if (mapper == null)
            {
                throw new ArgumentNullException(nameof(mapper));
            }

            if (ct == null)
            {
                throw new ArgumentNullException(nameof(ct));
            }

            await Task.Run(
                () =>
            {
                // 33ms delay (~30fps)
                using (var gif = AnimatedGif.AnimatedGif.Create(Path.Combine(destinationPath, destinationFilename), 33))
                {
                    for (uint i = 0; i < sourceFilenames.Length; i++)
                    {
                        ct.ThrowIfCancellationRequested();

                        using (Image image = Image.FromFile(Path.Combine(sourcePath, sourceFilenames[i])))
                        {
                            int delay = Convert.ToInt32(mapper.GetMappedPosition(i));
                            gif.AddFrame(image, delay, quality: GifQuality.Bit8);
                        }
                    }
                }
            }, ct);
        }
        public void BezierPositionMapper_GetPointOnBezierCurve_BezierEasingType(BezierEasingType bezierEasingType)
        {
            // Arrange
            uint amount = 60;

            // Act
            var mapper = new BezierPositionMapper(amount, bezierEasingType);

            // Assert
            Assert.AreEqual(new Tuple <float, float>(0, 0), mapper.GetPointOnBezierCurve(0));
            Assert.AreEqual(new Tuple <float, float>(1, 1), mapper.GetPointOnBezierCurve(1));

            float duration = 0;

            for (uint i = 0; i < amount; i++)
            {
                duration += mapper.GetMappedPosition(i);
            }
            Assert.IsTrue(duration > 2800f);
            Assert.IsTrue(duration < 3200f);
        }
        public void BezierPositionMapper_GetPointOnBezierCurve_BezierEasingType()
        {
            // Arrange
            uint             amount           = 60;
            BezierEasingType bezierEasingType = BezierEasingType.Linear;

            // Act
            var mapper = new BezierPositionMapper(amount, bezierEasingType);

            // Assert
            Assert.AreEqual(new Tuple <float, float>(0, 0), mapper.GetPointOnBezierCurve(0));
            Assert.AreEqual(new Tuple <float, float>(1, 1), mapper.GetPointOnBezierCurve(1));
            Assert.AreEqual(new Tuple <float, float>(0.5f, 0.5f), mapper.GetPointOnBezierCurve(0.5f));

            float duration = 0;

            for (uint i = 0; i < amount; i++)
            {
                duration += mapper.GetMappedPosition(i);
            }
            Assert.AreEqual(3000, Convert.ToInt32(duration));
        }