Exemplo n.º 1
0
 void CreateOrientedSegsOnLine(Metroline line)
 {
     for (PolylinePoint polyPoint = line.Polyline.StartPoint.Next; polyPoint.Next != null; polyPoint = polyPoint.Next)
     {
         CreateOrientedSegsOnLineVertex(line, polyPoint);
     }
 }
Exemplo n.º 2
0
        void InitEdgeData(EdgeGeometry geomEdge, int index)
        {
            var metroEdge = new Metroline((Polyline)geomEdge.Curve, geomEdge.LineWidth, EdgeSourceAndTargetFunc(geomEdge), index);

            metrolines.Add(metroEdge);
            PointToStations[metroEdge.Polyline.Start].BoundaryCurve = geomEdge.SourcePort.Curve;
            PointToStations[metroEdge.Polyline.End].BoundaryCurve   = geomEdge.TargetPort.Curve;
        }
Exemplo n.º 3
0
 void InitMetroNodeInfos(Metroline metroline)
 {
     for (var pp = metroline.Polyline.StartPoint; pp != null; pp = pp.Next)
     {
         Station station = PointToStations[pp.Point];
         station.MetroNodeInfos.Add(new MetroNodeInfo(metroline, station, pp));
     }
 }
 /// <summary>
 /// Get the index of line on the edge (u->v) and node u
 /// </summary>
 int IMetroMapOrderingAlgorithm.GetLineIndexInOrder(Station u, Station v, Metroline Metroline) {
     MetroEdge me = MetroEdge.CreateFromTwoNodes(u.SerialNumber, v.SerialNumber);
     Dictionary<Metroline, int> d = lineIndexInOrder[me];
     if (u.SerialNumber < v.SerialNumber) {
         return d[Metroline];
     }
     else {
         return d.Count - 1 - d[Metroline];
     }
 }
Exemplo n.º 5
0
        internal bool PointIsAcceptableForEdge(Metroline metroline, Point point)
        {
            if (LoosePolylineOfPort == null)
            {
                return(true);
            }
            var polys = metroline.sourceAndTargetLoosePolylines();

            return(Curve.PointRelativeToCurveLocation(point, polys.Item1) == PointLocation.Outside &&
                   Curve.PointRelativeToCurveLocation(point, polys.Item2) == PointLocation.Outside);
        }
Exemplo n.º 6
0
        bool InsertPointsIntoPolyline(Metroline metroline, Dictionary <PointPair, List <Point> > splittingPoints)
        {
            bool inserted = false;

            for (var pp = metroline.Polyline.StartPoint; pp.Next != null; pp = pp.Next)
            {
                if (InsertPointsOnPolypoint(pp, splittingPoints, metroline))
                {
                    inserted = true;
                }
            }
            return(inserted);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get the index of line on the edge (u->v) and node u
        /// </summary>
        int IMetroMapOrderingAlgorithm.GetLineIndexInOrder(Station u, Station v, Metroline Metroline)
        {
            MetroEdge me = MetroEdge.CreateFromTwoNodes(u.SerialNumber, v.SerialNumber);
            Dictionary <Metroline, int> d = lineIndexInOrder[me];

            if (u.SerialNumber < v.SerialNumber)
            {
                return(d[Metroline]);
            }
            else
            {
                return(d.Count - 1 - d[Metroline]);
            }
        }
Exemplo n.º 8
0
        void CreateOrientedSegsOnLineVertex(Metroline line, PolylinePoint polyPoint)
        {
            Station            u   = metroGraphData.PointToStations[polyPoint.Prev.Point];
            Station            v   = metroGraphData.PointToStations[polyPoint.Point];
            Station            w   = metroGraphData.PointToStations[polyPoint.Next.Point];
            BundleBase         h0  = v.BundleBases[u];
            BundleBase         h1  = v.BundleBases[w];
            int                j0  = metroOrdering.GetLineIndexInOrder(u, v, line);
            int                j1  = metroOrdering.GetLineIndexInOrder(w, v, line);
            OrientedHubSegment or0 = h0.OrientedHubSegments[j0] = new OrientedHubSegment(null, false, j0, h0);
            OrientedHubSegment or1 = h1.OrientedHubSegments[j1] = new OrientedHubSegment(null, true, j1, h1);

            or1.Other = or0;
            or0.Other = or1;
        }
 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;
     if (CreateUnderlyingPolylines)
         edge.SmoothedPolyline = BuildUnderlyingPolyline(start, currentEnd, hubSegsOfLine);
 }
