/// <summary>
        /// Return the transformed curve
        /// </summary>
        /// <param name="transformation"></param>
        /// <returns>the transformed curve</returns>
        public ICurve Transform(PlaneTransformation transformation) {
            Curve c = new Curve(segs.Count);
            foreach (ICurve s in segs)
                c.AddSegment(s.Transform(transformation));

            return c;
        }
        /// <summary>
        /// Returns the curved scaled by x and y
        /// </summary>
        /// <param name="xScale"></param>
        /// <param name="yScale"></param>
        /// <returns></returns>     
        public ICurve ScaleFromOrigin(double xScale, double yScale)
        {
            Curve c = new Curve(segs.Count);
            foreach (ICurve s in segs)
                c.AddSegment(s.ScaleFromOrigin(xScale, yScale));

            return c;
        }
Example #3
0
        /// <summary>
        /// Returns the curved scaled by x and y
        /// </summary>
        /// <param name="xScale"></param>
        /// <param name="yScale"></param>
        /// <returns></returns>
        public ICurve ScaleFromOrigin(double xScale, double yScale)
        {
            Curve c = new Curve(segs.Count);

            foreach (ICurve s in segs)
            {
                c.AddSegment(s.ScaleFromOrigin(xScale, yScale));
            }

            return(c);
        }
Example #4
0
        private Curve ReadCurve()
        {
            var   c = new Curve();
            Match m;

            while ((m = ParseNextOrDone(RectFileStrings.ParseSegment, RectFileStrings.EndCurve)).Success)
            {
                c.AddSegment(LoadLineSegment(m));
            }
            return(c);
        }
Example #5
0
        void CreateCurveLine(Metroline line, EdgeGeometry edge)
        {
            var   c             = new Curve();
            Point start         = FindCurveStart(metroGraphData, metroOrdering, line);
            Point currentEnd    = start;
            var   hubSegsOfLine = HubSegsOfLine(metroGraphData, metroOrdering, line);

            foreach (var seg in hubSegsOfLine)
            {
                if (seg == null)
                {
                    continue;
                }
                c.AddSegment(new LineSegment(currentEnd, seg.Start));
                c.AddSegment(seg);
                currentEnd = seg.End;
            }
            c.AddSegment(new LineSegment(currentEnd, FindCurveEnd(metroGraphData, metroOrdering, line)));
            edge.Curve = c;
        }
Example #6
0
        static ICurve CreatObstaceOnLabel(Label label)
        {
            var    c = new Curve();
            double obstacleBottom = label.Center.Y - label.Height / 4;

            c.AddSegment(new LineSegment(new Point(label.BoundingBox.Left, obstacleBottom),
                                         new Point(label.BoundingBox.Right, obstacleBottom)));
            Curve.ContinueWithLineSegment(c, label.BoundingBox.RightTop);
            Curve.ContinueWithLineSegment(c, label.BoundingBox.LeftTop);
            Curve.CloseCurve(c);
            return(c);
        }
        private Curve ExtendCurveToEndpoints(Curve curve)
        {
            Point p = headSite.Point;

            if (!ApproximateComparer.Close(p, curve.Start))
            {
                Curve nc = new Curve();
                nc.AddSegs(new LineSegment(p, curve.Start), curve);
                curve = nc;
            }
            p = TailSite.Point;
            if (!ApproximateComparer.Close(p, curve.End))
            {
                curve.AddSegment(new LineSegment(curve.End, p));
            }
            return(curve);
        }
        private Curve ExtendCurveToEndpoints(Curve curve)
        {
            Point p = this.EdgePathPoint(0);

            if (!ApproximateComparer.Close(p, curve.Start))
            {
                Curve nc = new Curve();
                nc.AddSegs(new LineSegment(p, curve.Start), curve);
                curve = nc;
            }
            p = this.EdgePathPoint(edgePath.Count);
            if (!ApproximateComparer.Close(p, curve.End))
            {
                curve.AddSegment(new LineSegment(curve.End, p));
            }
            return(curve);
        }
        /// <summary>
        /// Creates a curve by using the underlying polyline
        /// </summary>
        /// <returns></returns>
        public Curve CreateCurve()
        {
            Curve curve = new Curve();
            Site  a     = HeadSite; //the corner start
            Site  b;                //the corner origin
            Site  c;                //the corner other end

            while (Curve.FindCorner(a, out b, out c))
            {
                CubicBezierSegment bezierSeg = CreateBezierSegOnSite(b);
                if (curve.Segments.Count == 0)
                {
                    if (!ApproximateComparer.Close(a.Point, bezierSeg.Start))
                    {
                        Curve.AddLineSegment(curve, a.Point, bezierSeg.Start);
                    }
                }
                else if (!ApproximateComparer.Close(curve.End, bezierSeg.Start))
                {
                    Curve.ContinueWithLineSegment(curve, bezierSeg.Start);
                }
                curve.AddSegment(bezierSeg);
                a = b;
            }

            System.Diagnostics.Debug.Assert(a.Next.Next == null);

            if (curve.Segments.Count == 0)
            {
                if (!ApproximateComparer.Close(a.Point, a.Next.Point))
                {
                    Curve.AddLineSegment(curve, a.Point, a.Next.Point);
                }
                else
                {
                    double w = 5;
                    curve.Segments.Add(new CubicBezierSegment(a.Point, a.Point + new Point(w, w), a.Point + new Point(-w, w), b.Point));
                }
            }
            else if (!ApproximateComparer.Close(curve.End, a.Next.Point))
            {
                Curve.ContinueWithLineSegment(curve, a.Next.Point);
            }
            return(curve);
        }
        Curve CreateSmoothedPolyline()
        {
            RemoveVerticesWithNoTurns();
            Curve curve = new Curve();
            Site  a     = headSite; //the corner start
            Site  b;                //the corner origin
            Site  c;                //the corner other end

            if (Curve.FindCorner(a, out b, out c))
            {
                CreateFilletCurve(curve, ref a, ref b, ref c);
                curve = ExtendCurveToEndpoints(curve);
            }
            else
            {
                curve.AddSegment(new LineSegment(headSite.Point, TailSite.Point));
            }
            return(curve);
        }
