コード例 #1
0
        public void TestMatrix2()
        {
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Rotate(30);
            mat.Translate(-20, 20);

            var at = new AffineCoordinateTransformation2D(mat);
            var atInv = at.Inverse();

            var p0 = new double[] { 50d, 50d };
            var pt = at.Transform(p0);
            at.Invert();
            var p1 = at.Transform(pt);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[0] - p0[0]), 0.01d);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[1] - p0[1]), 0.01d);
            var p2 = atInv.Transform(pt);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[0] - p0[0]), 0.01d);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[1] - p0[1]), 0.01d);

            
            System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

            mat.TransformPoints(pts);
            System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
            System.Drawing.PointF ptt = pts[0];
            System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
            System.Drawing.Drawing2D.Matrix inv = mat.Clone();
            inv.Invert();
            inv.TransformPoints(ptts);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
            NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);

        }
コード例 #2
0
        public static bool LineIntersectsRect(Matrix rayMatrix, Rectangle r)
        {
            Matrix m = rayMatrix.Clone();

            m.Translate(200, 0);
            return(LineIntersectsRect(new System.Drawing.Point((int)rayMatrix.OffsetX, (int)rayMatrix.OffsetY), new System.Drawing.Point((int)m.OffsetX, (int)m.OffsetY), r));
        }
コード例 #3
0
        void DrawCustomItem(Graphics g, int index, int x, int y)
        {
            MemoryStream ms = new MemoryStream();

            switch (index)
            {
            case 1:
                ResourceImages.Enabled.Save(ms, ImageFormat.Png);
                break;

            case 2:
                ResourceImages.Disabled.Save(ms, ImageFormat.Png);
                break;
            }
            System.Drawing.Image image = System.Drawing.Image.FromStream(ms);

            //flip the image around its center
            using (System.Drawing.Drawing2D.Matrix m = g.Transform)
            {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                {
                    float c = (float)y;

                    using (System.Drawing.Drawing2D.Matrix m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * c))
                        m.Multiply(m2);

                    //g.Transform = m;
                    g.DrawImage(image, new PointF((float)(x), (float)(y)));
                    g.Transform = saveM;
                }
            }
        }
コード例 #4
0
 public void SetImage(Bitmap bitmap, string studyUID, string seriesUID, int windowWidth,
                      int windowsLevel, int index, System.Drawing.Drawing2D.Matrix matrix)
 {
     Bitmap        = bitmap;
     _studyUID     = studyUID;
     _seriesUID    = seriesUID;
     _windowWidth  = windowWidth;
     _windowsLevel = windowsLevel;
     _index        = index;
     _matrix       = new System.Drawing.Drawing2D.Matrix();
     if (matrix != null)
     {
         _matrix = matrix.Clone();
         //for (int i = 0; i < matrix.Elements.Length; i++)
         //{
         //    _matrix.Elements[i] = matrix.Elements[i];
         //}
     }
     //Bitmap bitmap = MainWindowMA.Instance.GetCTBitmap();
     Console.WriteLine("btnSelectImage_MouseDown");
     if (bitmap != null)
     {
         image.Source = ToBitmapSource(bitmap);
         image.MouseLeftButtonDown += image_MouseDown;
         image.Visibility           = System.Windows.Visibility.Visible;
         //close.Visibility = System.Windows.Visibility.Visible;
     }
 }
コード例 #5
0
ファイル: Util.cs プロジェクト: andyhebear/mogregis3d
        public static System.Drawing.Drawing2D.Matrix multiply(System.Drawing.Drawing2D.Matrix a, System.Drawing.Drawing2D.Matrix b)
        {
            //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.clone' was converted to 'System.Drawing.Drawing2D.Matrix.Clone' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformclone_3"'
            System.Drawing.Drawing2D.Matrix tm = (System.Drawing.Drawing2D.Matrix)a.Clone();

            //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.concatenate' was converted to 'System.Drawing.Drawing2D.Matrix.Multiply' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformconcatenate_javaawtgeomAffineTransform_3"'
            tm.Multiply(b, System.Drawing.Drawing2D.MatrixOrder.Append);

            return(tm);
        }
コード例 #6
0
ファイル: SubClass.cs プロジェクト: ParisNagoya/Manta
        /// <summary>
        /// マウスポインタの位置の画像の輝度値を表示
        /// </summary>
        /// <param name="mat">画像を表示しているアフィン変換行列</param>
        /// <param name="image">表示している画像</param>
        /// <param name="pointPictureBox">表示先のピクチャボックス</param>
        private void DispPixelInfo(System.Drawing.Drawing2D.Matrix mat,
                                   ImagingSolution.Imaging.ImageData image, PointF pointPictureBox)
        {
            if (image == null)
            {
                return;
            }

            // ピクチャボックス→画像上の座標のアフィン変換行列
            var matInvert = mat.Clone();

            matInvert.Invert();

            // 画像上の座標
            var pointImage = new PointF[1];

            pointImage[0] = pointPictureBox;
            matInvert.TransformPoints(pointImage);

            int picX = (int)Math.Floor(pointImage[0].X + 0.5);
            int picY = (int)Math.Floor(pointImage[0].Y + 0.5);

            string bright = " = ";

            if (
                (picX >= 0) &&              // ポインタ座標が画像の範囲内の場合
                (picY >= 0) &&
                (picX < image.Width) &&
                (picY < image.Height) &&
                (image.ImageBit >= 24)    // カラー画像の場合
                )
            {
                bright += "(" +
                          image[picY, picX, 2].ToString() + ", " + // R
                          image[picY, picX, 1].ToString() + ", " + // G
                          image[picY, picX, 0].ToString() + ")";   // B
            }
            else
            {
                bright += image[picY, picX].ToString();
            }

            // 輝度値の表示(モノクロを除く)

            /**
             * lblPixelInfo.Text =
             *  "(" +
             *  picX.ToString() + ", " +
             *  picY.ToString() + ")" +
             *  bright;
             **/
        }
