Exemple #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);

        }
Exemple #2
0
        /// <summary>
        /// Return cursor for command
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="zoomLevel"></param>
        /// <returns>null if coordinates are not fine</returns>
        public Cursor GetCursor(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);

            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected

            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];

            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return(this.cursor);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Check if this command can be selected and return true in case it can
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool CanBeSelected(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);

            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected
            //float tmpX = LocationInPixelsX * zoomLevel;
            //float tmpY = LocationInPixelsY * zoomLevel;
            //float w = widthInPixels; //** zoomLevel;
            //float h = heightInPixels; //* zoomLevel;
            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];


            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
 /// <summary>
 /// use matrix to transform point
 /// </summary>
 /// <param name="pts">contain the points to be transform</param>
 private void TransformPoints(Point[] pts)
 {
     System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(
         1, 0, 0, 1, this.pictureBox.Width / 2, this.pictureBox.Height / 2);
     matrix.Invert();
     matrix.TransformPoints(pts);
 }
        /// <summary>
        /// Converts a <see cref="SizeF"/> from destination to source coordinates.
        /// </summary>
        /// <remarks>
        /// Only scale and rotation are applied when converting sizes; this is equivalent
        /// to converting a direction vector, as direction vectors have only magnitude
        /// and direction information, but no position.
        /// </remarks>
        public SizeF ConvertToSource(SizeF destinationDimensions)
        {
            PointF[] transformed = new PointF[] { destinationDimensions.ToPointF() };
            Matrix   inverse     = this.CumulativeTransform.Clone();

            inverse.Invert();
            inverse.TransformVectors(transformed);
            return(new SizeF(transformed[0]));
        }
Exemple #6
0
        private void Dialogs_MouseMove(object sender, MouseEventArgs e)
        {
            if (movestart == null)
            {
                return;
            }

            if (FocusedPhrase == -1 && FocusedTimeline == -1 && !TranslateFocus)
            {
                return;
            }

            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            //m.Translate(Translate.X, Translate.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Scale(ScaleZoom, ScaleZoom, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Invert();

            Point movement = new Point(movestart.X - e.X, movestart.Y - e.Y);

            movement.X = -movement.X;
            movement.Y = -movement.Y;
            Point[] t = new Point[] { movement };
            m.TransformPoints(t);
            movement = t[0];

            if (FocusedPhrase != -1)
            {
                if (TreeOperationMode)
                {
                    dlg.MovePhraseTree(FocusedPhrase, movement);
                }
                else
                {
                    dlg.MovePhrase(FocusedPhrase, movement);
                }

                Changed = true;
            }
            else if (FocusedTimeline >= 0)
            {
                Point x = new Point(0, dlginstance.Timeline(FocusedTimeline).Ylocation);
                x.Offset(movement);
                dlginstance.Timeline(FocusedTimeline).Ylocation = x.Y;

                Changed = true;
            }
            else
            {
                Translate.X -= movestart.X - e.X;
                Translate.Y -= movestart.Y - e.Y;
                //Translate.Offset(movement);
            }

            movestart = e.Location;
            this.Refresh();
        }
        /// <summary>
        /// Converts a <see cref="PointF"/> from destination to source coordinates.
        /// </summary>
        /// <param name="destinationPoint"></param>
        /// <returns></returns>
        public PointF ConvertToSource(PointF destinationPoint)
        {
            Matrix inverse = this.CumulativeTransform.Clone();

            inverse.Invert();

            PointF[] points = new PointF[1];
            points[0] = destinationPoint;
            inverse.TransformPoints(points);

            return(points[0]);
        }