Example #11
0
    private void Input()
    {
        Event   guiEvent      = Event.current;
        Vector2 mousePosition = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition).origin;

        if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0 && guiEvent.shift)
        {
            if (curve.isClosed)
            {
                return;
            }
            Undo.RecordObject(creator, "New Segment");
            curve.AddSegment(mousePosition);
        }
        else if (guiEvent.type == EventType.KeyDown && guiEvent.keyCode == KeyCode.A)
        {
            creator.curve = new Curve();
            curve         = creator.curve;
            curve.StartCurve(Vector2.zero);
            curve.isClosed = false;
        }
    }
Example #12
0
        public static ICurve GetNodeBoundary(Microsoft.Msagl.Drawing.Node n)
        {
            double cell = s_random.Next(50, 80);
            double ecc  = (((double)s_random.Next(20, 100) / 100.00) * cell);

            switch (n.Id.Split()[0])
            {
            case "Rhombus":
                return(CurveFactory.CreateDiamond(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point()));

            case "Circle":
                return(CurveFactory.CreateCircle(cell / 2.0, new Microsoft.Msagl.Core.Geometry.Point()));

            case "Ellipse":
                return(CurveFactory.CreateEllipse(cell / 2.0, ecc / 2.0, new Microsoft.Msagl.Core.Geometry.Point()));

            case "Rectangle":
                return(CurveFactory.CreateRectangle(cell, ecc, new Point()));

            case "Parallelogram":
            {
                ICurve baseRect = CurveFactory.CreateRectangle(cell, ecc, new Point());
                return(baseRect.Transform(new PlaneTransformation(1, (double)s_random.Next(0, 100) / 100.00, 0, 0, 1, 0)));
            }

            case "CurvedRectangle":
                return(CurveFactory.CreateRectangleWithRoundedCorners(cell * 2, ecc, ecc / 4, ecc / 4, new Microsoft.Msagl.Core.Geometry.Point()));

            case "Process":
            {
                Curve curve      = (Curve)CurveFactory.CreateRectangle(cell * 2, ecc, new Microsoft.Msagl.Core.Geometry.Point());
                Curve curveInner = (Curve)CurveFactory.CreateRectangle(cell * 1.5, ecc, new Microsoft.Msagl.Core.Geometry.Point());
                Curve.CloseCurve(curve);
                Curve.CloseCurve(curveInner);
                Curve.AddLineSegment(curve, curve.Start, curveInner.Start);
                curve.AddSegment(curveInner);
                return(curve);
            }

            case "ElongatedEllipse":
            {
                var    curve = new Curve();
                double x     = cell;
                double y     = ecc;
                double r     = x / 2;
                curve.AddSegment(new Ellipse(1.5 * Math.PI, 2.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(x, 0)));
                curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, y)));
                curve.AddSegment(new Ellipse(0.5 * Math.PI, 1.5 * Math.PI, new Point(r, 0), new Point(0, y), new Point(-1 * x, 0)));
                Curve.CloseCurve(curve);
                return(curve);
            }

            case "Database":
            {
                var    curve = new Curve();
                double x     = ecc;
                double y     = cell;
                double r     = y / 2;
                curve.AddSegment(new Ellipse(new Point(x, 0), new Point(0, r), new Point(0, 0)));
                curve.AddSegment(new Ellipse(0, Math.PI, new Point(x, 0), new Point(0, r), new Point(0, 0)));
                curve.AddSegment(new LineSegment(curve.End, new Point(-1 * x, -1 * y)));
                curve.AddSegment(new LineSegment(curve.End, new Point(x, -1 * y)));
                Curve.CloseCurve(curve);
                return(curve);
            }
            }
            throw new Exception("unrecognised shape type");
        }