コード例 #7
0
        protected override bool InitializeTransformMatrix()
        {
            if (this.CurveList == null)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("No data to display...");
            StockLog.Write(e);
            throw e;
             }
             if (this.GraphRectangle.Height > 0)
             {
            EventSeries.Clear();

            // Create fake Event Series;
            for (int i = 0; i < 5; i++)
            {
               EventSeries.Add(new BoolSerie(this.EndIndex, "Test" + i, i%2 == 0));
            }

            minValue = 0.0f;
            maxValue = EventSeries.Count + 1;

            if (graphic == null)
            {
               // Initialise graphics
               this.graphic = this.CreateGraphics();
               RectangleF rect = this.graphic.VisibleClipBounds;
               rect.Inflate(new SizeF(-this.XMargin, -this.YMargin));
               this.GraphRectangle = rect;
            }

            float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
            float coefY = this.GraphRectangle.Height / (maxValue - minValue);

            matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
            matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, maxValue * coefY + this.GraphRectangle.Y);
            matrixValueToScreen.Scale(coefX, -coefY);

            matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
            matrixScreenToValue.Invert();
             }
             else
             {
            this.Deactivate("App too small...", false);
            return false;
             }
             return true;
        }
コード例 #8
0
        protected override bool InitializeTransformMatrix()
        {
            if (this.CurveList == null)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("No data to display...");
            StockLog.Write(e);
            throw e;
             }
             if (this.GraphRectangle.Height > 0)
             {
            minValue = float.MaxValue;
            maxValue = float.MinValue;
            this.CurveList.GetMinMax(StartIndex, EndIndex, ref minValue, ref maxValue, this.ScaleInvisible);

            if (minValue == maxValue || float.IsNaN(minValue) || float.IsInfinity(minValue) || float.IsNaN(maxValue) || float.IsInfinity(maxValue))
            {
               this.Deactivate("No volume for this stock", false);
               return false;
            }
            if (graphic == null)
            {
               // Initialise graphics
               this.graphic = this.CreateGraphics();
               RectangleF rect = this.graphic.VisibleClipBounds;
               rect.Inflate(new SizeF(-this.XMargin, -this.YMargin));
               this.GraphRectangle = rect;
            }

            float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
            float coefY = this.GraphRectangle.Height / (maxValue - minValue);

            matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
            matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, maxValue * coefY + this.GraphRectangle.Y);
            matrixValueToScreen.Scale(coefX, -coefY);

            matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
            matrixScreenToValue.Invert();
             }
             else
             {
            this.Deactivate("App too small...", false);
            return false;
             }
             return true;
        }
コード例 #9
0
            public void TestMatrix()
            {
                var p = new NetTopologySuite.Geometries.Point(10, 10);
                var b = p.AsBinary();

                System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                mat.Rotate(30);
                mat.Translate(-20, 20);
                System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

                mat.TransformPoints(pts);
                System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
                System.Drawing.PointF           ptt  = pts[0];
                System.Drawing.PointF[]         ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
                System.Drawing.Drawing2D.Matrix inv  = mat.Clone();
                inv.Invert();
                inv.TransformPoints(ptts);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);
            }
コード例 #10
0
ファイル: Graphics.cs プロジェクト: andyhebear/mogregis3d
            public virtual System.Object Clone()
            {
                try
                {
                    State s = (State)base.MemberwiseClone();

                    s.textPosition = new float[textPosition.Length];
                    textPosition.CopyTo(s.textPosition, 0);
                    //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.clone' was converted to 'System.Drawing.Drawing2D.Matrix.Clone' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformclone_3"'
                    s.transform = (System.Drawing.Drawing2D.Matrix)transform.Clone();

                    return(s);
                }
                //UPGRADE_NOTE: Exception 'java.lang.CloneNotSupportedException' was converted to 'System.Exception' which has different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1100_3"'
                catch (System.Exception e)
                {
                    Console.WriteLine("Error " + e);
                    return(null);
                }
            }
コード例 #11
0
        public static System.Drawing.Drawing2D.Matrix RotateGraphics(
            System.Drawing.Graphics g,
            System.Drawing.Rectangle Bounds,
            float Angle)
        {
            //			System.Drawing.Point cp = RectangleCommon.Center( Bounds );
            //			System.Drawing.Rectangle rect = new System.Drawing.Rectangle (
            //				cp.X - ContentBounds.Width / 2 ,
            //				cp.Y - ContentBounds.Height / 2 ,
            //				ContentBounds.Width ,
            //				ContentBounds.Height );


            System.Drawing.Drawing2D.Matrix om = g.Transform;
            System.Drawing.Drawing2D.Matrix nm = om.Clone();
            System.Drawing.Point            p  = RectangleCommon.Center(Bounds);
            nm.RotateAt(Angle, new System.Drawing.PointF(p.X, p.Y));
            g.Transform = nm;
            return(om);
        }