Exemple #8
0
        public void DragPoint(int index, System.Drawing.PointF newPosition)
        {
            if (index < 0 || index >= _obj.Points.Length)
            {
                throw new System.ArgumentOutOfRangeException("index");
            }

            System.Drawing.PointF dragVector = new System.Drawing.PointF(newPosition.X - _transformedPoints[index].X, newPosition.Y - _transformedPoints[index].Y);
            using (System.Drawing.Drawing2D.Matrix inverseMatrix = (System.Drawing.Drawing2D.Matrix)_obj.Transform.Clone())
            {
                inverseMatrix.Invert();
                VObjectsUtils.TransformVector(inverseMatrix, ref dragVector);

                _obj.Points[index].X += dragVector.X;
                _obj.Points[index].Y += dragVector.Y;
            }

            _obj.Update();
        }
Exemple #9
0
        public virtual bool IsPointInside(Point p)
        {
            bool result = false;

            System.Drawing.Drawing2D.Matrix m = this.Transforms[0].Matrix.GetDrawing2DMatrix();
            m.Invert();
            System.Drawing.PointF[] p2 = new System.Drawing.PointF[] { new System.Drawing.PointF(p.X, p.Y) };
            m.TransformPoints(p2);
            Point tp = new Point(p2[0].X, p2[0].Y);

            for (int i = 0; i < this.Definition.Shapes.Count; i++)
            {
                if (this.Definition.Shapes[i].IsPointInside(tp))
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Exemple #10
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);
            }
Exemple #11
0
        private bool IsPointInside(V2DInstance inst, Point p)
        {
            bool result = false;

            System.Drawing.Drawing2D.Matrix m = ((Matrix)inst.UserData).GetDrawing2DMatrix();
            m.Invert();
            System.Drawing.PointF[] p2 = new System.Drawing.PointF[] { new System.Drawing.PointF(p.X, p.Y) };
            m.TransformPoints(p2);
            Point tp = new Point(p2[0].X, p2[0].Y);

            for (int i = 0; i < inst.Definition.V2DShapes.Count; i++)
            {
                if (Shapes[i].IsPointInside(tp))
                {
                    result = true;
                    break;
                }
            }
            return(result);
        }
Exemple #12
0
        public Bitmap ShiftCoordinateSystem()
        {
            System.Drawing.Drawing2D.Matrix inverse = gr.Transform;
            inverse.Invert();
            PointF[] pointFs =
            {
                mouseDown,
                mouseUp
            };

            //Transform Points in Coordinate-System Points
            inverse.TransformPoints(pointFs);

            float xOffSet = pointFs[0].X - pointFs[1].X;
            float yOffSet = pointFs[0].Y - pointFs[1].Y;

            xmin += xOffSet;
            xmax += xOffSet;
            ymin += yOffSet;
            ymax += yOffSet;

            return(MakeGraph(xmin, xmax, ymin, ymax));
        }