Exemplo n.º 10
0
        void CreateOrientedSegsOnLineVertex(Metroline line, PolylinePoint polyPoint)
        {
            Station    u   = metroGraphData.PointToStations[polyPoint.Prev.Point];
            Station    v   = metroGraphData.PointToStations[polyPoint.Point];
            Station    w   = metroGraphData.PointToStations[polyPoint.Next.Point];
            BundleBase h0  = v.BundleBases[u];
            BundleBase h1  = v.BundleBases[w];
            int        j0  = metroOrdering.GetLineIndexInOrder(u, v, line);
            int        j1  = metroOrdering.GetLineIndexInOrder(w, v, line);
            var        seg = bundlingSettings.UseCubicBezierSegmentsInsideOfHubs ?
                             StandardBezier(h0.Points[j0], h0.Tangents[j0], h1.Points[j1], h1.Tangents[j1]) :
                             BiArc(h0.Points[j0], h0.Tangents[j0], h1.Points[j1], h1.Tangents[j1]);

            h0.OrientedHubSegments[j0].Segment = seg;
            h1.OrientedHubSegments[j1].Segment = seg;
        }
Exemplo n.º 11
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;
        }
Exemplo n.º 12
0
        void InitNodeEnterableLoosePolylines(Metroline metroline, EdgeGeometry regularEdge)
        {
            //If we have groups, EdgeLooseEnterable are precomputed.
            var metrolineEnterable = EdgeLooseEnterable != null ? EdgeLooseEnterable[regularEdge] : new Set <Polyline>();

            for (var p = metroline.Polyline.StartPoint.Next; p != null && p.Next != null; p = p.Next)
            {
                var v = PointToStations[p.Point];
                if (v.EnterableLoosePolylines != null)
                {
                    v.EnterableLoosePolylines *= metrolineEnterable;
                }
                else
                {
                    v.EnterableLoosePolylines = new Set <Polyline>(metrolineEnterable);
                }
            }

            AddLooseEnterableForMetrolineStartEndPoints(metroline);
        }
        bool TrySeparateOnPolyline(Metroline metroline, Dictionary <PointPair, Set <Metroline> > segsToPolylines,
                                   HashSet <Point> affectedPoints, Set <Polyline> obstaclesAllowedToIntersect)
        {
            bool progress = false;
            var  relaxing = true;

            while (relaxing)
            {
                relaxing = false;
                for (var p = metroline.Polyline.StartPoint; p.Next != null && p.Next.Next != null; p = p.Next)
                {
                    if (TryShortcutPolypoint(p, segsToPolylines, affectedPoints, obstaclesAllowedToIntersect))
                    {
                        relaxing = true;
                    }
                }
                if (relaxing)
                {
                    progress = true;
                }
            }
            return(progress);
        }
        bool InsertPointsOnPolypoint(PolylinePoint pp, Dictionary<PointPair, List<Point>> splittingPoints, Metroline metroline) {
            var pointPair = FlipCollapser.OrderedPair(pp);
            var reversed = pp.Point != pointPair.First;
            List<Point> list;
            if (!splittingPoints.TryGetValue(pointPair, out list))
                return false;

            var endPolyPoint = pp.Next;
            var poly = pp.Polyline;
            if (reversed)
                for (int i = list.Count - 1; i >= 0; i--) {
                    if ( polylineAcceptsPoint!=null && !polylineAcceptsPoint(metroline, list[i])) continue;
                    var p = new PolylinePoint(list[i]) { Prev = pp, Polyline = poly };
                    pp.Next = p;
                    pp = p;
                }
            else
                for (int i = 0; i < list.Count; i++) {
                    if (polylineAcceptsPoint!=null &&!polylineAcceptsPoint(metroline, list[i])) continue;
                    var p = new PolylinePoint(list[i]) { Prev = pp, Polyline = poly };
                    pp.Next = p;
                    pp = p;
                }
            pp.Next = endPolyPoint;
            endPolyPoint.Prev = pp;
            return true;
        }
 internal void Add(Metroline metroline) {
     Metrolines.Add(metroline);
 }
        /// <summary>
        /// Get the index of line on the edge (u->v) and node u
        /// </summary>