コード例 #12
0
        protected override bool InitializeTransformMatrix()
        {
            if (float.IsNaN(this.RangeMin) || float.IsNaN(this.RangeMax))
             {
            return base.InitializeTransformMatrix();
             }

             if (this.CurveList == null)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("No data to display...");
            throw e;
             }
             if (this.CurveList.GetNbVisible() == 0)
             {
            this.Deactivate("No data to display...", false);
            return false;
             }
             if (this.StartIndex == this.EndIndex || this.EndIndex > this.dateSerie.Length - 1)
             {
            this.IsInitialized = false;
            InvalidSerieException e = new InvalidSerieException("Invalid input data range...");
            throw e;
             }
             if (this.GraphRectangle.Height > 0)
             {
            float minValue = this.RangeMin, maxValue = this.RangeMax;
            float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
            float coefY = this.GraphRectangle.Height / (maxValue - minValue);

            matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
            matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, maxValue * coefY + this.GraphRectangle.Y);
            matrixValueToScreen.Scale(coefX, -coefY);

            matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
            matrixScreenToValue.Invert();
            return true;
             }
             return false;
        }
コード例 #13
0
        /// <summary>
        /// Main Overloaded Node Drawing
        /// Functionality Copied from examples and by looking at how it is implemeted by Default
        ///
        /// The major difference between this DrawNode and Default behavior is to allow an Image to be in the node
        /// For a visual Cue.
        /// </summary>
        /// <param name="node"></param>
        /// <param name="graphics"></param>
        /// <returns></returns>
        bool DrawNode(DrawingNode node, object graphics)
        {
            Graphics g     = (Graphics)graphics;
            Image    image = getGroupImage(node.UserData);
            //Set Alpha on Given Fill Color so Image Can show Through..
            //node.Attr.FillColor = new DrawingColor(100, node.Attr.FillColor.R,node.Attr.FillColor.G,node.Attr.FillColor.B);
            Color      border      = Color.FromArgb(node.Attr.Color.R, node.Attr.Color.G, node.Attr.Color.B);
            Pen        borderPen   = new Pen(border, (float)node.Attr.LineWidth);
            SolidBrush borderBrush = new SolidBrush(border);

            Color fill = Color.FromArgb(200, node.Attr.FillColor.R, node.Attr.FillColor.G, node.Attr.FillColor.B);


            using (System.Drawing.Drawing2D.Matrix m = g.Transform)
            {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                {
                    System.Drawing.Drawing2D.GraphicsPath path = FillTheGraphicsPath(node.GeometryNode.BoundaryCurve);

                    g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));
                    using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y))
                        m.Multiply(m2);

                    g.Transform = m;

                    g.FillPath(new SolidBrush(fill), path); //Fill the inside
                    g.DrawImage(image, new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2) + 2, (float)(node.GeometryNode.Center.Y - node.GeometryNode.Height / 2) + 2));
                    Font f = new Font(node.Label.FontName, (float)node.Label.FontSize, (System.Drawing.FontStyle)(int) node.Label.FontStyle);
                    g.DrawString(node.LabelText, f, new SolidBrush(ForeColor),
                                 new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2 + image.Width), (float)(node.GeometryNode.Center.Y - g.MeasureString(node.LabelText, f).Height / 2)));
                    g.DrawPath(borderPen, path); // Draw the Border

                    g.Transform = saveM;
                    g.ResetClip();
                }
            }
            image.Dispose();
            return(true);//returning false would enable the default rendering
        }
コード例 #14
0
        private bool IntersectsWith(Matrix sourceMatrix, Rectangle rect)
        {
            Matrix rayMatrix = sourceMatrix.Clone();

            rayMatrix.Translate(250, 0);

            var X  = sourceMatrix.OffsetX;
            var Y  = sourceMatrix.OffsetY;
            var Xd = rayMatrix.OffsetX;
            var Yd = rayMatrix.OffsetY;

            float tmin = (rect.Left - X) / Xd;
            float tmax = (rect.Right - X) / Xd;

            if (tmin > tmax)
            {
                var temp = tmin;
                tmin = tmax;
                tmax = temp;
            }

            float tymin = (rect.Bottom - Y) / Yd;
            float tymax = (rect.Top - Y) / Yd;

            if (tymin > tymax)
            {
                var temp = tymin;
                tymin = tymax;
                tymax = temp;
            }

            if ((tmin > tymax) || (tymin > tmax))
            {
                return(false);
            }

            return(true);
        }
コード例 #15
0
ファイル: Graphics.cs プロジェクト: andyhebear/mogregis3d
 /// <summary> Constructs a new Graphics object using the given SceneContainer as
 /// the root node. The transformation matrix of the root node is also
 /// given. This matrix is used to position hinted glyphs properly.
 ///
 /// </summary>
 /// <param name="scene">The root node into which graphics is drawn.
 /// </param>
 /// <param name="transform">The transformation matrix of the root node.
 /// </param>
 public Graphics(SceneContainer scene, System.Drawing.Drawing2D.Matrix transform)
 {
     //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1156_3"'
     stateStack  = new Stack <State>();
     state       = newState();
     state.scene = scene;
     //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.clone' was converted to 'System.Drawing.Drawing2D.Matrix.Clone' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformclone_3"'
     state.transform = (System.Drawing.Drawing2D.Matrix)transform.Clone();
     //UPGRADE_NOTE: If the given Font Name does not exist, a default Font instance is created. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1075_3"'
     //UPGRADE_TODO: Field 'java.awt.Font.PLAIN' was converted to 'System.Drawing.FontStyle.Regular' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtFontPLAIN_f_3"'
     state.font                      = new System.Drawing.Font("SansSerif", 12, System.Drawing.FontStyle.Regular);
     state.strokeColor               = new ScenicColor(0, 0, 0);
     state.fillColor                 = state.strokeColor;
     state.lineWidth                 = 1.0f;
     state.lineCap                   = LineCapStyle.BUTT_CAP;
     state.lineJoin                  = LineJoinStyle.BEVEL_JOIN;
     state.miterLimit                = 10.0f;
     state.lineDashLengths           = null;
     state.lineDashPhase             = 0.0f;
     state.fillRule                  = FillRule.ODD_WINDING;
     state.usesFractionalFontMetrics = false;
     path = new PathBuilder();
 }