Exemple #13
0
        public Bitmap MakeGraph(float _xmin, float _xmax, float _ymin, float _ymax)
        {
            //The bounds to draw.
            xmin = _xmin;
            xmax = _xmax;
            ymin = _ymin;
            ymax = _ymax;

            // Make the Bitmap.
            gr = Graphics.FromImage(bitmapFunction);
            gr.Clear(Color.Transparent);
            gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            //Transform the graphics object to cartesian coordinates
            float fdx = wid * -(xmin / (xmax - xmin));
            float fdy = hgt * -(ymax / (ymin - ymax));

            gr.TranslateTransform(fdx, fdy);

            float sx = Convert.ToSingle(wid) / Math.Abs(xmax - xmin);
            float sy = Convert.ToSingle(hgt) / Math.Abs(ymax - ymin);

            gr.ScaleTransform(sx, -sy);

            // Draw the graph.
            using (Pen graph_pen = new Pen(Color.Blue, 0), grid_pen = new Pen(Color.LightGray, 0))
            {
                for (int x = (int)xmin; x <= xmax; x++)
                {
                    //Draw Grid
                    gr.DrawLine(grid_pen, x, ymin, x, ymax);
                    //Draw AxesSeperation
                    gr.DrawLine(graph_pen, x, -0.1f, x, 0.1f);
                }
                for (int y = (int)ymin; y <= ymax; y++)
                {
                    //Draw Grid
                    gr.DrawLine(grid_pen, xmin, y, xmax, y);
                    //Draw AxesSeperation
                    gr.DrawLine(graph_pen, -0.1f, y, 0.1f, y);
                }

                //Draw the axes.
                gr.DrawLine(graph_pen, xmin, 0, xmax, 0);
                gr.DrawLine(graph_pen, 0, ymin, 0, ymax);

                graph_pen.Color = Color.Red;

                //See how big 1 pixel is horizontally.
                System.Drawing.Drawing2D.Matrix inverse = gr.Transform;
                inverse.Invert();
                PointF[] pixel_pts =
                {
                    new PointF(0, 0),
                    new PointF(1, 0)
                };
                inverse.TransformPoints(pixel_pts);
                float dx = pixel_pts[1].X - pixel_pts[0].X;
                dx /= 4;

                //Draw Function
                //Loop over every function in DataGridView
                for (int i = 0; i < dataGridView.RowCount - 1; i++)
                {
                    if (dataGridView.Rows[i].Selected == true)
                    {
                        float y;
                        //Loop over x values to generate points.
                        for (float x = xmin; x <= xmax; x += dx)
                        {
                            //Get the next point.
                            y = function(x, i);

                            if (!Single.IsNaN(y) && !Single.IsInfinity(y) && !(y > 100000))
                            {
                                //Only add points that are visible
                                if (y < ymax + 0.2 && ymin - 0.2 < y)
                                {
                                    if (function(x - dx, i) > ymax || function(x - dx, i) < ymin)
                                    {
                                        pointsFunction.Add(new PointF(x - dx, function(x - dx, i)));
                                    }

                                    pointsFunction.Add(new PointF(x, y));

                                    if (function(x + dx, i) > ymax || function(x + dx, i) < ymin)
                                    {
                                        pointsFunction.Add(new PointF(x + dx, function(x + dx, i)));
                                    }
                                }
                            }
                        }

                        if (pointsFunction.Count != 0)
                        {
                            try
                            {
                                gr.DrawLines(graph_pen, pointsFunction.ToArray());
                            }
                            catch (Exception e)
                            {
                                MessageBox.Show(e.ToString(), e.Message);
                            }
                        }
                        pointsFunction.Clear();
                    }
                }
            }

            controller.UpdateFunctionTextBox(xmin, xmax, ymin, ymax);

            //return the result.
            return(DrawVisualization());
        }
Exemple #14
0
        private void GraphicsView_MouseMove(object sender, MouseEventArgs e)
        {
            if (movestart == null) return;
            if (!TranslateFocus)
                return;
            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            //m.Translate(Translate.X, Translate.Y, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Scale(ZoomScale, ZoomScale, System.Drawing.Drawing2D.MatrixOrder.Append);
            m.Invert();

            Point movement = new Point(movestart.X - e.X, movestart.Y - e.Y);
            movement.X = -movement.X;
            movement.Y = -movement.Y;
            Point[] t = new Point[] { movement };
            m.TransformPoints(t);
            movement = t[0];

            Translate.X -= movestart.X - e.X;
            Translate.Y -= movestart.Y - e.Y;

            movestart = e.Location;

            HighPrecisionDraw = false;
            this.Refresh();
        }
