Example #1
0
        //--------------------------------------------------------------------------------------------------------------
        // Performance benchmarking
        //--------------------------------------------------------------------------------------------------------------
        /// <summary>
        /// Just to mak sure the code is compiled etc
        /// </summary>
        /// <returns>A hash code that just prevents a too-smart compiler for removing redundent code. </returns>
        public static double PerformanceTestGDIConversion(int numberOfTests)
        {
            //TODO: HOW THE HELL DOES THIS TAKE 2MS TO COMPLETE???
            double[] numbers = new double[] { 5, 8, 232.5, 123321, 12, -18 };
            double   hash    = 0;

            for (int i = 1; i < numberOfTests; i++)
            {
                //I want to know that the transformation matrix is valid in GDI plus conversions.
                TransMatrix2D t1 = TransMatrix2D.FromTRS(
                    new Point2D(22.25, 31.75),
                    numbers[i % numbers.Length],
                    new Point2D(51, 37),
                    new Point2D(0.5, 0.25));

                GDIMatrix     g1 = t1.ToGDIPlusMatrix();
                TransMatrix2D t2 = TransMatrix2D.FromGDIPlusMatrix(g1);

                Point2D test = new Point2D(7.1, numbers[(i + 2) % numbers.Length]);
                Point2D p1   = t1.Transform(test);

                var temp = new PointF[] { test.AsPointF() };
                g1.TransformPoints(temp);
                Point2D p2 = new Point2D(temp[0]);

                Point2D p3 = t2.Transform(test);

                hash += p1.X + p2.X - p3.X;
            }

            return(hash);
        }
Example #2
0
        public void TestFromGDIPlusMatrix()
        {
            //TODO: HOW THE HELL DOES THIS TAKE 2MS TO COMPLETE???

            //I want to know that the transformation matrix is valid in GDI plus conversions.
            TransMatrix2D t1 = TransMatrix2D.FromTRS(
                new Point2D(22.25, 31.75),
                12,
                new Point2D(51, 37),
                new Point2D(0.5, 0.25));

            GDIMatrix     g1 = t1.ToGDIPlusMatrix();
            TransMatrix2D t2 = TransMatrix2D.FromGDIPlusMatrix(g1);

            Point2D test = new Point2D(7.1, -81.2);
            Point2D p1   = t1.Transform(test);

            var temp = new PointF[] { test.AsPointF() };

            g1.TransformPoints(temp);
            Point2D p2 = new Point2D(temp[0]);

            Point2D p3 = t2.Transform(test);

            double errorThreshold = 0.001;


            //all points should not be on the origen
            Assert.IsTrue(p1.Length() > errorThreshold);
            Assert.IsTrue(p2.Length() > errorThreshold);
            Assert.IsTrue(p3.Length() > errorThreshold);

            //all points should be similar
            Assert.IsTrue(p1.DistanceTo(p2) < errorThreshold);
            Assert.IsTrue(p1.DistanceTo(p3) < errorThreshold);
        }