コード例 #16
0
        bool DrawNode(DrawingNode node, object graphics)
        {
            Graphics g     = (Graphics)graphics;
            Image    image = ImageOfNode(node);

            //flip the image around its center
            using (System.Drawing.Drawing2D.Matrix m = g.Transform)
            {
                using (System.Drawing.Drawing2D.Matrix saveM = m.Clone())
                {
                    g.SetClip(FillTheGraphicsPath(node.GeometryNode.BoundaryCurve));
                    using (var m2 = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 2 * (float)node.GeometryNode.Center.Y))
                        m.Multiply(m2);

                    g.Transform = m;
                    g.DrawImage(image, new PointF((float)(node.GeometryNode.Center.X - node.GeometryNode.Width / 2),
                                                  (float)(node.GeometryNode.Center.Y - node.GeometryNode.Height / 2)));
                    g.Transform = saveM;
                }
            }

            return(true);//returning false would enable the default rendering
        }
コード例 #17
0
        /// <summary>
        /// 画像の移動
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void picImage_MouseMove(object sender, MouseEventArgs e)
        {
            // マウスをクリックしながら移動中のとき、画像の移動
            if (_mouseDownFlg == true)
            {
                // 画像の移動
                _matAffine.Translate(e.X - _oldPoint.X, e.Y - _oldPoint.Y,
                                     System.Drawing.Drawing2D.MatrixOrder.Append);
                // 画像の描画
                RedrawImage();

                // ポインタ位置の保持
                _oldPoint.X = e.X;
                _oldPoint.Y = e.Y;
            }

            ////////////////////////////
            // マウスポインタの座標と画像の座標を表示する

            // マウスポインタの座標
            lblMousePointer.Text = $"Mouse {e.Location}";

            // アフィン変換行列(画像座標→ピクチャボックス座標)の逆行列(ピクチャボックス座標→画像座標)を求める
            // Invertで元の行列が上書きされるため、Cloneを取ってから逆行列
            var invert = _matAffine.Clone();

            invert.Invert();

            var pf = new PointF[] { e.Location };

            // ピクチャボックス座標を画像座標に変換する
            invert.TransformPoints(pf);

            // 画像の座標
            lblImagePointer.Text = $"Image {pf[0]}";
        }
コード例 #18
0
ファイル: DUIMatrix.cs プロジェクト: scjjcs/DirectUI
 public DUIMatrix(System.Drawing.Drawing2D.Matrix matrix)
 {
     this.matrix = matrix.Clone();
     RefreshMatrix3x2();
 }
コード例 #19
0
ファイル: Graphics.cs プロジェクト: andyhebear/mogregis3d
 /// <summary> Multiplies the current transformation matrix with the
 /// given affine transform.
 ///
 /// </summary>
 /// <param name="m">the affine transform
 /// </param>
 public virtual void transform(System.Drawing.Drawing2D.Matrix m)
 {
     //UPGRADE_TODO: Method 'java.awt.geom.AffineTransform.clone' was converted to 'System.Drawing.Drawing2D.Matrix.Clone' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtgeomAffineTransformclone_3"'
     transformImpl((System.Drawing.Drawing2D.Matrix)m.Clone());
 }
コード例 #20
0
        protected override bool InitializeTransformMatrix()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (!CheckGraphSanity()) { return false; }
            if (this.GraphRectangle.Height > 0)
            {
               minValue = float.MaxValue;
               maxValue = float.MinValue;
               this.CurveList.GetMinMax(0, dateSerie.Length - 1, ref minValue, ref maxValue, this.ScaleInvisible);

               if (minValue == maxValue || minValue == float.MaxValue || float.IsNaN(minValue) || float.IsInfinity(minValue) || maxValue == float.MinValue || float.IsNaN(maxValue) || float.IsInfinity(maxValue))
               {
                  this.Deactivate("Input data is corrupted and cannot be displayed...", false);
                  return false;
               }

               if (this.IsLogScale && minValue > 0)
               {
                  minValue -= (maxValue - minValue) * 0.025f;
               }
               else
               {
                  minValue -= (maxValue - minValue) * 0.05f;
               }
               maxValue += (maxValue - minValue) * 0.05f;

               float tmpMinValue, tmpMaxValue;
               if (this.IsLogScale)
               {
                  tmpMinValue = minValue < 0 ? (float)-Math.Log10(-minValue + 1) : (float)Math.Log10(minValue + 1);
                  tmpMaxValue = maxValue < 0 ? (float)-Math.Log10(-maxValue + 1) : (float)Math.Log10(maxValue + 1);
               }
               else
               {
                  tmpMinValue = minValue;
                  tmpMaxValue = maxValue;
               }

               float coefX = (this.GraphRectangle.Width * 0.94f) / (dateSerie.Length - 1);
               float coefY = this.GraphRectangle.Height / (tmpMaxValue - tmpMinValue);

               matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
               matrixValueToScreen.Translate(this.GraphRectangle.X + 20, tmpMaxValue * coefY + this.GraphRectangle.Y);
               matrixValueToScreen.Scale(coefX, -coefY);

               matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
               matrixScreenToValue.Invert();
            }
            else
            {
               this.Deactivate("App too small...", false);
               return false;
            }
            return true;
             }
        }