Exemple #15
0
        public Bitmap GraphFunc()
        {
            int    w  = picGraph.ClientSize.Width;
            int    h  = picGraph.ClientSize.Height;
            Bitmap bm = new Bitmap(w, h);

            using (Graphics gr = Graphics.FromImage(bm))
            {
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                RectangleF rect = new RectangleF(xmin, ymin, xmax - xmin, ymax - ymin);
                PointF[]   pts  = { new PointF(0, h), new PointF(w, h), new PointF(0, 0) };
                gr.Transform = new System.Drawing.Drawing2D.Matrix(rect, pts);

                using (Pen graph_pen = new Pen(Color.Blue, 0))
                {
                    gr.DrawLine(graph_pen, xmin, 0, xmax, 0);
                    gr.DrawLine(graph_pen, 0, ymin, 0, ymax);
                    for (int x = (int)xmin; x <= xmax; x++)
                    {
                        gr.DrawLine(graph_pen, x, -0.1f, x, 0.1f);
                    }
                    for (int y = (int)ymin; y <= ymax; y++)
                    {
                        gr.DrawLine(graph_pen, -0.1f, y, 0.1f, y);
                    }
                    graph_pen.Color = Color.Red;

                    if (func.Count == 0)
                    {
                        return(bm);
                    }

                    System.Drawing.Drawing2D.Matrix inverse = gr.Transform;
                    inverse.Invert();
                    PointF[] pixel_pts = { new PointF(0, 0), new PointF(1, 0) };
                    inverse.TransformPoints(pixel_pts);
                    float dx = pixel_pts[1].X - pixel_pts[0].X;
                    dx /= 2;

                    List <PointF> points = new List <PointF>();
                    for (float x = xmin; x <= xmax; x += dx)
                    {
                        bool valid_point = false;
                        try
                        {
                            float y = 0;
                            y = func[0].eval(x);

                            if (points.Count == 0)
                            {
                                valid_point = true;
                            }
                            else
                            {
                                float dy = y - points[points.Count - 1].Y;
                                if (Math.Abs(dy / dx) < 1000)
                                {
                                    valid_point = true;
                                }
                            }
                            if (valid_point)
                            {
                                points.Add(new PointF(x, y));
                            }
                        }
                        catch
                        {
                        }

                        if (!valid_point)
                        {
                            if (points.Count > 1)
                            {
                                gr.DrawLines(graph_pen, points.ToArray());
                            }
                            points.Clear();
                        }
                    }
                    if (points.Count > 1)
                    {
                        gr.DrawLines(graph_pen, points.ToArray());
                    }

                    Pen           tpen    = new Pen(Color.Green, 0);
                    List <PointF> tpoints = new List <PointF>();
                    for (float x = xmin; x <= xmax; x += dx)
                    {
                        bool valid_point = false;
                        try
                        {
                            float y = 0;
                            y = func[0].teval(x, taylorterms);

                            if (tpoints.Count == 0)
                            {
                                valid_point = true;
                            }
                            else
                            {
                                float dy = y - tpoints[tpoints.Count - 1].Y;
                                if (Math.Abs(dy / dx) < 1000)
                                {
                                    valid_point = true;
                                }
                            }
                            if (valid_point)
                            {
                                tpoints.Add(new PointF(x, y));
                            }
                        }
                        catch
                        {
                        }

                        if (!valid_point)
                        {
                            if (tpoints.Count > 1)
                            {
                                gr.DrawLines(graph_pen, tpoints.ToArray());
                            }
                            tpoints.Clear();
                        }
                    }
                    if (tpoints.Count > 1)
                    {
                        gr.DrawLines(tpen, tpoints.ToArray());
                    }
                }
            }
            return(bm);
        }
        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;
            }
        }
Exemple #17
0
        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;
            }
        }
Exemple #18
0
        /// <summary>
        /// Return cursor for command
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="zoomLevel"></param>
        /// <returns>null if coordinates are not fine</returns>
        public Cursor GetCursor(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);
            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected

            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];

            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return this.cursor;
            }
            else
            {
                return null;
            }
        }
