コード例 #1
0
 public RendererSettings(IRenderer r)
 {
     AngleType       = r.AngleType;
     LineEndCapStyle = r.LineEndCapStyle;
     HighQuality     = r.HighQuality;
     Transform       = r.Transform;
 }
コード例 #2
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);
        }
コード例 #3
0
        private static Bitmap mapToIsoMetric(Bitmap b, IsoMetricTileGenerationSettings settings)
        {
            int newWidth = (int)Math.Ceiling(Math.Sqrt(2 * (Math.Pow(Math.Max(b.Width, b.Height), 2))));

            //keep the width even
            if ((newWidth % 2) != 0)
            {
                newWidth++;
            }
            int           newHeight     = newWidth;
            int           halfNewWidth  = newWidth / 2;
            int           halfNewHeight = newWidth / 2;
            IRenderer     r             = IRendererFactory.GetPreferredRenderer(newWidth, newHeight);
            TransMatrix2D rot           = TransMatrix2D.FromRotation(Math.PI / 4.0, new Point2D(halfNewWidth, halfNewHeight));

            r.SetTransform(rot);
            r.DrawImage(b,
                        halfNewWidth - (b.Width / 2) + 1,
                        halfNewHeight - (b.Height / 2) + 1);

            Bitmap rotated = r.RenderTargetAsGDIBitmap();

            //apply squash
            if (Math.Abs(settings.HeightRatio) > 0.0001)
            {
                //return new Bitmap(rotated, rotated.Width, rotated.Height / 2);
                return(new Bitmap(rotated, b.Width, b.Height / 2));
            }
            return(rotated);
        }
コード例 #4
0
ファイル: IView2D.cs プロジェクト: busyDuckman/WDLib
 public static TransMatrix2D CalculateWorldToScreenTransformMatrix(this IView2D view)
 {
     return(TransMatrix2D.FromTRS(new Point2D(view.TransformX, view.TransformY),
                                  view.ClockwiseRotation,
                                  //screenSpaceBounds.Middle(),
                                  Point2D.Origen,
                                  new Point2D(view.Zoom, view.Zoom)));
 }
コード例 #5
0
 public void ApplySettings(IRendererSettings settings)
 {
     if (settings != null)
     {
         RendererSettings rs = settings as RendererSettings;
         if (rs != null)
         {
             rs.Apply(this);
         }
         else
         {
             AngleType       = settings.AngleType;
             LineEndCapStyle = settings.LineEndCapStyle;
             HighQuality     = settings.HighQuality;
             Transform       = settings.Transform;
         }
     }
 }
コード例 #6
0
        public void Render <T>(IRenderer r, IRenderableShape <ST> s) where T : IShape
        {
            TransMatrix2D transform = s.TransMatrix;

            //TODO: Transform
            if (s.Geomerty is Circle)
            {
                Circle c = s.Geomerty as Circle;
                r.DrawCircle(Color.Red, 1, (int)c.Centre.X, (int)c.Centre.Y, (int)c.Radius);
            }
            else
            {
                //meh, squares et al., are all polygons.
                //The class should cache the conversion.
                Polygon p = s.Geomerty.ToPolygon();
                //PointList p2 = transform.Transform();
                for (int i = 0; i < p.Points.Count; i++)
                {
                    //NB: p.points is padded with an extra indexable value, to close the shape
                    //so p.Points[i + 1] is valid on the last iteration
                    r.DrawLine(Color.Red, 1, p.Points[i], p.Points[i + 1]);
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: View2dBase.cs プロジェクト: busyDuckman/WDLib
 protected void clearTransformProxies()
 {
     renderMatrixProxy        = null;
     inverseRenderMatrixProxy = null;
 }
コード例 #9
0
 private void SetTransform(TransMatrix2D transform)
 {
     graphics.Transform = transform.ToGDIPlusMatrix();
 }
コード例 #10
0
 private TransMatrix2D GetTransform()
 {
     return(TransMatrix2D.FromGDIPlusMatrix(graphics.Transform));
 }
コード例 #11
0
 /// <summary>
 /// IRenderer was updated to use acessors, an extension for the old
 /// set method reduces the amount of updates required.
 /// </summary>
 public static void SetTransform(this IRenderer renderer, TransMatrix2D transform)
 {
     renderer.Transform = transform;
 }