コード例 #21
0
 public bool LineIntersectsRect(Matrix rayMatrix, Rectangle r)
 {
     Matrix m = rayMatrix.Clone();
     m.Translate(200, 0);
     return LineIntersectsRect(
         new System.Drawing.Point((int)rayMatrix.OffsetX, (int)rayMatrix.OffsetY),
         new System.Drawing.Point((int)m.OffsetX, (int)m.OffsetY),
         r);
 }
コード例 #22
0
        private void DrawFillPattern(Graphics g)
        {
            Stopwatch sw = Stopwatch.StartNew();
            float matrixScale;
            var fillPattern = FillPattern;
            if (fillPattern == null)
                return;

            if (fillPattern.Target == FillPatternTarget.Model)
                matrixScale = Scale;
            else
                matrixScale = Scale * 10;

            try
            {
                var width =
                    (ActualWidth == 0 ? Width : ActualWidth) == 0
                    ? 100
                    : (ActualWidth == 0 ? Width : ActualWidth);

                if (double.IsNaN(width))
                    width = 100;

                var height =
                    (ActualHeight == 0 ? Height : ActualHeight) == 0
                    ? 30
                    : (ActualHeight == 0 ? Height : ActualHeight);

                if (double.IsNaN(height))
                    height = 30;

                var viewRect = new Rectangle(0, 0,
                                             (int)width, (int)height);

                var centerX = (viewRect.Left + viewRect.Left
                               + viewRect.Width) / 2;

                var centerY = (viewRect.Top + viewRect.Top
                               + viewRect.Height) / 2;

                g.TranslateTransform(centerX, centerY);

                var rectF = new Rectangle(-1, -1, 2, 2);
                g.FillRectangle(Brushes.Blue, rectF); //draw a small rectangle in the center of the image

                g.ResetTransform();

                var fillGrids = fillPattern.GetFillGrids();

                Debug.Print(new string('-', 100));
                Debug.Print("FilPattern name: {0}", fillPattern.Name);
                if (fillPattern.Target == FillPatternTarget.Model)
                    Debug.Print("FillPattern type: Model");
                else
                    Debug.Print("FillPattern type: Drafting");
                Debug.Print("Matrix scale: {0}", matrixScale);
                Debug.Print("Grids count: {0}", fillGrids.Count);
                Debug.Print("Len\\Area: {0}", fillPattern.LengthPerArea);
                Debug.Print("Lines\\Len: {0}", fillPattern.LinesPerLength);
                Debug.Print("Strokes\\Area: {0}", fillPattern.StrokesPerArea);

                foreach (var fillGrid in fillGrids)
                {
                    var degreeAngle = (float)RadianToGradus(fillGrid.Angle);
                    Debug.Print(new string('-', 50));
                    Debug.Print("Origin: U:{0} V:{1}",
                                fillGrid.Origin.U, fillGrid.Origin.V);
                    Debug.Print("Offset: {0}", fillGrid.Offset);
                    Debug.Print("Angle: {0}", degreeAngle);
                    Debug.Print("Shift: {0}", fillGrid.Shift);

                    var pen = new Pen(System.Drawing.Color.Black)
                    {
                        Width = 1f / matrixScale
                    };

                    float dashLength = 1;
                    var segments = fillGrid.GetSegments();

                    if (segments.Count > 0)
                    {
                        pen.DashPattern = segments
                            .Select(Convert.ToSingle)
                            .ToArray();

                        Debug.Print("\tSegments:");
                        foreach (var segment in segments)
                        {
                            Debug.Print("\t\t{0}", segment);
                        }

                        dashLength = pen.DashPattern.Sum();
                    }

                    g.ResetTransform();
                    var rotateMatrix = new Matrix();
                    rotateMatrix.Rotate(degreeAngle);
                    var matrix = new Matrix(1, 0,
                                            0, -1,
                                            centerX, centerY); //-1 reflects about x-axis
                    matrix.Scale(matrixScale, matrixScale);
                    matrix.Translate((float)fillGrid.Origin.U,
                                     (float)fillGrid.Origin.V);
                    var backMatrix = matrix.Clone();
                    backMatrix.Multiply(rotateMatrix);
                    matrix.Multiply(rotateMatrix);

                    var offset = (-10) * dashLength;
                    matrix.Translate(offset, 0);
                    backMatrix.Translate(offset, 0);
                    Debug.Print("Offset: {0}", offset);

                    bool moving_forward = true;
                    bool moving_back = true;
                    int safety = 500;
                    double alternator = 0;
                    while (moving_forward || moving_back)    //draw segments shifting and offsetting each time
                    {
                        Debug.Write("*");
                        var rectF1 = new RectangleF(-2 / matrixScale, -2 / matrixScale, 4 / matrixScale, 4 / matrixScale);

                        if (moving_forward && LineIntersectsRect(matrix, viewRect))
                        {
                            g.Transform = matrix;
                            g.DrawLine(pen, new PointF(0, 0), new PointF(LENGTH, 0));
                        }
                        else
                        {
                            moving_forward = false;
                            Debug.Print("\n----> Matrix does not intersect view");
                        }

                        if (moving_back && LineIntersectsRect(backMatrix, viewRect))
                        {
                            g.Transform = backMatrix;
                            g.DrawLine(pen, new PointF(0, 0), new PointF(LENGTH, 0));
                        }
                        else
                        {
                            moving_back = false;
                            Debug.Print("\n----> Back matrix does not intersect view");
                        }

                        if (safety == 0)
                        {
                            Debug.Print("\n--------> Safety limit exceeded");
                            break;
                        }
                        else
                            --safety;

                        matrix.Translate((float)fillGrid.Shift,
                                         (float)fillGrid.Offset);
                        backMatrix.Translate(-(float)fillGrid.Shift,
                                             -(float)fillGrid.Offset);

                        alternator += fillGrid.Shift;
                        if (Math.Abs(alternator) > Math.Abs(offset))
                        {
                            Debug.Print("\n----> Alternating");
                            matrix.Translate(offset, 0);
                            backMatrix.Translate(offset, 0);
                            alternator = 0d;
                        }
                    }
                }
                sw.Stop();
                g.ResetTransform();
            #if DEBUG
                g.DrawString(string.Format("{0} ms",
                                           sw.ElapsedMilliseconds),
                             System.Drawing.SystemFonts.DefaultFont,
                             Brushes.Red, 0, 0);
            #endif
                Debug.Print(new string('-', 50));

                Pen p = new Pen(System.Drawing.Color.Black);
                p.Width = 1f / matrixScale;
                Debug.Print("Finished");
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
            }
        }