Exemple #19
0
        /// <summary>
        /// Check if this command can be selected and return true in case it can
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public bool CanBeSelected(float x, float y, System.Drawing.Drawing2D.Matrix viewMatrix)
        {
            // transform x,y back to object coordinates to check for selection
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.DrawMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(viewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(x, y);
            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformPoints(points);

            tmpPoint = points[0];
            // check if this item should be selected
            //float tmpX = LocationInPixelsX * zoomLevel;
            //float tmpY = LocationInPixelsY * zoomLevel;
            //float w = widthInPixels; //** zoomLevel;
            //float h = heightInPixels; //* zoomLevel;
            float w = (float)this.WidthInPixels / this.Owner.ViewMatrix.Elements[0];
            float h = (float)this.HeightInPixels / this.Owner.ViewMatrix.Elements[3];

            // if starting coordinate fall inside this component rect
            if (tmpPoint.X >= 0 && tmpPoint.X <= w && tmpPoint.Y >= 0 && tmpPoint.Y <= h)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Exemple #20
0
 /// <summary>
 /// use matrix to transform point
 /// </summary>
 /// <param name="pts">contain the points to be transformed</param>
 private void TransformPoints(Point[] pts)
 {
     System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(
         1, 0, 0, 1, m_sizePictureBox.Width / 2, m_sizePictureBox.Height / 2);
     matrix.Invert();
     matrix.TransformPoints(pts);
 }
Exemple #21
0
        public override void Move(float dx, float dy)
        {
            // convert dx, dy to vector in object space
            System.Drawing.Drawing2D.Matrix mat = this.Owner.DrawMatrix.Clone();
            mat.Multiply(this.TransformationMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Multiply(this.Owner.ViewMatrix, System.Drawing.Drawing2D.MatrixOrder.Append);
            mat.Invert();

            PointF tmpPoint = new PointF(dx, dy);

            PointF[] points = new PointF[1];
            points[0] = tmpPoint;
            mat.TransformVectors(points);

            tmpPoint = points[0];

            dx = tmpPoint.X;
            dy = tmpPoint.Y;
            float udx = UnitsManager.Instance.ConvertUnit(tmpPoint.X, MeasureUnits.pixel, this.Owner.MeasureUnit);
            float udy = UnitsManager.Instance.ConvertUnit(tmpPoint.Y, MeasureUnits.pixel, this.Owner.MeasureUnit);

            //dx = UnitsManager.Instance.ConvertUnit(tmpPoint.X, MeasureUnits.pixel, this.Owner.MeasureUnit);
            //dy = UnitsManager.Instance.ConvertUnit(tmpPoint.Y, MeasureUnits.pixel, this.Owner.MeasureUnit);

            switch (this.CommandPosition)
            {
            case CommandPosition.TopLeft:
                this.Owner.LocationInUnitsX = startLocX + udx;
                this.Owner.LocationInUnitsY = startLocY + udy;
                this.Owner.WidthInPixels    = startWidth - dx;
                this.Owner.HeightInPixels   = startHeight - dy;
                this.Owner.AnchorAll(udx, udy, -dx, -dy);
                break;

            case CommandPosition.TopCenter:
                this.Owner.LocationInUnitsY = startLocY + udy;
                this.Owner.HeightInPixels   = startHeight - dy;
                this.Owner.AnchorAll(0.0f, udy, 0.0f, -dy);
                break;

            case CommandPosition.TopRight:
                this.Owner.LocationInUnitsY = startLocY + udy;
                this.Owner.WidthInPixels    = startWidth + dx;
                this.Owner.HeightInPixels   = startHeight - dy;
                this.Owner.AnchorAll(0.0f, udy, dx, -dy);
                break;

            case CommandPosition.MiddleLeft:
                this.Owner.LocationInUnitsX = startLocX + udx;
                this.Owner.WidthInPixels    = startWidth - dx;
                this.Owner.AnchorAll(udx, 0.0f, -dx, 0.0f);
                break;

            case CommandPosition.MiddleRight:
                this.Owner.WidthInPixels = startWidth + dx;
                this.Owner.AnchorAll(0.0f, 0.0f, dx, 0.0f);
                break;

            case CommandPosition.BottomLeft:
                this.Owner.LocationInUnitsX = startLocX + udx;
                this.Owner.WidthInPixels    = startWidth - dx;
                this.Owner.HeightInPixels   = startHeight + dy;
                this.Owner.AnchorAll(udx, 0.0f, -dx, dy);
                break;

            case CommandPosition.BottomCenter:
                this.Owner.HeightInPixels = startHeight + dy;
                this.Owner.AnchorAll(0.0f, 0.0f, 0.0f, dy);
                break;

            case CommandPosition.BottomRight:
                this.Owner.WidthInPixels  = startWidth + dx;
                this.Owner.HeightInPixels = startHeight + dy;
                this.Owner.AnchorAll(0.0f, 0.0f, dx, dy);
                break;
            }

            if (this.Owner.WidthInPixels < UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel))
            {
                this.Owner.WidthInPixels = UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel);
            }
            if (this.Owner.HeightInPixels < UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel))
            {
                this.Owner.HeightInPixels = UnitsManager.Instance.ConvertUnit(1.0f, MeasureUnits.mm, MeasureUnits.pixel);
            }

            this.Owner.DockAll();
            if (this.Owner.Parent != null)
            {
                this.Owner.Parent.DockAll();
            }
        }