#if SHARPKIT //http://code.google.com/p/sharpkit/issues/detail?id=203
        //SharpKit/Colin - Interface implementations
        public int GetLineIndexInOrder(Station u, Station v, Metroline Metroline) {
#else
        int IMetroMapOrderingAlgorithm.GetLineIndexInOrder(Station u, Station v, Metroline Metroline) {
#endif
            var edge = new PointPair(u.Position, v.Position);
            var reversed = u.Position != edge.First;
            var d = bundles[edge].LineIndexInOrder;
            return !reversed ? d[Metroline] : d.Count - 1 - d[Metroline];
        }


        
        /// <summary>
        /// Do the main job
        /// </summary>
        void BuildOrder() {
            bundles = new Dictionary<PointPair, PointPairOrder>();
            
            //initialization
            foreach (var Metroline in Metrolines) {
                for (var p = Metroline.Polyline.StartPoint; p.Next != null; p = p.Next) {
                    var e = new PointPair(p.Point, p.Next.Point);
                    PointPairOrder li;
                    if (!bundles.TryGetValue(e, out li))
                        bundles[e] = li = new PointPairOrder();
                    li.Add(Metroline);
                }
            }

            foreach (var edge in bundles)
                BuildOrder(edge.Key, edge.Value);
        }

        /// <summary>
        /// Build order for edge (u->v)
        /// </summary>
        void BuildOrder(PointPair pair, PointPairOrder order) {
            if (order.orderFixed) return;
            order.Metrolines.Sort((line0, line1) => CompareLines(line0, line1, pair.First, pair.Second));

            //save order
            order.orderFixed = true;
            order.LineIndexInOrder = new Dictionary<Metroline, int>();
            for (int i = 0; i < order.Metrolines.Count; i++)
                order.LineIndexInOrder[order.Metrolines[i]] = i;
        }




        /// <summary>
        /// Compare two lines on station u with respect to edge (u->v)
        /// </summary>
        int CompareLines(Metroline ml0, Metroline ml1, Point u, Point v) {
            PolylinePoint polylinePoint0;
            Func<PolylinePoint, PolylinePoint> next0;
            Func<PolylinePoint, PolylinePoint> prev0;
            FindStationOnLine(u, v, ml0, out polylinePoint0, out next0, out prev0);
            PolylinePoint polylinePoint1;
            Func<PolylinePoint, PolylinePoint> next1;
            Func<PolylinePoint, PolylinePoint> prev1;
            FindStationOnLine(u, v, ml1, out polylinePoint1, out next1, out prev1);

            //go backward
            var p0 = polylinePoint0;
            var p1 = polylinePoint1;
            PolylinePoint p00, p11 = null;

            while ((p00 = prev0(p0)) != null && (p11 = prev1(p1)) != null && p00.Point == p11.Point) {
                var edge = new PointPair(p00.Point, p0.Point);
                if (bundles[edge].orderFixed) {
                    return CompareOnFixedOrder(edge, ml0, ml1, p00.Point !=edge.First);
                }
                p0 = p00;
                p1 = p11;
            }

            if (p00 != null && p11 != null) {   //we have a backward fork
                var forkBase = p0.Point;
                return IsLeft(next0(p0).Point - forkBase,
                              p00.Point - forkBase,
                              p11.Point - forkBase);
            }

            //go forward
            p0 = polylinePoint0;
            p1 = polylinePoint1;
            while ((p00 = next0(p0)) != null && (p11 = next1(p1)) != null && p00.Point == p11.Point) {
                var edge = new PointPair(p00.Point, p0.Point);

                if (bundles[edge].orderFixed)
                    return CompareOnFixedOrder(edge, ml0, ml1, p0.Point!=edge.First);
                p0 = p00;
                p1 = p11;
            }


            if (p00 != null && p11 != null) {//compare forward fork
                var forkBase = p0.Point;
                return -IsLeft(prev0(p0).Point - forkBase,
                              p00.Point - forkBase,
                              p11.Point - forkBase);
            }

            //these are multiple edges
            return ml0.Index.CompareTo(ml1.Index);
        }

        int CompareOnFixedOrder(PointPair edge, Metroline ml0, Metroline ml1, bool reverse) {
            var mlToIndex = bundles[edge].LineIndexInOrder;
            int r = reverse ? -1 : 1;
            return r * mlToIndex[ml0].CompareTo(mlToIndex[ml1]);
        }


        /// <summary>
        /// Reimplement it in more efficient way!!! (cache indexes)
        /// </summary>
        void FindStationOnLine(Point u, Point v, Metroline Metroline, out PolylinePoint polyPoint, out Func<PolylinePoint, PolylinePoint> next,
            out Func<PolylinePoint, PolylinePoint> prev) {

            for (var p = Metroline.Polyline.StartPoint; p.Next != null; p = p.Next) {
                if (p.Point == u && p.Next.Point == v) {
                    next = Next;
                    prev = Prev;
                    polyPoint = p;
                    return;
                }

                if (p.Point == v && p.Next.Point == u) {
                    prev = Next;
                    next = Prev;
                    polyPoint = p.Next;
                    return;
                }
            }
            throw new InvalidOperationException();
        }
Exemplo n.º 17
0
 internal MetroNodeInfo(Metroline metroline, Station station, PolylinePoint polyPoint)
 {
     this.metroline = metroline;
     this.station   = station;
     this.polyPoint = polyPoint;
 }
        static ICurve SegOnLineVertex(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroOrdering, Metroline line, PolylinePoint i) {
            Station u = metroGraphData.PointToStations[i.Prev.Point];
            Station v = metroGraphData.PointToStations[i.Point];
            BundleBase h0 = v.BundleBases[u];
            int j0 = metroOrdering.GetLineIndexInOrder(u, v, line);
            if (h0.OrientedHubSegments[j0] == null || h0.OrientedHubSegments[j0].Segment == null) {
                var w = metroGraphData.PointToStations[i.Next.Point];
                var otherBase = v.BundleBases[w];
                var j1 = metroOrdering.GetLineIndexInOrder(w, v, line);
                return new LineSegment(h0.Points[j0], otherBase.Points[j1]);
            }

            return h0.OrientedHubSegments[j0].Segment;
        }
        void CreateOrientedSegsOnLineVertex(Metroline line, PolylinePoint polyPoint) {
            Station u = metroGraphData.PointToStations[polyPoint.Prev.Point];
            Station v = metroGraphData.PointToStations[polyPoint.Point];
            Station w = metroGraphData.PointToStations[polyPoint.Next.Point];
            BundleBase h0 = v.BundleBases[u];
            BundleBase h1 = v.BundleBases[w];
            int j0 = metroOrdering.GetLineIndexInOrder(u, v, line);
            int j1 = metroOrdering.GetLineIndexInOrder(w, v, line);
            var seg = bundlingSettings.UseCubicBezierSegmentsInsideOfHubs ?
                StandardBezier(h0.Points[j0], h0.Tangents[j0], h1.Points[j1], h1.Tangents[j1]) :
                BiArc(h0.Points[j0], h0.Tangents[j0], h1.Points[j1], h1.Tangents[j1]);

            h0.OrientedHubSegments[j0].Segment = seg;
            h1.OrientedHubSegments[j1].Segment = seg;
        }
 internal MetroNodeInfo(Metroline metroline, Station station, PolylinePoint polyPoint) {
     this.metroline = metroline;
     this.station = station;
     this.polyPoint = polyPoint;
 }
Exemplo n.º 21
0
 internal void Add(Metroline metroline)
 {
     Metrolines.Add(metroline);
 }
 internal bool PointIsAcceptableForEdge(Metroline metroline, Point point) {
     if (LoosePolylineOfPort == null)
         return true;
     var polys = metroline.sourceAndTargetLoosePolylines();
     return Curve.PointRelativeToCurveLocation(point, polys.Item1) == PointLocation.Outside &&
            Curve.PointRelativeToCurveLocation(point, polys.Item2) == PointLocation.Outside;
 }
 bool InsertPointsIntoPolyline(Metroline metroline, Dictionary<PointPair, List<Point>> splittingPoints) {
     bool inserted = false;
     for (var pp = metroline.Polyline.StartPoint; pp.Next != null; pp = pp.Next)
         if (InsertPointsOnPolypoint(pp, splittingPoints, metroline)) inserted = true;
     return inserted;
 }
        void InitNodeEnterableTightPolylines(Metroline metroline, EdgeGeometry regularEdge) {
            //If we have groups, EdgeTightEnterable are precomputed.
            var metrolineEnterable = EdgeTightEnterable != null ? EdgeTightEnterable[regularEdge] : new Set<Polyline>();

            for (var p = metroline.Polyline.StartPoint.Next; p!=null && p.Next != null; p = p.Next) {
                var v = PointToStations[p.Point];
                Set<Polyline> nodeEnterable = v.EnterableTightPolylines;
                if (nodeEnterable != null)
                    v.EnterableTightPolylines = nodeEnterable * metrolineEnterable;
                else
                    v.EnterableTightPolylines = new Set<Polyline>(metrolineEnterable);
            }

            AddTightEnterableForMetrolineStartEndPoints(metroline);
        }
 void AddTightEnterableForMetrolineStartEndPoints(Metroline metroline) {
     AddTightEnterableForEnd(metroline.Polyline.Start);
     AddTightEnterableForEnd(metroline.Polyline.End);
 }
 void InitMetroNodeInfos(Metroline metroline) {
     for (var pp = metroline.Polyline.StartPoint; pp != null; pp = pp.Next) {
         Station station = PointToStations[pp.Point];
         station.MetroNodeInfos.Add(new MetroNodeInfo(metroline, station, pp));
     }
 }
 void InitEdgeData(EdgeGeometry geomEdge, int index) {
     var metroEdge = new Metroline((Polyline)geomEdge.Curve, geomEdge.LineWidth, EdgeSourceAndTargetFunc(geomEdge), index);
     metrolines.Add(metroEdge);
     PointToStations[metroEdge.Polyline.Start].BoundaryCurve = geomEdge.SourcePort.Curve;
     PointToStations[metroEdge.Polyline.End].BoundaryCurve = geomEdge.TargetPort.Curve;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Get the index of line on the edge (u->v) and node u
        /// </summary>
#if SHARPKIT //http://code.google.com/p/sharpkit/issues/detail?id=203
        //SharpKit/Colin - Interface implementations
        public int GetLineIndexInOrder(Station u, Station v, Metroline Metroline)
        {
#else
        int IMetroMapOrderingAlgorithm.GetLineIndexInOrder(Station u, Station v, Metroline Metroline)
        {
#endif
            var edge     = new PointPair(u.Position, v.Position);
            var reversed = u.Position != edge.First;
            var d        = bundles[edge].LineIndexInOrder;
            return(!reversed ? d[Metroline] : d.Count - 1 - d[Metroline]);
        }

        /// <summary>
        /// Do the main job
        /// </summary>
        void BuildOrder()
        {
            bundles = new Dictionary <PointPair, PointPairOrder>();

            //initialization
            foreach (var Metroline in Metrolines)
            {
                for (var p = Metroline.Polyline.StartPoint; p.Next != null; p = p.Next)
                {
                    var            e = new PointPair(p.Point, p.Next.Point);
                    PointPairOrder li;
                    if (!bundles.TryGetValue(e, out li))
                    {
                        bundles[e] = li = new PointPairOrder();
                    }
                    li.Add(Metroline);
                }
            }

            foreach (var edge in bundles)
            {
                BuildOrder(edge.Key, edge.Value);
            }
        }

        /// <summary>
        /// Build order for edge (u->v)
        /// </summary>
        void BuildOrder(PointPair pair, PointPairOrder order)
        {
            if (order.orderFixed)
            {
                return;
            }
            order.Metrolines.Sort((line0, line1) => CompareLines(line0, line1, pair.First, pair.Second));

            //save order
            order.orderFixed       = true;
            order.LineIndexInOrder = new Dictionary <Metroline, int>();
            for (int i = 0; i < order.Metrolines.Count; i++)
            {
                order.LineIndexInOrder[order.Metrolines[i]] = i;
            }
        }

        /// <summary>
        /// Compare two lines on station u with respect to edge (u->v)
        /// </summary>
        int CompareLines(Metroline ml0, Metroline ml1, Point u, Point v)
        {
            PolylinePoint polylinePoint0;
            Func <PolylinePoint, PolylinePoint> next0;
            Func <PolylinePoint, PolylinePoint> prev0;

            FindStationOnLine(u, v, ml0, out polylinePoint0, out next0, out prev0);
            PolylinePoint polylinePoint1;
            Func <PolylinePoint, PolylinePoint> next1;
            Func <PolylinePoint, PolylinePoint> prev1;

            FindStationOnLine(u, v, ml1, out polylinePoint1, out next1, out prev1);

            //go backward
            var           p0 = polylinePoint0;
            var           p1 = polylinePoint1;
            PolylinePoint p00, p11 = null;

            while ((p00 = prev0(p0)) != null && (p11 = prev1(p1)) != null && p00.Point == p11.Point)
            {
                var edge = new PointPair(p00.Point, p0.Point);
                if (bundles[edge].orderFixed)
                {
                    return(CompareOnFixedOrder(edge, ml0, ml1, p00.Point != edge.First));
                }

                p0 = p00;
                p1 = p11;
            }

            if (p00 != null && p11 != null)     //we have a backward fork
            {
                var forkBase = p0.Point;
                return(IsLeft(next0(p0).Point - forkBase,
                              p00.Point - forkBase,
                              p11.Point - forkBase));
            }

            //go forward
            p0 = polylinePoint0;
            p1 = polylinePoint1;
            while ((p00 = next0(p0)) != null && (p11 = next1(p1)) != null && p00.Point == p11.Point)
            {
                var edge = new PointPair(p00.Point, p0.Point);

                if (bundles[edge].orderFixed)
                {
                    return(CompareOnFixedOrder(edge, ml0, ml1, p0.Point != edge.First));
                }
                p0 = p00;
                p1 = p11;
            }


            if (p00 != null && p11 != null)  //compare forward fork
            {
                var forkBase = p0.Point;
                return(-IsLeft(prev0(p0).Point - forkBase,
                               p00.Point - forkBase,
                               p11.Point - forkBase));
            }

            //these are multiple edges
            return(ml0.Index.CompareTo(ml1.Index));
        }

        int CompareOnFixedOrder(PointPair edge, Metroline ml0, Metroline ml1, bool reverse)
        {
            var mlToIndex = bundles[edge].LineIndexInOrder;
            int r         = reverse ? -1 : 1;

            return(r * mlToIndex[ml0].CompareTo(mlToIndex[ml1]));
        }

        /// <summary>
        /// Reimplement it in more efficient way!!! (cache indexes)
        /// </summary>
        void FindStationOnLine(Point u, Point v, Metroline Metroline, out PolylinePoint polyPoint, out Func <PolylinePoint, PolylinePoint> next,
                               out Func <PolylinePoint, PolylinePoint> prev)
        {
            for (var p = Metroline.Polyline.StartPoint; p.Next != null; p = p.Next)
            {
                if (p.Point == u && p.Next.Point == v)
                {
                    next      = Next;
                    prev      = Prev;
                    polyPoint = p;
                    return;
                }

                if (p.Point == v && p.Next.Point == u)
                {
                    prev      = Next;
                    next      = Prev;
                    polyPoint = p.Next;
                    return;
                }
            }
            throw new InvalidOperationException();
        }
Exemplo n.º 29
0
        bool InsertPointsOnPolypoint(PolylinePoint pp, Dictionary <PointPair, List <Point> > splittingPoints, Metroline metroline)
        {
            var          pointPair = FlipCollapser.OrderedPair(pp);
            var          reversed  = pp.Point != pointPair.First;
            List <Point> list;

            if (!splittingPoints.TryGetValue(pointPair, out list))
            {
                return(false);
            }

            var endPolyPoint = pp.Next;
            var poly         = pp.Polyline;

            if (reversed)
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    if (polylineAcceptsPoint != null && !polylineAcceptsPoint(metroline, list[i]))
                    {
                        continue;
                    }
                    var p = new PolylinePoint(list[i])
                    {
                        Prev = pp, Polyline = poly
                    };
                    pp.Next = p;
                    pp      = p;
                }
            }
            else
            {
                for (int i = 0; i < list.Count; i++)
                {
                    if (polylineAcceptsPoint != null && !polylineAcceptsPoint(metroline, list[i]))
                    {
                        continue;
                    }
                    var p = new PolylinePoint(list[i])
                    {
                        Prev = pp, Polyline = poly
                    };
                    pp.Next = p;
                    pp      = p;
                }
            }

            pp.Next           = endPolyPoint;
            endPolyPoint.Prev = pp;
            return(true);
        }
 bool TrySeparateOnPolyline(Metroline metroline, Dictionary<PointPair, Set<Metroline>> segsToPolylines,
                            HashSet<Point> affectedPoints, Set<Polyline> obstaclesAllowedToIntersect) {
     bool progress = false;
     var relaxing = true;
     while (relaxing) {
         relaxing = false;
         for (var p = metroline.Polyline.StartPoint; p.Next != null && p.Next.Next != null; p = p.Next)
             if (TryShortcutPolypoint(p, segsToPolylines, affectedPoints, obstaclesAllowedToIntersect))
                 relaxing = true;
         if (relaxing) progress = true;
     }
     return progress;
 }
 void CreateOrientedSegsOnLineVertex(Metroline line, PolylinePoint polyPoint) {
     Station u = metroGraphData.PointToStations[polyPoint.Prev.Point];
     Station v = metroGraphData.PointToStations[polyPoint.Point];
     Station w = metroGraphData.PointToStations[polyPoint.Next.Point];
     BundleBase h0 = v.BundleBases[u];
     BundleBase h1 = v.BundleBases[w];
     int j0 = metroOrdering.GetLineIndexInOrder(u, v, line);
     int j1 = metroOrdering.GetLineIndexInOrder(w, v, line);
     OrientedHubSegment or0 = h0.OrientedHubSegments[j0] = new OrientedHubSegment(null, false, j0, h0);
     OrientedHubSegment or1 = h1.OrientedHubSegments[j1] = new OrientedHubSegment(null, true, j1, h1);
     or1.Other = or0;
     or0.Other = or1;
 }
Exemplo n.º 32
0
        static ICurve SegOnLineVertex(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroOrdering, Metroline line, PolylinePoint i)
        {
            Station    u  = metroGraphData.PointToStations[i.Prev.Point];
            Station    v  = metroGraphData.PointToStations[i.Point];
            BundleBase h0 = v.BundleBases[u];
            int        j0 = metroOrdering.GetLineIndexInOrder(u, v, line);

            if (h0.OrientedHubSegments[j0] == null || h0.OrientedHubSegments[j0].Segment == null)
            {
                var w         = metroGraphData.PointToStations[i.Next.Point];
                var otherBase = v.BundleBases[w];
                var j1        = metroOrdering.GetLineIndexInOrder(w, v, line);
                return(new LineSegment(h0.Points[j0], otherBase.Points[j1]));
            }

            return(h0.OrientedHubSegments[j0].Segment);
        }
 static IEnumerable<ICurve> HubSegsOfLine(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroOrdering, Metroline line) {
     for (PolylinePoint i = line.Polyline.StartPoint.Next; i.Next != null; i = i.Next)
         yield return SegOnLineVertex(metroGraphData, metroOrdering, line, i);
 }
Exemplo n.º 34
0
 static IEnumerable <ICurve> HubSegsOfLine(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroOrdering, Metroline line)
 {
     for (PolylinePoint i = line.Polyline.StartPoint.Next; i.Next != null; i = i.Next)
     {
         yield return(SegOnLineVertex(metroGraphData, metroOrdering, line, i));
     }
 }
 void CreateOrientedSegsOnLine(Metroline line) {
     for (PolylinePoint polyPoint = line.Polyline.StartPoint.Next; polyPoint.Next != null; polyPoint = polyPoint.Next)
         CreateOrientedSegsOnLineVertex(line, polyPoint);
 }
Exemplo n.º 36
0
        static Point FindCurveEnd(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroOrdering, Metroline metroline)
        {
            Station u = metroGraphData.PointToStations[metroline.Polyline.EndPoint.Prev.Point];
            Station v = metroGraphData.PointToStations[metroline.Polyline.EndPoint.Point];

            BundleBase bb    = v.BundleBases[u];
            int        index = (!bb.IsParent ? metroOrdering.GetLineIndexInOrder(u, v, metroline) : metroOrdering.GetLineIndexInOrder(v, u, metroline));

            return(bb.Points[index]);
        }
        static List<Tuple<Point, Point>> GetInterestingSegs(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroMapOrdering, Metroline line) {
            var ret = new List<Tuple<Point, Point>>();
            Point start = FindCurveStart(metroGraphData, metroMapOrdering, line);
            var cubicSegs = HubSegsOfLine(metroGraphData, metroMapOrdering, line);
            foreach (var seg in cubicSegs) {
                if (seg == null) continue;
                ret.Add(new Tuple<Point, Point>(start, seg.Start));
                start = seg.End;
            }
            ret.Add(new Tuple<Point, Point>(start, FindCurveEnd(metroGraphData, metroMapOrdering, line)));

            return ret;
        }
Exemplo n.º 38
0
 void AddTightEnterableForMetrolineStartEndPoints(Metroline metroline)
 {
     AddTightEnterableForEnd(metroline.Polyline.Start);
     AddTightEnterableForEnd(metroline.Polyline.End);
 }
        static Point FindCurveStart(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroOrdering, Metroline metroline) {
            Station u = metroGraphData.PointToStations[metroline.Polyline.StartPoint.Point];
            Station v = metroGraphData.PointToStations[metroline.Polyline.StartPoint.Next.Point];

            BundleBase bb = u.BundleBases[v];
            int index = (!bb.IsParent ? metroOrdering.GetLineIndexInOrder(v, u, metroline) : metroOrdering.GetLineIndexInOrder(u, v, metroline));
            return bb.Points[index];
        }
Exemplo n.º 40
0
        static List <Tuple <Point, Point> > GetInterestingSegs(MetroGraphData metroGraphData, IMetroMapOrderingAlgorithm metroMapOrdering, Metroline line)
        {
            var   ret       = new List <Tuple <Point, Point> >();
            Point start     = FindCurveStart(metroGraphData, metroMapOrdering, line);
            var   cubicSegs = HubSegsOfLine(metroGraphData, metroMapOrdering, line);

            foreach (var seg in cubicSegs)
            {
                if (seg == null)
                {
                    continue;
                }
                ret.Add(new Tuple <Point, Point>(start, seg.Start));
                start = seg.End;
            }
            ret.Add(new Tuple <Point, Point>(start, FindCurveEnd(metroGraphData, metroMapOrdering, line)));

            return(ret);
        }