コード例 #23
0
ファイル: AWTShapePath.cs プロジェクト: andyhebear/mogregis3d
        public virtual void  walk(PathWalker walker, System.Drawing.Drawing2D.Matrix errorMatrix, double error)
        {
            //UPGRADE_TODO: Interface 'java.awt.geom.PathIterator' was converted to 'System.Drawing.Drawing2D.GraphicsPathIterator' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_3"'
            //UPGRADE_TODO: Method 'java.awt.Shape.getPathIterator' was converted to 'System.Drawing.Drawing2D.GraphicsPathIterator.GraphicsPathIterator' which has a different behavior. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1073_javaawtShapegetPathIterator_javaawtgeomAffineTransform_double_3"'
            System.Drawing.Drawing2D.GraphicsPathIterator itr = new System.Drawing.Drawing2D.GraphicsPathIterator(shape);
            double[] point = new double[6];
            int      i     = 0;

            System.Drawing.Drawing2D.Matrix inv;
            double m00, m01, m10, m11, dx, dy;

            try
            {
                System.Drawing.Drawing2D.Matrix temp_Matrix;
                temp_Matrix = new System.Drawing.Drawing2D.Matrix();
                temp_Matrix = errorMatrix.Clone();
                temp_Matrix.Invert();
                inv = temp_Matrix;
            }
            catch (System.Exception e)
            {
                return;
            }

            m00 = (float)inv.Elements.GetValue(0);
            m01 = (float)inv.Elements.GetValue(2);
            m10 = (float)inv.Elements.GetValue(1);
            m11 = (float)inv.Elements.GetValue(3);
            dx  = (System.Single)inv.OffsetX;
            dy  = (System.Single)inv.OffsetY;

            //UPGRADE_ISSUE: Method 'java.awt.geom.PathIterator.isDone' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomPathIteratorisDone_3"'
            while (!itr.isDone())
            {
                //UPGRADE_ISSUE: Method 'java.awt.geom.PathIterator.currentSegment' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomPathIteratorcurrentSegment_double[]_3"'
                int type = itr.currentSegment(point);

                //UPGRADE_ISSUE: Method 'java.awt.geom.PathIterator.next' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomPathIteratornext_3"'
                itr.next();
                //UPGRADE_ISSUE: Field 'java.awt.geom.PathIterator.SEG_MOVETO' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomPathIteratorSEG_MOVETO_f_3"'
                if (type == PathIterator.SEG_MOVETO)
                {
                    if (i > 0)
                    {
                        walk(walker, points, i, false);
                        i = 0;
                    }
                    points[i++] = m00 * point[0] + m01 * point[1] + dx;
                    points[i++] = m10 * point[0] + m11 * point[1] + dy;
                }
                else
                {
                    //UPGRADE_ISSUE: Field 'java.awt.geom.PathIterator.SEG_LINETO' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomPathIteratorSEG_LINETO_f_3"'
                    if (type == PathIterator.SEG_LINETO)
                    {
                        points[i++] = m00 * point[0] + m01 * point[1] + dx;
                        points[i++] = m10 * point[0] + m11 * point[1] + dy;
                    }
                    else
                    {
                        //UPGRADE_ISSUE: Field 'java.awt.geom.PathIterator.SEG_CLOSE' was not converted. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1000_javaawtgeomPathIteratorSEG_CLOSE_f_3"'
                        if (type == PathIterator.SEG_CLOSE)
                        {
                            if (i > 0)
                            {
                                walk(walker, points, i, true);
                                i = 0;
                            }
                        }
                    }
                }
            }
            if (i > 0)
            {
                walk(walker, points, i, false);
                i = 0;
            }
        }
