Inheritance: MonoBehaviour
Example #1
0
 public void PointRotatorCreate1()
 {
     for (var angle = -360d; angle <= 360d; angle += 2.5)
     {
         var rotator = new PointRotator(angle);
         this.DisposeAndCheckDisposedState(rotator);
     }
 }
        public void RotationTest270Degree()
        {
            Point p = new Point(3, 2);

            PointRotator rotator = new PointRotator(270);

            var rotate = rotator.Rotate(p);

            Assert.AreEqual(rotate.X, 2);
            Assert.AreEqual(rotate.Y, -3);
        }
Example #3
0
 public void PointRotatorOperator()
 {
     for (var x = -10d; x <= 10d; x += 0.5)
     {
         for (var y = -10d; y <= 10d; y += 0.5)
         {
             var vector  = new DPoint(x, y);
             var rotator = new PointRotator(15);
             var ret     = rotator.Operator(vector);
             this.DisposeAndCheckDisposedState(rotator);
         }
     }
 }
Example #4
0
 public void PointRotatorM()
 {
     for (var angle = -360d; angle <= 360d; angle += 2.5)
     {
         var rotator = new PointRotator(angle);
         var m       = rotator.M;
         Assert.Equal(m.MatrixElementType, MatrixElementTypes.Double);
         Assert.Equal(m.Rows, 2);
         Assert.Equal(m.Columns, 2);
         this.DisposeAndCheckDisposedState(m);
         this.DisposeAndCheckDisposedState(rotator);
     }
 }
        public void RotationTest()
        {
            CartesianArray<int> src = new CartesianArray<int>(11, 11, -5, -5);
            CartesianArrayTester.FillArray(src);

            PointRotator rotator = new PointRotator(90);

            var result = rotator.Rotate(src);

            Assert.AreEqual(result[-5, -5], -25);
            Assert.AreEqual(result[3, -3], 9);
            Assert.AreEqual(result[5, 5], -25);
            Assert.AreEqual(result[5, -5], 25);
        }
        public void RotationTestUnshapped()
        {
            CartesianArray<int> src = new CartesianArray<int>(11, 7, -5, -3);
            CartesianArrayTester.FillArray(src);

            src[5, -3] = int.MaxValue;

            PointRotator rotator = new PointRotator(90);

            var result = rotator.Rotate(src);
            
            Assert.AreEqual(result.TopLeftCoordinate.X, -3);
            Assert.AreEqual(result.TopLeftCoordinate.Y, 5);

            Assert.AreEqual(result.BottomLeftCoordinate.X, -3);
            Assert.AreEqual(result.BottomLeftCoordinate.Y, -5);
                
            Assert.AreEqual(result.BottomRightCoordinate.X, 3);
            Assert.AreEqual(result.BottomRightCoordinate.Y, -5);

            Assert.AreEqual(src[2, 2], result[-2, 2]);
            Assert.AreEqual(src[2, 3], result[-3, 2]);
        }
Example #7
0
        public void TransformImagePointRotator()
        {
            const string testName = "TransformImagePointRotator";
            var          path     = this.GetDataFile($"{LoadTarget}.bmp");

            var tests = new[]
            {
                new { Type = ImageTypes.HsiPixel, ExpectResult = false },
                new { Type = ImageTypes.RgbAlphaPixel, ExpectResult = false },
                new { Type = ImageTypes.RgbPixel, ExpectResult = true },
                new { Type = ImageTypes.UInt8, ExpectResult = true },
                new { Type = ImageTypes.UInt16, ExpectResult = true },
                new { Type = ImageTypes.Float, ExpectResult = true },
                new { Type = ImageTypes.Double, ExpectResult = true }
            };

            var angleCases = new[]
            {
                45d, -45d, 90d, 180d
            };

            var type = this.GetType().Name;

            foreach (var angle in angleCases)
            {
                foreach (var input in tests)
                {
                    foreach (var output in tests)
                    {
                        var expectResult = input.ExpectResult && output.ExpectResult;
                        var imageObj     = DlibTest.LoadImage(input.Type, path);
                        var outputObj    = Array2DTest.CreateArray2D(output.Type, imageObj.Rows, imageObj.Columns);
                        var transform    = new PointRotator(angle);

                        var outputImageAction = new Func <bool, Array2DBase>(expect =>
                        {
                            Dlib.TransformImage(imageObj, outputObj, transform);
                            return(outputObj);
                        });

                        var successAction = new Action <Array2DBase>(image =>
                        {
                            Dlib.SaveJpeg(image, $"{Path.Combine(this.GetOutDir(type, testName), $"{LoadTarget}_{input.Type}_{output.Type}_{angle}.jpg")}");
                        });

                        var failAction = new Action(() =>
                        {
                            Assert.Fail($"{testName} should throw excption for InputType: {input.Type}, OutputType: {output.Type}, Angle,: {angle}.");
                        });

                        var finallyAction = new Action(() =>
                        {
                            this.DisposeAndCheckDisposedState(transform);
                            this.DisposeAndCheckDisposedState(imageObj);
                            if (outputObj != null)
                            {
                                this.DisposeAndCheckDisposedState(outputObj);
                            }
                        });

                        var exceptionAction = new Action(() =>
                        {
                            Console.WriteLine($"Failed to execute {testName} to InputType: {input.Type}, OutputType: {output.Type}, Angle,: {angle}.");
                        });

                        DoTest(outputImageAction, expectResult, successAction, finallyAction, failAction, exceptionAction);
                    }
                }
            }
        }
Example #8
0
        public void PointRotatorCreate()
        {
            var rotator = new PointRotator();

            this.DisposeAndCheckDisposedState(rotator);
        }
        public void RotationTest30Degree()
        {
            // Results calculated with Wolfram Alpha
            Point p = new Point(10, 10);

            PointRotator rotator = new PointRotator(30);

            var rotate = rotator.Rotate(p);

            Assert.AreEqual(rotate.X, 4);
            Assert.AreEqual(rotate.Y, 14);
        }