コード例 #1
0
 private void AddToTheRightGroup(ref MsaglRectangle b1, ref int count1, int lp, ref int rp, ObjectWithBox g)
 {
     Swap(lp, rp);
     rp--;
     b1.Add(g.Box);
     count1++;
 }
コード例 #2
0
 private void AddToTheRightGroup(ref MsaglRectangle b1, ref int count1, int lp, ref int rp, ObjectWithBox g)
 {
     Swap(lp, rp);
     rp--;
     b1.Add(g.Box);
     count1++;
 }
コード例 #3
0
 static double CommonArea(ref MsaglRectangle a, ref MsaglRectangle b)
 {
     double l = Math.Min(a.Left, b.Left);
     double r = Math.Max(a.Right, b.Right);
     double t = Math.Max(a.Top, b.Top);
     double bt = Math.Min(a.Bottom, b.Bottom);
     return (r - l) * (t - bt);
 }
コード例 #4
0
        static void FillContexForCurve(PathGeometry path, Curve c)
        {
            PathFigure curveFigure = new PathFigure();

            foreach (ICurve seg in c.Segments)
            {
                var bezSeg = seg as CubicBezierSegment;

                if (bezSeg != null)
                {
                    curveFigure.Segments.Add(new BezierSegment()
                    {
                        Point1 = Common.UwpPoint(bezSeg.B(1)),
                        Point2 = Common.UwpPoint(bezSeg.B(2)),
                        Point3 = Common.UwpPoint(bezSeg.B(3))
                    });
                }
                else
                {
                    var ls = seg as LineSegment;

                    if (ls != null)
                    {
                        curveFigure.Segments.Add(new Windows.UI.Xaml.Media.LineSegment()
                        {
                            Point = Common.UwpPoint(ls.End)
                        });
                    }
                    else
                    {
                        var ellipse = seg as Ellipse;

                        if (ellipse != null)
                        {
                            // context.LineTo(Common.WpfPoint(ellipse.End),true,false);
                            double    sweepAngle = EllipseSweepAngle(ellipse);
                            bool      largeArc   = Math.Abs(sweepAngle) >= Math.PI;
                            Rectangle box        = ellipse.FullBox();

                            curveFigure.Segments.Add(new ArcSegment()
                            {
                                Point          = Common.UwpPoint(ellipse.End),
                                Size           = new Size(box.Width / 2, box.Height / 2),
                                RotationAngle  = sweepAngle,
                                IsLargeArc     = largeArc,
                                SweepDirection = sweepAngle < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise
                            });
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }
            }

            path.Figures.Add(curveFigure);
        }
コード例 #5
0
        static double CommonArea(ref MsaglRectangle a, ref MsaglRectangle b)
        {
            double l  = Math.Min(a.Left, b.Left);
            double r  = Math.Max(a.Right, b.Right);
            double t  = Math.Max(a.Top, b.Top);
            double bt = Math.Min(a.Bottom, b.Bottom);

            return((r - l) * (t - bt));
        }
コード例 #6
0
        Rectangle CreateRectForRubberEdge()
        {
            var    rect = new BBox(rubberLineStart, RubberLineEnd);
            double w    = gViewer.LineThicknessForEditing;
            var    del  = new P2(-w, w);

            rect.Add(rect.LeftTop + del);
            rect.Add(rect.RightBottom - del);
            return(GViewer.CreateScreenRectFromTwoCornersInTheSource(rect.LeftTop, rect.RightBottom));
        }
コード例 #7
0
        internal Geometry(DObject dObject) {
            this.dObject = dObject;

            DNode dNode = dObject as DNode;
            if (dNode != null)
                bBox = dNode.DrawingNode.BoundingBox;
            else {
                DLabel dLabel = dObject as DLabel;
                if (dLabel != null)
                    bBox = dLabel.DrawingLabel.BoundingBox;
            }
        }
コード例 #8
0
        private void FindSeeds(int first, int count, out int seed0, out MsaglRectangle b0, out int seed1)
        {
            seed0 = first;
            b0    = geometries[seed0].Box;

            double area = -1.0f;

            //looking for seed0
            for (int i = first + 1; i < first + count; i++)
            {
                ObjectWithBox  g  = geometries[i];
                MsaglRectangle b  = g.Box;
                double         ar = CommonArea(ref b0, ref b);
                if (ar > area)
                {
                    seed0 = i;
                    area  = ar;
                }
            }

            //looking for seed1
            seed1 = first;//I'm getting a compiler error: there is no need actually to init seed1
            area  = -1.0f;

            b0 = geometries[seed0].Box;

            for (int i = first; i < first + count; i++)
            {
                if (i == seed0)
                {
                    continue;
                }

                ObjectWithBox g = geometries[i];

                MsaglRectangle b = g.Box;

                double ar = CommonArea(ref b0, ref b);
                if (ar > area)
                {
                    seed1 = i;
                    area  = ar;
                }
            }

            if (seed0 > seed1)
            {
                int t = seed1;
                seed1 = seed0;
                seed0 = t;
            }
        }
コード例 #9
0
        internal void DrawRubberEdge(EdgeGeometry edgeGeometry)
        {
            BBox rectToInvalidate = edgeGeometry.BoundingBox;

            if (CurrentRubberEdge != null)
            {
                BBox b = CurrentRubberEdge.BoundingBox;
                rectToInvalidate.Add(b);
            }
            CurrentRubberEdge = edgeGeometry;
            GViewer.Invalidate(GViewer.CreateScreenRectFromTwoCornersInTheSource(rectToInvalidate.LeftTop,
                                                                                 rectToInvalidate.RightBottom));
        }
コード例 #10
0
        private void SplitOnGroups(int first, int count, int seed0, ref MsaglRectangle b0, int seed1, out MsaglRectangle b1, out int count0, out int count1)
        {
            b0 = geometries[seed0].Box;
            b1 = geometries[seed1].Box;

            //reshuffling in place:
            //put the next element of the first group on the first not occupied place on from the left
            //put the next element of the second group to the last not occupied place to the right
            Swap(first, seed0);             //this puts the seed0 the most left position
            Swap(first + count - 1, seed1); //this puts seed1 to the right most position

            double ratio = 2;
            //lp points to the first not assigned element to the right of group 0
            int lp = first + 1;
            //rp
            int rp = first + count - 2; //seed1 stands at first +count-1

            count0 = 1;
            count1 = 1;

            while (count0 + count1 < count)
            {
                //First check the ratio of numbers of elements of the groups.
                //We need to keep the tree balanced. Let's watch that the ratio of the numbers of elements of the
                // two groups is between ratio and 1/ratio.
                ObjectWithBox g = geometries[lp];
                if (count0 * ratio < count1)
                {
                    AddToTheLeftGroup(ref b0, ref count0, ref lp, g);
                }
                else if (count1 * ratio < count0)
                {
                    AddToTheRightGroup(ref b1, ref count1, lp, ref rp, g);
                }
                else
                { //make decision based on the growing of the group boxes
                    MsaglRectangle b             = g.Box;
                    double         squareGrouth0 = CommonArea(ref b0, ref b) - b0.Area;
                    double         squareGrouth1 = CommonArea(ref b1, ref b) - b1.Area;
                    if (squareGrouth0 < squareGrouth1)
                    {
                        AddToTheLeftGroup(ref b0, ref count0, ref lp, g);
                    }
                    else
                    {
                        AddToTheRightGroup(ref b1, ref count1, lp, ref rp, g);
                    }
                }
            }
        }
コード例 #11
0
        private void FindSeeds(int first, int count, out int seed0, out MsaglRectangle b0, out int seed1)
        {
            seed0 = first;
            b0 = geometries[seed0].Box;

            double area = -1.0f;
            //looking for seed0
            for (int i = first + 1; i < first + count; i++)
            {
                ObjectWithBox g = geometries[i];
                MsaglRectangle b = g.Box;
                double ar = CommonArea(ref b0, ref b);
                if (ar > area)
                {
                    seed0 = i;
                    area = ar;
                }
            }

            //looking for seed1
            seed1 = first;//I'm getting a compiler error: there is no need actually to init seed1
            area = -1.0f;

            b0 = geometries[seed0].Box;

            for (int i = first; i < first + count; i++)
            {

                if (i == seed0)
                    continue;

                ObjectWithBox g = geometries[i];

                MsaglRectangle b = g.Box;

                double ar = CommonArea(ref b0, ref b);
                if (ar > area)
                {
                    seed1 = i;
                    area = ar;
                }
            }

            if (seed0 > seed1)
            {
                int t = seed1;
                seed1 = seed0;
                seed0 = t;
            }
        }
        public int MeasureLevelOfDetail(Size container)
        {
            int LOD;

            for (LOD = 0; LOD < _boundingBoxes.Count; LOD++)
            {
                Rectangle box = _boundingBoxes[LOD];
                if (container.Width < box.Width || container.Height < box.Height || container.Width < box.Right || container.Height < box.Bottom)
                {
                    break;
                }
            }
            return(LOD);
        }
        public void AddDetail(Visual v, Rectangle bounding_box)
        {
            if (v != null)
            {
                _visuals.Add(v);

                Rectangle last_box;
                if (_boundingBoxes.Count > 0)
                {
                    last_box = _boundingBoxes[_boundingBoxes.Count - 1];
                    bounding_box.Add(last_box);
                }

                _boundingBoxes.Add(bounding_box);
            }
        }
コード例 #14
0
        public void AddDetail(Visual v, Rectangle bounding_box)
        {
            if (v != null)
            {
                _visuals.Add(v);

                Rectangle last_box;
                if (_boundingBoxes.Count > 0)
                {
                    last_box = _boundingBoxes[_boundingBoxes.Count - 1];
                    bounding_box.Add(last_box);
                }

                _boundingBoxes.Add(bounding_box);
            }
        }
コード例 #15
0
        private static PathGeometry ConvertMsaglRectangleToDoubleCirclePathGeometry(GeometryRectangle box)
        {
            double w = box.Width;
            double h = box.Height;

            var pathGeometry = new PathGeometry();

            var r = new Rect(box.Left, box.Bottom, w, h);

            pathGeometry.AddGeometry(new EllipseGeometry(r));

            var inflation = Math.Min(5.0, Math.Min(w / 3, h / 3));

            r.Inflate(-inflation, -inflation);
            pathGeometry.AddGeometry(new EllipseGeometry(r));

            return(pathGeometry);
        }
コード例 #16
0
ファイル: Modeller.cs プロジェクト: j-prox/blueprint41
        void AutoResizeWithoutUndoRedo()
        {
            if (GraphEditor.Viewer.Graph == null)
            {
                return;
            }

            GeometryGraph geometryGraph = GraphEditor.Viewer.Graph.GeometryGraph;

            if (GraphEditor.Viewer.Graph.GeometryGraph != null)
            {
                var r = new Microsoft.Msagl.Core.Geometry.Rectangle();

                foreach (var n in geometryGraph.Nodes)
                {
                    r = n.BoundingBox;
                    break;
                }
                foreach (var n in geometryGraph.Nodes)
                {
                    r.Add(n.BoundingBox);
                }
                foreach (var e in geometryGraph.Edges)
                {
                    r.Add(e.BoundingBox);
                    if (e.Label != null)
                    {
                        r.Add(e.Label.BoundingBox);
                    }
                }

                r.Left   -= geometryGraph.Margins;
                r.Top    += geometryGraph.Margins;
                r.Bottom -= geometryGraph.Margins;
                r.Right  += geometryGraph.Margins;

                r.Add(geometryGraph.BoundingBox);

                if (geometryGraph.BoundingBox.Contains(r) == false)
                {
                    geometryGraph.BoundingBox = r;
                }
            }
        }
コード例 #17
0
ファイル: XEdge.cs プロジェクト: Caliper/MSAGL
 static void FillContexForCurve(StreamGeometryContext context, Curve c)
 {
     foreach (ICurve seg in c.Segments)
     {
         var bezSeg = seg as CubicBezierSegment;
         if (bezSeg != null)
         {
             context.BezierTo(CommonX.WpfPoint(bezSeg.B(1)),
                              CommonX.WpfPoint(bezSeg.B(2)), CommonX.WpfPoint(bezSeg.B(3)), true, false);
         }
         else
         {
             var ls = seg as LineSegment;
             if (ls != null)
             {
                 context.LineTo(CommonX.WpfPoint(ls.End), true, false);
             }
             else
             {
                 var ellipse = seg as Ellipse;
                 if (ellipse != null)
                 {
                     //       context.LineTo(Common.WpfPoint(ellipse.End),true,false);
                     double    sweepAngle = EllipseSweepAngle(ellipse);
                     bool      largeArc   = Math.Abs(sweepAngle) >= Math.PI;
                     Rectangle box        = ellipse.FullBox();
                     context.ArcTo(CommonX.WpfPoint(ellipse.End),
                                   new Size(box.Width / 2, box.Height / 2),
                                   sweepAngle,
                                   largeArc,
                                   sweepAngle < 0
                                       ? SweepDirection.Counterclockwise
                                       : SweepDirection.Clockwise,
                                   true, true);
                 }
                 else
                 {
                     throw new NotImplementedException();
                 }
             }
         }
     }
 }
コード例 #18
0
        internal Geometry(DObject dObject)
        {
            this.dObject = dObject;

            DNode dNode = dObject as DNode;

            if (dNode != null)
            {
                bBox = dNode.DrawingNode.BoundingBox;
            }
            else
            {
                DLabel dLabel = dObject as DLabel;
                if (dLabel != null)
                {
                    bBox = dLabel.Label.BoundingBox;
                }
            }
        }
コード例 #19
0
        void ShowObjectsInTheLastRectClick(object sender, EventArgs e)
        {
            string message;

            if (gViewer.Graph == null)
            {
                message = "there is no graph";
            }
            else
            {
                if (MouseDownPointAndMouseUpPointsAreFarEnough())
                {
                    var p0         = gViewer.ScreenToSource(myMouseDownPoint);
                    var p1         = gViewer.ScreenToSource(myMouseUpPoint);
                    var rubberRect = new Microsoft.Msagl.Core.Geometry.Rectangle(p0, p1);
                    var stringB    = new StringBuilder();
                    foreach (var node in gViewer.Graph.Nodes)
                    {
                        if (rubberRect.Contains(node.BoundingBox))
                        {
                            stringB.Append(node.LabelText + "\n");
                        }
                    }

                    foreach (var edge in gViewer.Graph.Edges)
                    {
                        if (rubberRect.Contains(edge.BoundingBox))
                        {
                            stringB.Append(String.Format("edge from {0} to {1}\n", edge.SourceNode.LabelText,
                                                         edge.TargetNode.LabelText));
                        }
                    }

                    message = stringB.ToString();
                }
                else
                {
                    message = "the window is not defined";
                }
            }

            MessageBox.Show(message);
        }
コード例 #20
0
        void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            foreach (NodeTypeEntry nte in m_NodeTypes)
            {
                if (nte.Button == e.Button)
                {
                    var center = new Point();
                    var random = new Random(1);

                    var   rect1 = gViewer.ClientRectangle; //gViewer.Graph.GeometryGraph.BoundingBox;
                    var   rect2 = gViewer.Graph.BoundingBox;
                    Point p     = gViewer.ScreenToSource(rect1.Location);
                    Point p2    = gViewer.ScreenToSource(rect1.Location + rect1.Size);
                    if (p.X < rect2.Left)
                    {
                        p.X = rect2.Left;
                    }
                    if (p2.X > rect2.Right)
                    {
                        p2.X = rect2.Right;
                    }
                    if (p.Y > rect2.Top)
                    {
                        p.Y = rect2.Top;
                    }
                    if (p2.Y < rect2.Bottom)
                    {
                        p2.Y = rect2.Bottom;
                    }
                    var rect = new Microsoft.Msagl.Core.Geometry.Rectangle(p, p2);

                    center.X = rect.Left + random.NextDouble() * rect.Width;
                    center.Y = rect.Bottom + random.NextDouble() * rect.Height;

                    DrawingNode n = InsertNode(center, nte);
                    if (NodeInsertedByUser != null)
                    {
                        NodeInsertedByUser(n);
                    }
                }
            }
        }
コード例 #21
0
        public void Invalidate(double scale = 1)
        {
            if (BoundaryCurveIsDirty)
            {
                BoundaryPath.Data    = CreatePathFromNodeBoundary();
                BoundaryCurveIsDirty = false;
            }


            double    node_scale = Scale();
            Rectangle bounds     = LgNodeInfo.OriginalCurveOfGeomNode.BoundingBox;
            Size      real_size  = new Size(bounds.Width * node_scale * scale,
                                            bounds.Height * node_scale * scale);

            if (node_scale < 0.5 && (real_size.Width < _fontSize || real_size.Height < _fontSize))
            {
                _visualObject.LevelOfDetail = 0;
            }
            else
            {
                if (_visualObject.MaxLevelOfDetail == 0)
                {
                    // First time becoming visible: generate visuals
                    InitiateContainer();
                    Visual    visual;
                    Rectangle rect;

                    rect = CreateIcon(new Point(), out visual);
                    _visualObject.AddDetail(visual, rect);

                    rect = CreateTitle(rect.RightBottom, out visual);
                    _visualObject.AddDetail(visual, rect);

                    rect = CreateDescription(new Point(rect.Center.X, rect.Top), out visual);
                    _visualObject.AddDetail(visual, rect);
                }
                _visualObject.LevelOfDetail = _visualObject.MeasureLevelOfDetail(real_size);

                CommonX.PositionElement(_visualObject, _visualObject.BoundingBox, Node.BoundingBox, 1 / scale);
            }
        }
コード例 #22
0
        public static Cairo.Matrix CalculateTransformMatrix(Microsoft.Msagl.Core.Geometry.Rectangle geometryRectangle, Cairo.Rectangle clientRectangle)
        {
            if (clientRectangle.Height > 1 && clientRectangle.Width > 1)
            {
                var scale = Math.Min(clientRectangle.Width * 0.9 / geometryRectangle.Width, clientRectangle.Height * 0.9 / geometryRectangle.Height);
                var g0    = (geometryRectangle.Left + geometryRectangle.Right) / 2;
                var g1    = (geometryRectangle.Top + geometryRectangle.Bottom) / 2;

                var c0 = (clientRectangle.X + (clientRectangle.X + clientRectangle.Width)) / 2;
                var c1 = (clientRectangle.Y + (clientRectangle.Y + clientRectangle.Height)) / 2;
                var dx = c0 - scale * g0;
                var dy = c1 - scale * g1;

                /*
                 * //instead of setting transormation for graphics it is possible to transform the geometry graph, just to test that GeometryGraph.Transform() works
                 *
                 * var planeTransformation=new PlaneTransformation(scale,0,dx, 0, scale, dy);
                 * geometryGraph.Transform(planeTransformation);
                 * //*/
                return(new Cairo.Matrix((float)scale, 0, 0, (float)scale, (float)dx, (float)dy));
            }
            return(new Cairo.Matrix(1, 0, 0, 1, 0, 0));
        }
コード例 #23
0
 internal Geometry(DObject dObject, BBox box) {
     this.dObject = dObject;
     this.bBox = box;
 }
コード例 #24
0
 public static VisioAutomation.Drawing.Rectangle ToVARectangle(MG.Core.Geometry.Rectangle n)
 {
     return(new VisioAutomation.Drawing.Rectangle(n.Left, n.Bottom, n.Right, n.Top));
 }
コード例 #25
0
ファイル: VNodeX.cs プロジェクト: mrkcass/SuffixTreeExplorer
 void PositionPath(Rectangle box)
 {
     Canvas.SetLeft(BoundaryPath, box.Left + box.Width/2);
     Canvas.SetTop(BoundaryPath, box.Bottom + box.Height/2);
 }
コード例 #26
0
ファイル: VEdge.cs プロジェクト: KOpenMOS/Mos
        internal static void FillContextForICurve(WStreamGeometryContext context, ICurve iCurve)
        {
            context.BeginFigure(Common.WpfPoint(iCurve.Start), false, false);

            var c = iCurve as Curve;

            if (c != null)
            {
                FillContexForCurve(context, c);
            }
            else
            {
                var cubicBezierSeg = iCurve as CubicBezierSegment;
                if (cubicBezierSeg != null)
                {
                    context.BezierTo(Common.WpfPoint(cubicBezierSeg.B(1)), Common.WpfPoint(cubicBezierSeg.B(2)),
                                     Common.WpfPoint(cubicBezierSeg.B(3)), true, false);
                }
                else
                {
                    var ls = iCurve as MLineSegment;
                    if (ls != null)
                    {
                        context.LineTo(Common.WpfPoint(ls.End), true, false);
                    }
                    else
                    {
                        var rr = iCurve as RoundedRect;
                        if (rr != null)
                        {
                            FillContexForCurve(context, rr.Curve);
                        }
                        else
                        {
                            var poly = iCurve as MPolyline;
                            if (poly != null)
                            {
                                FillContexForPolyline(context, poly);
                            }
                            else
                            {
                                var ellipse = iCurve as MEllipse;
                                if (ellipse != null)
                                {
                                    double     sweepAngle = EllipseSweepAngle(ellipse);
                                    bool       largeArc   = Math.Abs(sweepAngle) >= Math.PI;
                                    MRectangle box        = ellipse.FullBox();
                                    context.ArcTo(Common.WpfPoint(ellipse.End),
                                                  new WSize(box.Width / 2, box.Height / 2),
                                                  sweepAngle,
                                                  largeArc,
                                                  sweepAngle < 0
                                                      ? WSweepDirection.Counterclockwise
                                                      : WSweepDirection.Clockwise,
                                                  true, true);
                                }
                                else
                                {
                                    throw new NotImplementedException();
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #27
0
 internal Geometry(DObject dObject, MsaglRectangle box)
 {
     this.dObject = dObject;
     this.bBox    = box;
 }
コード例 #28
0
        private void SplitOnGroups(int first, int count, int seed0, ref BBox b0, int seed1, out BBox b1, out int count0, out int count1) {
            b0 = geometries[seed0].Box;
            b1 = geometries[seed1].Box;

            //reshuffling in place: 
            //put the next element of the first group on the first not occupied place on from the left
            //put the next element of the second group to the last not occupied place to the right
            Swap(first, seed0);//this puts the seed0 the most left position
            Swap(first + count - 1, seed1);//this puts seed1 to the right most position

            double ratio = 2;
            //lp points to the first not assigned element to the right of group 0
            int lp = first + 1;
            //rp 
            int rp = first + count - 2; //seed1 stands at first +count-1
            count0 = 1;
            count1 = 1;

            while (count0 + count1 < count) {
                //First check the ratio of numbers of elements of the groups.
                //We need to keep the tree balanced. Let's watch that the ratio of the numbers of elements of the 
                // two groups is between ratio and 1/ratio.
                ObjectWithBox g = geometries[lp];
                if (count0 * ratio < count1)
                    AddToTheLeftGroup(ref b0, ref count0, ref lp, g);
                else if (count1 * ratio < count0)
                    AddToTheRightGroup(ref b1, ref count1, lp, ref rp, g);
                else { //make decision based on the growing of the group boxes
                    BBox b=g.Box;
                    double squareGrouth0 = CommonArea(ref b0, ref b) - b0.Area;
                    double squareGrouth1 = CommonArea(ref b1, ref b) - b1.Area;
                    if (squareGrouth0 < squareGrouth1)
                        AddToTheLeftGroup(ref b0, ref count0, ref lp, g);     
                    else
                        AddToTheRightGroup(ref b1, ref count1, lp, ref rp, g);
                }
            }
    
        }
コード例 #29
0
 private static EllipseGeometry ConvertMsaglRectangleToEllipseGeometry(GeometryRectangle box)
 {
     return(new EllipseGeometry(box.Center.ToWpf(), box.Width / 2, box.Height / 2));
 }
コード例 #30
0
        static private void CreateEdgePathFromCurve(StreamGeometryContext context, ICurve iCurve)
        {
            context.BeginFigure(iCurve.Start.ToWpf(), false, false);

            var c = iCurve as Curve;

            if (c != null)
            {
                FillContexForCurve(context, c);
                return;
            }

            var cubicBezierSeg = iCurve as CubicBezierSegment;

            if (cubicBezierSeg != null)
            {
                context.BezierTo(cubicBezierSeg.B(1).ToWpf(), cubicBezierSeg.B(2).ToWpf(), cubicBezierSeg.B(3).ToWpf(), true, false);
                return;
            }

            var ls = iCurve as GeometryLineSegment;

            if (ls != null)
            {
                context.LineTo(ls.End.ToWpf(), true, false);
                return;
            }

            var rr = iCurve as RoundedRect;

            if (rr != null)
            {
                FillContexForCurve(context, rr.Curve);
                return;
            }

            var poly = iCurve as GeometryPolyline;

            if (poly != null)
            {
                FillContexForPolyline(context, poly);
                return;
            }

            var ellipse = iCurve as GeometryEllipse;

            if (ellipse != null)
            {
                //       context.LineTo(Common.WpfPoint(ellipse.End),true,false);
                double            sweepAngle = EllipseSweepAngle(ellipse);
                bool              largeArc   = Math.Abs(sweepAngle) >= Math.PI;
                GeometryRectangle box        = ellipse.FullBox();
                context.ArcTo(ellipse.End.ToWpf(),
                              new Size(box.Width / 2, box.Height / 2),
                              sweepAngle,
                              largeArc,
                              sweepAngle < 0
                                    ? SweepDirection.Counterclockwise
                                    : SweepDirection.Clockwise,
                              true, true);

                return;
            }
            else
            {
                throw new NotImplementedException($"{iCurve.GetType()}");
            }
        }
コード例 #31
0
 internal Geometry(DObject dObject, MsaglRectangle box)
 {
     this.dObject = dObject;
     this.bBox = box;
 }
コード例 #32
0
 /// <summary>
 /// return true if the two rects are nearly identical (ignoring precision errors smaller than DistanceEpsilon)
 /// </summary>
 /// <param name="rect1">first Rectangle</param>
 /// <param name="rect2">second Rectangle</param>
 /// <returns></returns>
 public static bool Close(Rectangle rect1, Rectangle rect2)
 {
     return(Close(rect1, rect2, DistanceEpsilon));
 }
コード例 #33
0
 Rectangle CreateRectForRubberEdge() {
     var rect = new BBox(rubberLineStart, RubberLineEnd);
     double w = gViewer.LineThicknessForEditing;
     var del = new P2(-w, w);
     rect.Add(rect.LeftTop + del);
     rect.Add(rect.RightBottom - del);
     return GViewer.CreateScreenRectFromTwoCornersInTheSource(rect.LeftTop, rect.RightBottom);
 }
コード例 #34
0
 private static void AddToTheLeftGroup(ref MsaglRectangle b0, ref int count0, ref int lp, ObjectWithBox g)
 {
     lp++;
     count0++;
     b0.Add(g.Box);
 }
コード例 #35
0
 void PositionPath(Rectangle box)
 {
     Canvas.SetLeft(BoundaryPath, box.Left + box.Width / 2);
     Canvas.SetTop(BoundaryPath, box.Bottom + box.Height / 2);
 }
コード例 #36
0
        static internal void FillContextForICurve(PathGeometry path, ICurve iCurve)
        {
            var curveFigure = new PathFigure()
            {
                StartPoint = Common.UwpPoint(iCurve.Start)
            };

            var c = iCurve as Curve;

            if (c != null)
            {
                FillContexForCurve(path, c);
            }
            else
            {
                var cubicBezierSeg = iCurve as CubicBezierSegment;

                if (cubicBezierSeg != null)
                {
                    curveFigure.Segments.Add(new BezierSegment()
                    {
                        Point1 = Common.UwpPoint(cubicBezierSeg.B(1)),
                        Point2 = Common.UwpPoint(cubicBezierSeg.B(2)),
                        Point3 = Common.UwpPoint(cubicBezierSeg.B(3))
                    });
                }
                else
                {
                    var ls = iCurve as LineSegment;

                    if (ls != null)
                    {
                        curveFigure.Segments.Add(new Windows.UI.Xaml.Media.LineSegment()
                        {
                            Point = Common.UwpPoint(ls.End)
                        });
                    }
                    else
                    {
                        var rr = iCurve as RoundedRect;

                        if (rr != null)
                        {
                            FillContexForCurve(path, rr.Curve);
                        }
                        else
                        {
                            var poly = iCurve as Polyline;

                            if (poly != null)
                            {
                                FillContexForPolyline(path, poly);
                            }
                            else
                            {
                                var ellipse = iCurve as Ellipse;

                                if (ellipse != null)
                                {
                                    // context.LineTo(Common.WpfPoint(ellipse.End),true,false);
                                    double    sweepAngle = EllipseSweepAngle(ellipse);
                                    bool      largeArc   = Math.Abs(sweepAngle) >= Math.PI;
                                    Rectangle box        = ellipse.FullBox();

                                    curveFigure.Segments.Add(new ArcSegment()
                                    {
                                        Point          = Common.UwpPoint(ellipse.End),
                                        Size           = new Size(box.Width / 2, box.Height / 2),
                                        RotationAngle  = sweepAngle,
                                        IsLargeArc     = largeArc,
                                        SweepDirection = sweepAngle < 0 ? SweepDirection.Counterclockwise : SweepDirection.Clockwise,
                                    });
                                }
                                else
                                {
                                    throw new NotImplementedException();
                                }
                            }
                        }
                    }
                }
            }

            path.Figures.Add(curveFigure);
        }
コード例 #37
0
 private static void AddToTheLeftGroup(ref BBox b0, ref int count0, ref int lp, ObjectWithBox g) {
     lp++;
     count0++;
     b0.Add(g.Box);
 }
コード例 #38
0
 internal Geometry(DObject dObject, BBox box)
 {
     this.dObject = dObject;
     this.bBox    = box;
 }
コード例 #39
0
ファイル: Form1.cs プロジェクト: mrkcass/SuffixTreeExplorer
        void ShowObjectsInTheLastRectClick(object sender, EventArgs e)
        {
            string message;
            if(gViewer.Graph==null) {
                message = "there is no graph";
            }else {
                if (MouseDownPointAndMouseUpPointsAreFarEnough()) {
                    var p0 = gViewer.ScreenToSource(myMouseDownPoint);
                    var p1 = gViewer.ScreenToSource(myMouseUpPoint);
                    var rubberRect = new Microsoft.Msagl.Core.Geometry.Rectangle(p0, p1);
                    var stringB = new StringBuilder();
                    foreach (var node in gViewer.Graph.Nodes)
                        if (rubberRect.Contains(node.BoundingBox))
                            stringB.Append(node.LabelText + "\n");

                    foreach (var edge in gViewer.Graph.Edges)
                        if (rubberRect.Contains(edge.BoundingBox))
                            stringB.Append(String.Format("edge from {0} to {1}\n", edge.SourceNode.LabelText,
                                                         edge.TargetNode.LabelText));

                    message = stringB.ToString();
                }
                else
                    message = "the window is not defined";
            }

            MessageBox.Show(message);
        }
コード例 #40
0
 public Rect Convert(Microsoft.Msagl.Core.Geometry.Rectangle rect)
 {
     return(new Rect(Convert(rect.LeftTop), Convert(rect.RightBottom)));
 }
コード例 #41
0
 /// <summary>
 /// return true if the two rects are nearly identical (ignoring precision errors smaller than DistanceEpsilon)
 /// </summary>
 public static bool Close(Rectangle rect1, Rectangle rect2, double tolerance)
 {
     return(Close(rect1.LeftBottom, rect2.LeftBottom, tolerance) && Close(rect1.RightTop, rect2.RightTop, tolerance));
 }
コード例 #42
0
        void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) {
            foreach (NodeTypeEntry nte in m_NodeTypes)
                if (nte.Button == e.Button) {
                    var center = new Point();
                    var random = new Random(1);

                    var rect1 = gViewer.ClientRectangle; //gViewer.Graph.GeometryGraph.BoundingBox;
                    var rect2 = gViewer.Graph.BoundingBox;
                    Point p = gViewer.ScreenToSource(rect1.Location);
                    Point p2 = gViewer.ScreenToSource(rect1.Location + rect1.Size);
                    if (p.X < rect2.Left)
                        p.X = rect2.Left;
                    if (p2.X > rect2.Right)
                        p2.X = rect2.Right;
                    if (p.Y > rect2.Top)
                        p.Y = rect2.Top;
                    if (p2.Y < rect2.Bottom)
                        p2.Y = rect2.Bottom;
                    var rect = new Microsoft.Msagl.Core.Geometry.Rectangle(p, p2);

                    center.X = rect.Left + random.NextDouble()*rect.Width;
                    center.Y = rect.Bottom + random.NextDouble()*rect.Height;

                    
                }
        }
コード例 #43
0
 /// <summary>
 /// it is a very tricky function, please change carefully
 /// </summary>
 /// <param name="ellipse"></param>
 /// <param name="startAngle"></param>
 /// <param name="sweepAngle"></param>
 /// <param name="box"></param>
 public static void GetGdiArcDimensions(Ellipse ellipse, out float startAngle, out double sweepAngle, out BBox box) {
     box = ellipse.FullBox();
     startAngle = EllipseStandardAngle(ellipse, ellipse.ParStart);
     bool orientedCcw = ellipse.OrientedCounterclockwise();
     if ( Math.Abs(( Math.Abs(ellipse.ParEnd - ellipse.ParStart) - Math.PI * 2)) < 0.001)//we have a full ellipse
         sweepAngle = 360;
     else
         sweepAngle = (orientedCcw ? P2.Angle(ellipse.Start, ellipse.Center, ellipse.End) :P2.Angle(ellipse.End, ellipse.Center, ellipse.Start))
             * ToDegreesMultiplier;
     if (!orientedCcw)
         sweepAngle = -sweepAngle;
 }