コード例 #24
0
        private void DrawFillPattern(Graphics gfx, double width, double height)
        {
            // verify fill pattern
            var fillPattern = FillPattern;

            if (fillPattern == null)
            {
                return;
            }

            // determine drawing scale
            float matrixScale;

            if (fillPattern.Target == FillPatternTarget.Model)
            {
                matrixScale = _scale;
            }
            else
            {
                matrixScale = _scale * 10;
            }

            // prepare pen
            var pen = new Pen(System.Drawing.Color.Black)
            {
                Width = 1f / matrixScale
            };

            try {
                // setup rectangle and center
                var viewRect = new Rectangle(0, 0, (int)width, (int)height);
                var centerX  = (viewRect.Left + viewRect.Left + viewRect.Width) / 2;
                var centerY  = (viewRect.Top + viewRect.Top + viewRect.Height) / 2;

                gfx.ResetTransform();

                // draw each fill grid
                foreach (var fillGrid in fillPattern.GetFillGrids())
                {
                    // radian to degree: inline math is faster
                    var degreeAngle = (float)(fillGrid.Angle * 180 / Math.PI);

                    // setup pen dash
                    float dashLength = 1;
                    var   segments   = fillGrid.GetSegments();
                    if (segments.Count > 0)
                    {
                        pen.DashPattern = segments.Select(Convert.ToSingle).ToArray();
                        dashLength      = pen.DashPattern.Sum();
                    }

                    gfx.ResetTransform();
                    // determine offset and rotation
                    var offset       = (-10) * dashLength;
                    var rotateMatrix = new Matrix();
                    rotateMatrix.Rotate(degreeAngle);

                    var matrix = new Matrix(1, 0, 0, -1, centerX, centerY);
                    matrix.Scale(matrixScale, matrixScale);
                    matrix.Translate((float)fillGrid.Origin.U, (float)fillGrid.Origin.V);

                    // make a copy for backward move
                    var backMatrix = matrix.Clone();

                    matrix.Multiply(rotateMatrix);
                    matrix.Translate(offset, 0);

                    backMatrix.Multiply(rotateMatrix);
                    backMatrix.Translate(offset, 0);

                    int    safety     = 250;
                    double alternator = 0;

                    // draw moving forward
                    while (IntersectsWith(matrix, viewRect) && safety > 0)
                    {
                        gfx.Transform = matrix;
                        gfx.DrawLine(pen, 0, 0, _length, 0);

                        matrix.Translate((float)fillGrid.Shift, (float)fillGrid.Offset);

                        alternator += fillGrid.Shift;
                        if (Math.Abs(alternator) > Math.Abs(offset))
                        {
                            matrix.Translate(offset, 0);
                            alternator = 0d;
                        }

                        --safety;
                    }

                    // draw moving backward
                    safety     = 250;
                    alternator = 0;
                    while (IntersectsWith(backMatrix, viewRect) && safety > 0)
                    {
                        gfx.Transform = backMatrix;
                        gfx.DrawLine(pen, 0, 0, _length, 0);

                        backMatrix.Translate(-(float)fillGrid.Shift, -(float)fillGrid.Offset);

                        alternator += fillGrid.Shift;
                        if (Math.Abs(alternator) > Math.Abs(offset))
                        {
                            backMatrix.Translate(offset, 0);
                            alternator = 0d;
                        }

                        --safety;
                    }
                }
            }
            catch (Exception ex) {
                logger.Debug(ex.ToString());
            }
        }
コード例 #25
0
            public void TestMatrix()
            {
                SharpMap.Geometries.Point p = new Point(10, 10);
                var b = p.AsBinary();

                System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                mat.Rotate(30);
                mat.Translate(-20, 20);
                System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

                mat.TransformPoints(pts);
                System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
                System.Drawing.PointF ptt = pts[0];
                System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
                System.Drawing.Drawing2D.Matrix inv = mat.Clone();
                inv.Invert();
                inv.TransformPoints(ptts);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);
            }
コード例 #26
0
            public void TestMatrix2()
            {
                System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
                mat.Rotate(30);
                mat.Translate(-20, 20);

                var at = new AffineCoordinateTransformation2D(mat);
                var atInv = at.Inverse();

                var p0 = new double[] { 50d, 50d };
                var pt = at.Transform(p0);
                at.Invert();
                var p1 = at.Transform(pt);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[0] - p0[0]), 0.01d);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p1[1] - p0[1]), 0.01d);
                var p2 = atInv.Transform(pt);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[0] - p0[0]), 0.01d);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(p2[1] - p0[1]), 0.01d);

                System.Drawing.PointF[] pts = new System.Drawing.PointF[] { new System.Drawing.PointF(50, 50) };

                mat.TransformPoints(pts);
                System.Diagnostics.Debug.WriteLine(string.Format("POINT ({0} {1})", pts[0].X, pts[0].Y));
                System.Drawing.PointF ptt = pts[0];
                System.Drawing.PointF[] ptts = new System.Drawing.PointF[] { new System.Drawing.PointF(ptt.X, ptt.Y) };
                System.Drawing.Drawing2D.Matrix inv = mat.Clone();
                inv.Invert();
                inv.TransformPoints(ptts);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].X - 50f), 0.01);
                NUnit.Framework.Assert.LessOrEqual(System.Math.Abs(ptts[0].Y - 50f), 0.01);
            }