Exemple #22
0
        //source: http://csharphelper.com/blog/2016/11/graph-an-equation-in-c/
        private void drawPolynominal()
        {
            label9.Visible = true;

            // The bounds to draw.
            float xmin = -20;
            float xmax = 20;
            float ymin = -20;
            float ymax = 20;

            // Make the Bitmap.
            int    wid = pictureBox2.ClientSize.Width;
            int    hgt = pictureBox2.ClientSize.Height;
            Bitmap bm  = new Bitmap(wid, hgt);

            using (Graphics gr = Graphics.FromImage(bm))
            {
                gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                // Transform to map the graph bounds to the Bitmap.
                RectangleF rect = new RectangleF(
                    xmin, ymin, xmax - xmin, ymax - ymin);
                PointF[] pts =
                {
                    new PointF(0,   hgt),
                    new PointF(wid, hgt),
                    new PointF(0,     0),
                };
                gr.Transform = new System.Drawing.Drawing2D.Matrix(rect, pts);

                // Draw the graph.
                using (Pen graph_pen = new Pen(Color.Blue, 0))
                {
                    // Draw the axes.
                    gr.DrawLine(graph_pen, xmin, 0, xmax, 0);
                    gr.DrawLine(graph_pen, 0, ymin, 0, ymax);
                    for (int x = (int)xmin; x <= xmax; x++)
                    {
                        gr.DrawLine(graph_pen, x, -0.1f, x, 0.1f);
                    }
                    for (int y = (int)ymin; y <= ymax; y++)
                    {
                        gr.DrawLine(graph_pen, -0.1f, y, 0.1f, y);
                    }
                    graph_pen.Color = Color.Red;

                    // See how big 1 pixel is horizontally.
                    System.Drawing.Drawing2D.Matrix inverse = gr.Transform;
                    inverse.Invert();
                    PointF[] pixel_pts =
                    {
                        new PointF(0, 0),
                        new PointF(1, 0)
                    };
                    inverse.TransformPoints(pixel_pts);
                    float dx = pixel_pts[1].X - pixel_pts[0].X;
                    dx /= 2;

                    // Loop over x values to generate points.
                    List <PointF> points = new List <PointF>();
                    for (float x = xmin; x <= xmax; x += dx)
                    {
                        bool valid_point = false;
                        try
                        {
                            // Get the next point.
                            float y = F(x);

                            // If the slope is reasonable,
                            // this is a valid point.
                            if (points.Count == 0)
                            {
                                valid_point = true;
                            }
                            else
                            {
                                float dy = y - points[points.Count - 1].Y;
                                if (Math.Abs(dy / dx) < 1000)
                                {
                                    valid_point = true;
                                }
                            }
                            if (valid_point)
                            {
                                points.Add(new PointF(x, y));
                            }
                        }
                        catch
                        {
                        }

                        // If the new point is invalid, draw
                        // the points in the latest batch.
                        if (!valid_point)
                        {
                            if (points.Count > 1)
                            {
                                gr.DrawLines(graph_pen, points.ToArray());
                            }
                            points.Clear();
                        }
                    }

                    // Draw the last batch of points.
                    if (points.Count > 1)
                    {
                        gr.DrawLines(graph_pen, points.ToArray());
                    }
                }
            }

            // Display the result.
            pictureBox2.Image = bm;
        }