コード例 #27
0
        private void DrawFillPattern(Graphics g)
        {
            Stopwatch sw = Stopwatch.StartNew();
            float     matrixScale;
            var       fillPattern = FillPattern;

            if (fillPattern == null)
            {
                return;
            }

            if (fillPattern.Target == FillPatternTarget.Model)
            {
                matrixScale = Scale;
            }
            else
            {
                matrixScale = Scale * 10;
            }

            try
            {
                var width
                    = (ActualWidth == 0 ? Width : ActualWidth) == 0
            ? 100
            : (ActualWidth == 0 ? Width : ActualWidth);

                if (double.IsNaN(width))
                {
                    width = 100;
                }

                var height
                    = (ActualHeight == 0 ? Height : ActualHeight) == 0
            ? 30
            : (ActualHeight == 0 ? Height : ActualHeight);

                if (double.IsNaN(height))
                {
                    height = 30;
                }

                var viewRect = new Rectangle(
                    0, 0, (int)width, (int)height);

                var centerX = (viewRect.Left
                               + viewRect.Left + viewRect.Width) / 2;

                var centerY = (viewRect.Top
                               + viewRect.Top + viewRect.Height) / 2;

                g.TranslateTransform(centerX, centerY);

                var rectF = new Rectangle(-1, -1, 2, 2);
                g.FillRectangle(Brushes.Blue, rectF); //draw a small rectangle in the center of the image

                g.ResetTransform();

                var fillGrids = fillPattern.GetFillGrids();

                Debug.Print(new string( '-', 100 ));
                Debug.Print("FilPattern name: {0}", fillPattern.Name);
                if (fillPattern.Target == FillPatternTarget.Model)
                {
                    Debug.Print("FillPattern type: Model");
                }
                else
                {
                    Debug.Print("FillPattern type: Drafting");
                }
                Debug.Print("Matrix scale: {0}", matrixScale);
                Debug.Print("Grids count: {0}", fillGrids.Count);
                Debug.Print("Len\\Area: {0}", fillPattern.LengthPerArea);
                Debug.Print("Lines\\Len: {0}", fillPattern.LinesPerLength);
                Debug.Print("Strokes\\Area: {0}", fillPattern.StrokesPerArea);

                foreach (var fillGrid in fillGrids)
                {
                    var degreeAngle = (float)RadianToGradus(fillGrid.Angle);
                    Debug.Print(new string( '-', 50 ));
                    Debug.Print("Origin: U:{0} V:{1}",
                                fillGrid.Origin.U, fillGrid.Origin.V);
                    Debug.Print("Offset: {0}", fillGrid.Offset);
                    Debug.Print("Angle: {0}", degreeAngle);
                    Debug.Print("Shift: {0}", fillGrid.Shift);

                    var pen = new Pen(System.Drawing.Color.Black)
                    {
                        Width = 1f / matrixScale
                    };

                    float dashLength = 1;
                    var   segments   = fillGrid.GetSegments();

                    if (segments.Count > 0)
                    {
                        pen.DashPattern = segments
                                          .Select(s => Math.Max(float.Epsilon, Convert.ToSingle(s)))
                                          .ToArray();

                        Debug.Print("\tSegments:");
                        foreach (var segment in segments)
                        {
                            Debug.Print("\t\t{0}", segment);
                        }
                        dashLength = pen.DashPattern.Sum();
                    }
                    g.ResetTransform();
                    var rotateMatrix = new Matrix();
                    rotateMatrix.Rotate(degreeAngle);
                    var matrix = new Matrix(
                        1, 0, 0, -1, centerX, centerY); //-1 reflects about x-axis
                    matrix.Scale(matrixScale, matrixScale);
                    matrix.Translate((float)fillGrid.Origin.U,
                                     (float)fillGrid.Origin.V);
                    var backMatrix = matrix.Clone();
                    backMatrix.Multiply(rotateMatrix);
                    matrix.Multiply(rotateMatrix);

                    var offset = (-10) * dashLength;
                    matrix.Translate(offset, 0);
                    backMatrix.Translate(offset, 0);
                    Debug.Print("Offset: {0}", offset);


                    bool   moving_forward = true;
                    bool   moving_back    = true;
                    int    safety         = 500;
                    double alternator     = 0;
                    while (moving_forward || moving_back) // draw segments shifting and offsetting each time
                    {
                        Debug.Write("*");
                        var rectF1 = new RectangleF(
                            -2 / matrixScale, -2 / matrixScale,
                            4 / matrixScale, 4 / matrixScale);

                        if (moving_forward && LineIntersectsRect(
                                matrix, viewRect))
                        {
                            g.Transform = matrix;
                            g.DrawLine(pen, new PointF(0, 0),
                                       new PointF(LENGTH, 0));
                        }
                        else
                        {
                            moving_forward = false;
                            Debug.Print("\n----> Matrix does not intersect view");
                        }

                        if (moving_back && LineIntersectsRect(
                                backMatrix, viewRect))
                        {
                            g.Transform = backMatrix;
                            g.DrawLine(pen, new PointF(0, 0),
                                       new PointF(LENGTH, 0));
                        }
                        else
                        {
                            moving_back = false;
                            Debug.Print("\n----> Back matrix does not intersect view");
                        }

                        if (safety == 0)
                        {
                            Debug.Print("\n--------> Safety limit exceeded");
                            break;
                        }
                        else
                        {
                            --safety;
                        }

                        matrix.Translate((float)fillGrid.Shift,
                                         (float)fillGrid.Offset);
                        backMatrix.Translate(-(float)fillGrid.Shift,
                                             -(float)fillGrid.Offset);

                        alternator += fillGrid.Shift;
                        if (Math.Abs(alternator) > Math.Abs(offset))
                        {
                            Debug.Print("\n----> Alternating");
                            matrix.Translate(offset, 0);
                            backMatrix.Translate(offset, 0);
                            alternator = 0d;
                        }
                    }
                }
                sw.Stop();
                g.ResetTransform();

#if DEBUG
                g.DrawString(string.Format(
                                 "{0} ms", sw.ElapsedMilliseconds),
                             System.Drawing.SystemFonts.DefaultFont,
                             Brushes.Red, 0, 0);
#endif

                Debug.Print(new string( '-', 50 ));

                Pen p = new Pen(System.Drawing.Color.Black);
                p.Width = 1f / matrixScale;
                Debug.Print("Finished");
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
            }
        }