public Intersections(MetroGraphData metroGraphData, BundlingSettings bundlingSettings,
     RectangleNode<Polyline> obstacleTree, Func<Station, Set<Polyline>> obstaclesToIgnore) {
     this.metroGraphData = metroGraphData;
     this.obstaclesToIgnore = obstaclesToIgnore;
     this.bundlingSettings = bundlingSettings;
     this.obstacleTree = obstacleTree;
 }
 internal MultiEdgeRouter(List<Edge[]> multiEdgeGeoms, InteractiveEdgeRouter interactiveEdgeRouter, IEnumerable<ICurve> nodeBoundaryCurves, BundlingSettings bundlingSettings, Func<EdgeGeometry, List<Shape>> transparentShapeSetter) {
     multiEdgeGeometries = multiEdgeGeoms.Select(l => l.Select(e => e.EdgeGeometry).ToArray()).ToList();
     
     this.interactiveEdgeRouter = interactiveEdgeRouter;
     this.bundlingSettings = bundlingSettings;
     this.transparentShapeSetter = transparentShapeSetter;
     nodeTree = RectangleNode<ICurve>.CreateRectangleNodeOnData(nodeBoundaryCurves, c => c.BoundingBox);
 }
        void CalculateTightObstaclesForBundle(RectangleNode<Polyline> tightTree, Set<Polyline> obstaclesToIgnore) {
            double sRadius = SourceBase.Curve.BoundingBox.Diagonal / 2;
            double tRadius = TargetBase.Curve.BoundingBox.Diagonal / 2;

            //Polyline bundle = Intersections.Create4gon(SourceBase.CurveCenter, TargetBase.CurveCenter, sRadius * 2, tRadius * 2);
            Polyline bundle = Intersections.Create4gon(SourceBase.Position, TargetBase.Position, sRadius * 2, tRadius * 2);

            tightObstaclesInTheBoundingBox = tightTree.AllHitItems(bundle.BoundingBox,
                p => !obstaclesToIgnore.Contains(p) && Curve.ClosedCurveInteriorsIntersect(bundle, p)).ToList();
        }
        void CreateTigthLooseCouples() {
            var couples = new List<TightLooseCouple>();

            foreach (var tightPolyline in tightHierarchy.GetAllLeaves()) {
                var distance = InteractiveObstacleCalculator.FindMaxPaddingForTightPolyline(tightHierarchy, tightPolyline, LoosePadding);
                var loosePoly = InteractiveObstacleCalculator.LoosePolylineWithFewCorners(tightPolyline, distance);
                couples.Add(new TightLooseCouple(tightPolyline, new Shape(loosePoly), distance));
            }
            coupleHierarchy = RectangleNode<TightLooseCouple>.
                CreateRectangleNodeOnEnumeration(couples.Select(c => new RectangleNode<TightLooseCouple>(c, c.TightPolyline.BoundingBox)));
        }
 private void GetIntersecting(RectangleNode<IHull> leafNode, RectangleNode<IHull> internalNode, List<IHull> intersecting) {
     Debug.Assert(leafNode.UserData != null);
     if (!leafNode.Rectangle.Intersects(internalNode.Rectangle))
         return;
     if (internalNode.UserData != null) {
         if (leafNode.UserData != internalNode.UserData) {
             intersecting.Add(internalNode.UserData);
         }
     } else {
         GetIntersecting(leafNode, internalNode.Left, intersecting);
         GetIntersecting(leafNode, internalNode.Right, intersecting);
     }
 }
        internal static bool LandlocksPoint(RectangleNode<Obstacle> root, Point location) 
        {
            var bbox = root.Rectangle;
            if (!bbox.Contains(location)) 
            {
                return false;
            }

            // This is just a simple test; a more robust one would actually look for a bendy path.);
            return IntersectsSegment(root, location, StaticGraphUtility.RectangleBorderIntersect(bbox, location, Directions.North))
                || IntersectsSegment(root, location, StaticGraphUtility.RectangleBorderIntersect(bbox, location, Directions.South))
                || IntersectsSegment(root, location, StaticGraphUtility.RectangleBorderIntersect(bbox, location, Directions.East))
                || IntersectsSegment(root, location, StaticGraphUtility.RectangleBorderIntersect(bbox, location, Directions.West));
        }
        void Init() {
            foreach (EdgeGeometry e in metroGraphData.Edges) {
                polylineToEdgeGeom[(Polyline)e.Curve] = e;
            }

            var del = new Point(ApproximateComparer.DistanceEpsilon, ApproximateComparer.DistanceEpsilon);

            if (cdt != null) {
                siteHierarchy = RectangleNode<CdtSite>.CreateRectangleNodeOnEnumeration(
                        cdt.PointsToSites.Values.Select(site => new RectangleNode<CdtSite>(site, new Rectangle(site.Point + del, site.Point - del))));

                triangleHierarchy = RectangleNode<CdtTriangle>.CreateRectangleNodeOnEnumeration(
                        cdt.GetTriangles().Select(tr => new RectangleNode<CdtTriangle>(tr, TriangleRectangle(tr.Sites))));
            }

            CreatePathsThroughPoints();
        }
        internal BundleRouter(GeometryGraph geometryGraph, SdShortestPath shortestPathRouter,
                              VisibilityGraph visibilityGraph, BundlingSettings bundlingSettings, double loosePadding, RectangleNode<Polyline> tightHierarchy,
                              RectangleNode<Polyline> looseHierarchy,
                              Dictionary<EdgeGeometry, Set<Polyline>> edgeLooseEnterable, Dictionary<EdgeGeometry, Set<Polyline>> edgeTightEnterable, Func<Port, Polyline> loosePolylineOfPort) {
            ValidateArg.IsNotNull(geometryGraph, "geometryGraph");
            ValidateArg.IsNotNull(bundlingSettings, "bundlingSettings");

            this.geometryGraph = geometryGraph;
            this.bundlingSettings = bundlingSettings;
            regularEdges = geometryGraph.Edges.Where(e => e.Source != e.Target).ToArray();
            VisibilityGraph = visibilityGraph;
            this.shortestPathRouter = shortestPathRouter;
            LoosePadding = loosePadding;
            LooseHierarchy = looseHierarchy;
            TightHierarchy = tightHierarchy;
            EdgeLooseEnterable = edgeLooseEnterable;
            EdgeTightEnterable = edgeTightEnterable;
            this.loosePolylineOfPort = loosePolylineOfPort;
        }
Esempio n. 9
0
        int CountCrossingsWithRTree(Size[] nodeSizes)
        {
            RectangleNode <int> rootNode =
                RectangleNode <int> .CreateRectangleNodeOnEnumeration(
                    nodeSizes.Select((r, index) => new RectangleNode <int>(index, new Rectangle(r, nodePositions[index]))));

            int numCrossings = 0;

            RectangleNodeUtils.CrossRectangleNodes <int, int>(rootNode, rootNode,
                                                              (a, b) => {
                if (a == b)
                {
                    return;
                }
                numCrossings++;
            });

            return(numCrossings);
        }
Esempio n. 10
0
        private void button1_Click(object sender, EventArgs e)  //this is abstract.dot of GraphViz
        {
            var tree = RectangleNode <object> .CreateRectangleNodeOnEnumeration(GetRectangleNodesFromGraph());

            var       numberOfTries = 10000;
            Random    random        = new Random(1);
            double    rectWidth     = 50;
            double    rectHeight    = 200;
            var       delta         = new Point(rectWidth / 2, rectHeight / 2);
            Rectangle bestRectangle = Rectangle.CreateAnEmptyBox();

            Point  hint        = (gViewer.Graph.BoundingBox.LeftBottom + gViewer.Graph.BoundingBox.RightTop) / 2;
            double minDistance = double.PositiveInfinity;

            for (int i = 0; i < numberOfTries; i++)
            {
                Point     randomCenter = GetRandomCenter(rectHeight, rectWidth, random);
                Rectangle r            = new Rectangle(randomCenter);
                r.Add(randomCenter + delta);
                r.Add(randomCenter - delta);
                if (tree.GetNodeItemsIntersectingRectangle(r).Any())
                {
                }
                else
                {
                    var len = (randomCenter - hint).LengthSquared;
                    if (len < minDistance)
                    {
                        minDistance   = len;
                        bestRectangle = r;
                    }
                }
            }
            if (bestRectangle.IsEmpty == false)
            {
                InsertNodeIntoGraph(bestRectangle);
            }
            else
            {
                MessageBox.Show("cannot insert");
            }
        }
Esempio n. 11
0
        static internal Cdt CreateConstrainedDelaunayTriangulation(RectangleNode <Polyline> looseHierarchy)
        {
            IEnumerable <Polyline> obstacles = looseHierarchy.GetAllLeaves();

            Rectangle rectangle = looseHierarchy.Rectangle;
            double    d         = rectangle.Diagonal / 4;
            Point     lb        = rectangle.LeftBottom + new Point(-d, -d);
            Point     lt        = rectangle.LeftTop + new Point(-d, d);
            Point     rt        = rectangle.RightTop + new Point(d, d);
            Point     rb        = rectangle.RightBottom + new Point(d, -d);

            var additionalObstacles = new[] {
                new Polyline(lb, lt, rt, rb)
                {
                    Closed = true
                }
            };

            return(GetConstrainedDelaunayTriangulation(obstacles.Concat(additionalObstacles)));
        }
Esempio n. 12
0
        internal BundleRouter(GeometryGraph geometryGraph, SdShortestPath shortestPathRouter,
                              VisibilityGraph visibilityGraph, BundlingSettings bundlingSettings, double loosePadding, RectangleNode <Polyline> tightHierarchy,
                              RectangleNode <Polyline> looseHierarchy,
                              Dictionary <EdgeGeometry, Set <Polyline> > edgeLooseEnterable, Dictionary <EdgeGeometry, Set <Polyline> > edgeTightEnterable, Func <Port, Polyline> loosePolylineOfPort)
        {
            ValidateArg.IsNotNull(geometryGraph, "geometryGraph");
            ValidateArg.IsNotNull(bundlingSettings, "bundlingSettings");

            this.geometryGraph       = geometryGraph;
            this.bundlingSettings    = bundlingSettings;
            regularEdges             = geometryGraph.Edges.Where(e => e.Source != e.Target).ToArray();
            VisibilityGraph          = visibilityGraph;
            this.shortestPathRouter  = shortestPathRouter;
            LoosePadding             = loosePadding;
            LooseHierarchy           = looseHierarchy;
            TightHierarchy           = tightHierarchy;
            EdgeLooseEnterable       = edgeLooseEnterable;
            EdgeTightEnterable       = edgeTightEnterable;
            this.loosePolylineOfPort = loosePolylineOfPort;
        }
        public void Should_Replace_Different_DrawOperation()
        {
            var node      = new VisualNode(new TestRoot(), null);
            var operation = new RectangleNode(Matrix.Identity, Brushes.Red, null, new Rect(0, 0, 100, 100), 0);
            var layers    = new SceneLayers(node.Visual);
            var target    = new DeferredDrawingContextImpl(null, layers);

            node.LayerRoot = node.Visual;
            node.AddDrawOperation(operation);

            using (target.BeginUpdate(node))
            {
                target.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100));
            }

            Assert.Equal(1, node.DrawOperations.Count);
            Assert.NotSame(operation, node.DrawOperations.Single());

            Assert.IsType <RectangleNode>(node.DrawOperations[0]);
        }
Esempio n. 14
0
        public BackgroundNode()
        {
            var count = GameUtils.AreaSize;

            var size = GameUtils.CellSize * 0.9f;

            foreach (var v in GameUtils.AllCells)
            {
                var node = new RectangleNode
                {
                    Position       = new Vector2F(v.X + 0.5f, v.Y + 0.5f) * GameUtils.CellSize,
                    CenterPosition = size * 0.5f,
                    RectangleSize  = size,
                    ZOrder         = ZOrders.Background,
                    Color          = new Color(20, 20, 20),
                };

                AddChildNode(node);
            }
        }
 private void GetIntersecting(RectangleNode <IHull> leafNode, RectangleNode <IHull> internalNode, List <IHull> intersecting)
 {
     Debug.Assert(leafNode.UserData != null);
     if (!leafNode.Rectangle.Intersects(internalNode.Rectangle))
     {
         return;
     }
     if (internalNode.UserData != null)
     {
         if (leafNode.UserData != internalNode.UserData)
         {
             intersecting.Add(internalNode.UserData);
         }
     }
     else
     {
         GetIntersecting(leafNode, internalNode.Left, intersecting);
         GetIntersecting(leafNode, internalNode.Right, intersecting);
     }
 }
        void Init()
        {
            foreach (EdgeGeometry e in metroGraphData.Edges)
            {
                polylineToEdgeGeom[(Polyline)e.Curve] = e;
            }

            var del = new Point(ApproximateComparer.DistanceEpsilon, ApproximateComparer.DistanceEpsilon);

            if (cdt != null)
            {
                siteHierarchy = RectangleNode <CdtSite> .CreateRectangleNodeOnEnumeration(
                    cdt.PointsToSites.Values.Select(site => new RectangleNode <CdtSite>(site, new Rectangle(site.Point + del, site.Point - del))));

                triangleHierarchy = RectangleNode <CdtTriangle> .CreateRectangleNodeOnEnumeration(
                    cdt.GetTriangles().Select(tr => new RectangleNode <CdtTriangle>(tr, TriangleRectangle(tr.Sites))));
            }

            CreatePathsThroughPoints();
        }
        internal MetroGraphData(EdgeGeometry[] regularEdges,
            RectangleNode<Polyline> looseTree, RectangleNode<Polyline> tightTree,
            BundlingSettings bundlingSettings, Cdt cdt,
            Dictionary<EdgeGeometry, Set<Polyline>> edgeLooseEnterable, Dictionary<EdgeGeometry, Set<Polyline>> edgeTightEnterable, Func<Port, Polyline> loosePolylineOfPort) {
            //Debug.Assert(cdt != null);
            this.regularEdges = regularEdges;
            if (cdt != null)
                Cdt = cdt;
            else
                Cdt = BundleRouter.CreateConstrainedDelaunayTriangulation(looseTree);

            EdgeLooseEnterable = edgeLooseEnterable;
            EdgeTightEnterable = edgeTightEnterable;
            LoosePolylineOfPort = loosePolylineOfPort;

            looseIntersections = new Intersections(this, bundlingSettings, looseTree, station => station.EnterableLoosePolylines);
            tightIntersections = new Intersections(this, bundlingSettings, tightTree, station => station.EnterableTightPolylines);
            cdtIntersections = new CdtIntersections(this, bundlingSettings);

            Initialize(false);
        }
        static int NumberOfHits(int numberOfChecks, Random random, RectangleNode <Node, Point> tree, int maxNumberOfHits)
        {
            // var l = new List<Point>();
            int numberOfHits = 0;

            for (int i = 0; i < numberOfChecks; i++)
            {
                Point point = RandomPointFromBox(random, (Rectangle)tree.rectangle);
                //   l.Add(point);
                if ((tree.FirstHitNode(point, (p, t) => HitTestBehavior.Stop)) != null)
                {
                    numberOfHits++;
                }
                if (numberOfHits == maxNumberOfHits)
                {
                    return(maxNumberOfHits);
                }
            }
            //LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(Getdc(tree, l));
            return(numberOfHits);
        }
        bool PushNodeAndUpdateRTree(Node pushingNode, RectangleNode<Node> pushed) {
            var del = pushed.UserData.Center - pushingNode.Center;
            var w = pushingNode.Width / 2 + pushed.UserData.Width / 2;
            var h = pushingNode.Height / 2 + pushed.UserData.Height / 2;
            var absDelXBetweenCenters = Math.Abs(del.X);
            var absDelYBetweenCenters = Math.Abs(del.Y);

            var xSep = absDelXBetweenCenters - w;
            var ySep = absDelYBetweenCenters - h;
            if (xSep >= separation || ySep >= separation)
                return false;
            if (absDelXBetweenCenters >= absDelYBetweenCenters) {
                double d = del.X > 0 ? separation - xSep : xSep - separation;
                PushByX(d, pushed);
            }
            else {
                double d = del.Y > 0 ? separation - ySep : ySep - separation;
                PushByY(d, pushed);
            }
            UpdateBoundingBoxesOfPushedAndUpParents(pushed);
            return true;
        }
Esempio n. 20
0
        RectangleNode <Node, Point> FindClusterNodeRecurse(RectangleNode <Node, Point> node, Node cluster, Rectangle previousBox)
        {
            if (node.UserData != null)
            {
                return(node.UserData == cluster ? node : null);
            }

            RectangleNode <Node, Point> n0 = null;

            if (previousBox.Intersects((Rectangle)node.Left.Rectangle))
            {
                n0 = FindClusterNodeRecurse(node.Left, cluster, previousBox);
            }
            if (n0 != null)
            {
                return(n0);
            }
            if (previousBox.Intersects((Rectangle)node.Right.Rectangle))
            {
                return(FindClusterNodeRecurse(node.Right, cluster, previousBox));
            }
            return(null);
        }
Esempio n. 21
0
        static void AddTilePoints(RectangleNode <Node> rtree, List <Point> list, double left, double bottom,
                                  double tileSize, Rectangle boundingBox)
        {
            const int n   = 2; //adding n*n points
            double    del = tileSize / (n + 1);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    var p = new Point(i * del + left, j * del + bottom);
                    if (!boundingBox.Contains(p))
                    {
                        continue;
                    }
                    if (rtree.FirstHitNode(p) != null)
                    {
                        continue;
                    }
                    list.Add(p);
                }
            }
        }
Esempio n. 22
0
        public void CreateScene()
        {
            _scene = new Scene();

            var clearNode = new RectangleNode()
            {
                Position = new Vector2(0, 0), Size = new Vector2(1000, 1000)
            };
            var fillNode = new SetColorNode {
                Color = Color.Green
            };

            for (var i = 0; i < 10; i++)
            {
                fillNode.Children.Add(
                    new RectangleNode {
                    Name = $"Rect{i}", Position = new Vector2(i * 50, 50), Size = new Vector2(40, 40)
                });
            }

            clearNode.Children.Add(fillNode);
            _scene.Root.Children.Add(clearNode);
        }
Esempio n. 23
0
        /// <summary>
        /// does the initialization
        /// </summary>
        public void Initialize()
        {
            if (_initFromPrecomputedLgData)
            {
                InitOnPrecomputedLgData();
                return;
            }

#if DEBUG && TEST_MSAGL
            mainGeometryGraph.SetDebugIds();
#endif

            CreateConnectedComponentsAndLayoutTheWholeGraph();
#if (!SILVERLIGHT && !SHARPKIT)
            Timer timer = new Timer();
            timer.Start();
#endif
            LevelCalculator.SetNodeZoomLevelsAndRouteEdgesOnLevels(lgData, mainGeometryGraph, lgLayoutSettings);
            TestZoomLevels();
            //    CalculateEdgeZoomLevels();
            //    Console.WriteLine("nodes {0} edges {1}", MainGeometryGraph.Nodes.Count(), MainGeometryGraph.Edges.Count());
            lgNodeHierarchy =
                RectangleNode <LgNodeInfo> .CreateRectangleNodeOnEnumeration(
                    lgData.GeometryNodesToLgNodeInfos.Values.Where(n => !(n.GeometryNode is Cluster)).Select(
                        lginfo => new RectangleNode <LgNodeInfo>(lginfo, lginfo.BoundingBox)));

            railGraph = new RailGraph();
#if (!SILVERLIGHT && !SHARPKIT)
            timer.Stop();
            Console.WriteLine("levels calculated for {0}", timer.Duration);

            if (lgLayoutSettings.ExitAfterInit)
            {
                Environment.Exit(0);
            }
#endif
        }
Esempio n. 24
0
        public void RectangleNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var rectangle1 = new RectangleNode()
            {
                Color          = new Color(255, 0, 0),
                Position       = new Vector2F(100f, 100f),
                CenterPosition = new Vector2F(25f, 25f),
                RectangleSize  = new Vector2F(50f, 50f),
            };
            var rectangle2 = new RectangleNode()
            {
                Color         = new Color(0, 255, 0),
                Position      = new Vector2F(400f, 200f),
                RectangleSize = new Vector2F(200f, 100f),
            };
            var rectangle3 = new RectangleNode()
            {
                Color         = new Color(0, 0, 255),
                Position      = new Vector2F(200f, 300f),
                RectangleSize = new Vector2F(100f, 150f),
            };

            Engine.AddNode(rectangle1);
            Engine.AddNode(rectangle2);
            Engine.AddNode(rectangle3);

            tc.LoopBody((c) =>
            {
                rectangle1.RectangleSize += new Vector2F(1, 1);
            }, null);

            tc.End();
        }
 private void GetClosePairs(RectangleNode<IHull> a, RectangleNode<IHull> b, List<Tuple<IHull, IHull>> closePairs) {
     if (!a.Rectangle.Intersects(b.Rectangle))
         return;
     if (a.UserData != null && b.UserData != null) {
         if (a.UserData != b.UserData) {
             Point ap = a.UserData.Center;
             Point bp = b.UserData.Center;
             if (ap.X <= bp.X || (ap.X == bp.X && ap.Y <= bp.Y)) {
                 closePairs.Add(new Tuple<IHull, IHull>(a.UserData, b.UserData));
             }
         }
     } else if (a.UserData == null && b.UserData == null) {
         GetClosePairs(a.Left, b.Left, closePairs);
         GetClosePairs(a.Left, b.Right, closePairs);
         GetClosePairs(a.Right, b.Left, closePairs);
         GetClosePairs(a.Right, b.Right, closePairs);
     } else if (a.UserData == null) {
         GetClosePairs(a.Left, b, closePairs);
         GetClosePairs(a.Right, b, closePairs);
     } else {
         GetClosePairs(a, b.Left, closePairs);
         GetClosePairs(a, b.Right, closePairs);
     }
 }
Esempio n. 26
0
        private SceneNodeBase GetRootElement()
        {
            var rectangle = RectangleNode.Create();

            rectangle.Scale        *= 3;
            rectangle.TextureSource = new TextureSource(@"Lenna.png");

            //var blend = RectangleNode.Create();
            //blend.Scale *= 1.5f;
            //blend.WorldPosition = new vec3(-0.5f, 0, 0.1f);
            //blend.RenderUnit.Methods[0].StateList.Add(new BlendState(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha));
            //blend.TextureSource = new TextureSource(@"particle.png");

            //var blend2 = RectangleNode.Create();
            //blend2.Scale *= 1.5f;
            //blend2.WorldPosition = new vec3(0.5f, 0, 0.2f);
            //blend2.RenderUnit.Methods[0].StateList.Add(new BlendState(BlendingSourceFactor.SourceAlpha, BlendingDestinationFactor.OneMinusSourceAlpha));
            //blend2.TextureSource = new TextureSource(@"particle.png");

            // note: this tells us that the right way is to render the nearest transparenct object at last.
            var group = new GroupNode(rectangle);//, blend, blend2);

            return(group);
        }
 private void GetClosePairs(RectangleNode <IHull> a, RectangleNode <IHull> b, List <Tuple <IHull, IHull> > closePairs)
 {
     if (!a.Rectangle.Intersects(b.Rectangle))
     {
         return;
     }
     if (a.UserData != null && b.UserData != null)
     {
         if (a.UserData != b.UserData)
         {
             Point ap = a.UserData.Center;
             Point bp = b.UserData.Center;
             if (ap.X <= bp.X || (ap.X == bp.X && ap.Y <= bp.Y))
             {
                 closePairs.Add(new Tuple <IHull, IHull>(a.UserData, b.UserData));
             }
         }
     }
     else if (a.UserData == null && b.UserData == null)
     {
         GetClosePairs(a.Left, b.Left, closePairs);
         GetClosePairs(a.Left, b.Right, closePairs);
         GetClosePairs(a.Right, b.Left, closePairs);
         GetClosePairs(a.Right, b.Right, closePairs);
     }
     else if (a.UserData == null)
     {
         GetClosePairs(a.Left, b, closePairs);
         GetClosePairs(a.Right, b, closePairs);
     }
     else
     {
         GetClosePairs(a, b.Left, closePairs);
         GetClosePairs(a, b.Right, closePairs);
     }
 }
        void UpdateBoundingBoxesOfPushedAndUpParents(RectangleNode<Node> pushed) {
            pushed.Rectangle = GetPaddedBoxOfNode(pushed.UserData);
            var parent = pushed.Parent;
            while (parent != null) {
                parent.Rectangle = new Rectangle(parent.Left.Rectangle, parent.Right.Rectangle);
                parent = parent.Parent;
            }

        }
Esempio n. 29
0
        static bool CurveIntersectsRectangleNode(ICurve curve, ref Rectangle curveBox, RectangleNode <Polyline> rectNode, Polyline polylineToIgnore)
        {
            if (!rectNode.Rectangle.Intersects(curveBox))
            {
                return(false);
            }

            if (rectNode.UserData != null)
            {
                return(rectNode.UserData != polylineToIgnore &&
                       (Curve.CurveCurveIntersectionOne(rectNode.UserData, curve, false) != null ||
                        Inside(rectNode.UserData, curve)));
            }

            Debug.Assert(rectNode.Left != null && rectNode.Right != null);

            return(CurveIntersectsRectangleNode(curve, ref curveBox, rectNode.Left, polylineToIgnore) ||
                   CurveIntersectsRectangleNode(curve, ref curveBox, rectNode.Right, polylineToIgnore));
        }
Esempio n. 30
0
        internal static bool CurveIntersectsRectangleNode(ICurve curve, RectangleNode <Polyline> rectNode)
        {
            Rectangle boundingBox = curve.BoundingBox;

            return(CurveIntersectsRectangleNode(curve, ref boundingBox, rectNode));
        }
 internal CdtGeneralPolylineTracer(IEnumerable<PolylinePoint> polylinePoints, RectangleNode<CdtSite> siteHierarchy, RectangleNode<CdtTriangle> triangleHierarchy) {
     iterator = polylinePoints.GetEnumerator();
     TriangleHierarchy = triangleHierarchy;
     SiteHierarchy = siteHierarchy;
 }
 internal ProximityQuery(List <IHull> nodeHulls)
 {
     hierarchy = RectangleNode <IHull> .CreateRectangleNodeOnEnumeration(GetNodeRects(nodeHulls));
 }
Esempio n. 33
0
 internal CdtGeneralPolylineTracer(IEnumerable <PolylinePoint> polylinePoints, RectangleNode <CdtSite> siteHierarchy, RectangleNode <CdtTriangle> triangleHierarchy)
 {
     iterator          = polylinePoints.GetEnumerator();
     TriangleHierarchy = triangleHierarchy;
     SiteHierarchy     = siteHierarchy;
 }
        static void IntersectionsOfLineAndRectangleNodeOverPolyline(LineSegment ls, RectangleNode<Polyline> rectNode,
                                                                    List<IntersectionInfo> listOfIntersections) {
            if (rectNode == null)
                return;
            if (!ls.BoundingBox.Intersects(rectNode.Rectangle))
                return;
            if (rectNode.UserData != null) {
                listOfIntersections.AddRange(Curve.GetAllIntersections(ls, rectNode.UserData, true));
                return;
            }

            IntersectionsOfLineAndRectangleNodeOverPolyline(ls, rectNode.Left, listOfIntersections);
            IntersectionsOfLineAndRectangleNodeOverPolyline(ls, rectNode.Right, listOfIntersections);
        }
Esempio n. 35
0
        internal static RectangleNode <Polyline> CalculateHierarchy(IEnumerable <Polyline> polylines)
        {
            var rectNodes = polylines.Select(polyline => CreateRectNodeOfPolyline(polyline)).ToList();

            return(RectangleNode <Polyline> .CreateRectangleNodeOnListOfNodes(rectNodes));
        }
 RectangleNode<Node> FindClusterNodeRecurse(RectangleNode<Node> node, Node cluster, Rectangle previousBox) {
     if (node.UserData != null)
         return node.UserData == cluster ? node : null;
     
     RectangleNode<Node> n0=null;
     if (previousBox.Intersects(node.Left.Rectangle))
         n0 = FindClusterNodeRecurse(node.Left, cluster, previousBox);
     if (n0 != null) return n0;
     if (previousBox.Intersects(node.Right.Rectangle))
         return FindClusterNodeRecurse(node.Right, cluster, previousBox);
     return null;
 }
        static internal Cdt CreateConstrainedDelaunayTriangulation(RectangleNode<Polyline> looseHierarchy) {
            IEnumerable<Polyline> obstacles = looseHierarchy.GetAllLeaves();

            Rectangle rectangle = looseHierarchy.Rectangle;
            double d = rectangle.Diagonal / 4;
            Point lb = rectangle.LeftBottom + new Point(-d, -d);
            Point lt = rectangle.LeftTop + new Point(-d, d);
            Point rt = rectangle.RightTop + new Point(d, d);
            Point rb = rectangle.RightBottom + new Point(d, -d);

            var additionalObstacles = new[] { 
                new Polyline(lb, lt, rt, rb) { Closed = true }};

            return GetConstrainedDelaunayTriangulation(obstacles.Concat(additionalObstacles));
        }
Esempio n. 38
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cluster"></param>
        /// <param name="previousBox"></param>
        public void UpdateRTreeByChangedNodeBox(Node cluster, Rectangle previousBox)
        {
            RectangleNode <Node, Point> rectNode = FindClusterNode(cluster, previousBox);

            UpdateBoundingBoxesOfPushedAndUpParents(rectNode);
        }
        static bool LineIntersectsRectangleNode(LineSegment ls, RectangleNode<Polyline> rectNode) {
            if (!ls.BoundingBox.Intersects(rectNode.Rectangle))
                return false;
            if (rectNode.UserData != null) {
                // SugiyamaLayoutSettings.Show(ls, rectNode.UserData);
                return Curve.GetAllIntersections(rectNode.UserData, ls, false).Count > 0;
            }


            return LineIntersectsRectangleNode(ls, rectNode.Left) || LineIntersectsRectangleNode(ls, rectNode.Right);
        }
Esempio n. 40
0
 internal static bool IntersectsSegment(RectangleNode<Obstacle> root, Point start, Point end) 
 {
     return root.GetLeafRectangleNodesIntersectingRectangle(new Rectangle(start, end)).Any();
 }
        internal RectangleNode<CdtTriangle> GetCdtTree() {
            if (cdtTree == null) {
                cdtTree = RectangleNode<CdtTriangle>.CreateRectangleNodeOnEnumeration(GetTriangles().Select(t => new RectangleNode<CdtTriangle>(t, t.BoundingBox())));
            }

            return cdtTree;
        }
 internal void CalculateHierarchy()
 {
     this.hierarchy = ObstacleTree.CalculateHierarchy(groupsAndClumps);
 }
Esempio n. 43
0
 internal void CalculateHierarchy()
 {
     this.hierarchy = ObstacleTree.CalculateHierarchy(groupsAndClumps);
 }
 bool PolylineIntersectsPolyRectangleNodeOfTightHierarchy(Point a, Point b, RectangleNode<Polyline> rect) {
     return PolylineIntersectsPolyRectangleNodeOfTightHierarchy(new LineSegment(a, b), rect);
 }
 void PushByX(double del, RectangleNode<Node> pushed) {
     var delPoint = new Point(del, 0);
     PushByPoint(pushed, delPoint);
 }
 bool PolylineIntersectsPolyRectangleNodeOfTightHierarchy(LineSegment ls, RectangleNode<Polyline> rect) {
     if (!ls.BoundingBox.Intersects(rect.Rectangle))
         return false;
     if (rect.UserData != null) {
         foreach (IntersectionInfo ii in Curve.GetAllIntersections(ls, rect.UserData, false)) {
             if (ii.Segment1 != SourceTightPolyline && ii.Segment1 != TargetTightPolyline)
                 return true;
             if (ii.Segment1 == SourceTightPolyline && SourcePort is CurvePort)
                 return true;
             if (ii.Segment1 == TargetTightPolyline && TargetPort is CurvePort)
                 return true;
         }
         return false;
     }
     return PolylineIntersectsPolyRectangleNodeOfTightHierarchy(ls, rect.Left) ||
            PolylineIntersectsPolyRectangleNodeOfTightHierarchy(ls, rect.Right);
 }
Esempio n. 47
0
        static void Main(string[] args)
        {
            // Altseed2 を初期化します。
            Engine.Initialize("ShapeNode", 640, 480);

            // 円を描画するノード
            var circle = new CircleNode()
            {
                Color    = new Color(255, 100, 100),
                Radius   = 30f,
                Position = new Vector2F(100f, 300f),
                VertNum  = 30
            };

            // 円弧を描画するノード
            var arc = new ArcNode()
            {
                Color       = new Color(100, 255, 100),
                Radius      = 25f,
                Position    = new Vector2F(300f, 100f),
                StartDegree = 30f,
                EndDegree   = 150f,
                VertNum     = 30
            };

            // 直線を描画するノード
            var line = new LineNode()
            {
                Color     = new Color(100, 100, 255),
                Point1    = new Vector2F(200f, 150f),
                Point2    = new Vector2F(400f, 350f),
                Thickness = 5f
            };

            // 短形を描画するノード
            var rectangle = new RectangleNode()
            {
                Color         = new Color(255, 255, 100),
                Position      = new Vector2F(300f, 400f),
                RectangleSize = new Vector2F(50f, 50f)
            };

            // 三角形を描画するノード
            var triangle = new TriangleNode()
            {
                Color  = new Color(255, 100, 255),
                Point1 = new Vector2F(50f, 50f),
                Point2 = new Vector2F(100f, 50f),
                Point3 = new Vector2F(50f, 100f),
            };

            // エンジンにノードを追加します。
            Engine.AddNode(circle);
            Engine.AddNode(arc);
            Engine.AddNode(line);
            Engine.AddNode(rectangle);
            Engine.AddNode(triangle);

            // メインループ。
            // Altseed のウインドウが閉じられると終了します。
            while (Engine.DoEvents())
            {
                // Altseed を更新します。
                Engine.Update();
            }

            // Altseed の終了処理をします。
            Engine.Terminate();
        }
 internal void SetParamsFeasiblySymmetrically(RectangleNode <Polyline> tightTree)
 {
     CalculateTightObstaclesForBundle(tightTree, obstaclesToIgnore);
     SetEndParamsSymmetrically();
 }
        internal static RectangleNode <Obstacle, Point> CalculateHierarchy(IEnumerable <Obstacle> obstacles)
        {
            var rectNodes = obstacles.Select(obs => new RectangleNode <Obstacle, Point>(obs, obs.VisibilityBoundingBox)).ToList();

            return(RectangleNode <Obstacle, Point> .CreateRectangleNodeOnListOfNodes(rectNodes));
        }
 StaircaseRemover(List<Path> paths, RectangleNode<Polyline> hierarchyOfObstacles) {
     HierarchyOfObstacles = new RTree<Polyline>(hierarchyOfObstacles);
     Paths = paths;
 }
Esempio n. 51
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="quadrilateral"></param>
        /// <param name="rectangleNode"></param>
        /// <param name="polylineToIgnore"></param>
        /// <returns></returns>
        public static bool CurveIntersectsRectangleNode(Polyline quadrilateral, RectangleNode <Polyline> rectangleNode, Polyline polylineToIgnore)
        {
            Rectangle boundingBox = quadrilateral.BoundingBox;

            return(CurveIntersectsRectangleNode(quadrilateral, ref boundingBox, rectangleNode, polylineToIgnore));
        }
 internal static void RemoveStaircases(List<Path> paths, RectangleNode<Polyline> hierarchyOfObstacles) {
     var r = new StaircaseRemover(paths, hierarchyOfObstacles);
     r.Calculate();
 }
Esempio n. 53
0
 bool ThereAreOverlaps(RectangleNode <Polyline> hierarchy)
 {
     return(RectangleNodeUtils.FindIntersectionWithProperty(hierarchy, hierarchy, Curve.CurvesIntersect));
 }
 bool ThereAreOverlaps(RectangleNode<Polyline> hierarchy) {
     return RectangleNodeUtils.FindIntersectionWithProperty(hierarchy, hierarchy, Curve.CurvesIntersect);
 }
 internal static bool IntersectsSegment(RectangleNode <Obstacle> root, Point start, Point end)
 {
     return(root.GetLeafRectangleNodesIntersectingRectangle(new Rectangle(start, end)).Any());
 }
 static void PushByPoint(RectangleNode<Node> pushed, Point delPoint) {
     pushed.UserData.Center += delPoint;
     var cluster = pushed.UserData as Cluster;
     if (cluster != null)
         cluster.DeepContentsTranslation(delPoint, true);
 }
        /// <summary>
        /// Computes the intersection between the hub and obstacles
        /// </summary>
        /// <param name="node"></param>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <param name="obstaclesToIgnore">these are the obstacles the are ignored by the method</param>
        /// <param name="touchedObstacles">list of pairs (obstacle, closest point on the obstacle)</param>
        /// <param name="minimalDistance">min distance from the center to an obstacle</param>
        /// <returns>false iff center is inside of an obstacle</returns>
        static bool IntersectCircleWithTree(RectangleNode<Polyline> node, Point center, double radius, Set<Polyline> obstaclesToIgnore,
            List<Tuple<Polyline, Point>> touchedObstacles, ref double minimalDistance) {
            if (!node.Rectangle.Contains(center, radius))
                return true;

            if (node.UserData == null) {
                bool res = IntersectCircleWithTree(node.Left, center, radius, obstaclesToIgnore, touchedObstacles, ref minimalDistance);
                if (!res) return false;
                res = IntersectCircleWithTree(node.Right, center, radius, obstaclesToIgnore, touchedObstacles, ref minimalDistance);
                if (!res) return false;
            }
            else {
                Polyline obstacle = node.UserData;
                if (obstaclesToIgnore.Contains(obstacle)) return true;

                PointLocation pl = Curve.PointRelativeToCurveLocation(center, obstacle);
                if (pl != PointLocation.Outside) return false;

                Point touchPoint = obstacle[obstacle.ClosestParameter(center)];
                double dist = (touchPoint - center).Length;
                if (dist <= radius)
                    touchedObstacles.Add(new Tuple<Polyline, Point>(obstacle, touchPoint));
                minimalDistance = Math.Min(dist, minimalDistance);
            }
            return true;
        }
 internal void SetParamsFeasiblySymmetrically(RectangleNode<Polyline> tightTree) {
     CalculateTightObstaclesForBundle(tightTree, obstaclesToIgnore);
     SetEndParamsSymmetrically();
 }
Esempio n. 59
0
        static bool CurveIntersectsRectangleNode(ICurve curve, ref Rectangle curveBox, RectangleNode <Polyline> rectNode)
        {
            if (!rectNode.Rectangle.Intersects(curveBox))
            {
                return(false);
            }

            if (rectNode.UserData != null)
            {
                var curveUnderTest = rectNode.UserData;
                return(Curve.CurveCurveIntersectionOne(curveUnderTest, curve, false) != null ||
                       Inside(curveUnderTest, curve));
            }
            Debug.Assert(rectNode.Left != null && rectNode.Right != null);

            return(CurveIntersectsRectangleNode(curve, ref curveBox, rectNode.Left) ||
                   CurveIntersectsRectangleNode(curve, ref curveBox, rectNode.Right));
        }
 internal static List<IntersectionInfo> IntersectionsOfLineAndRectangleNodeOverPolyline(LineSegment ls,
                                                                                        RectangleNode<Polyline>
                                                                                            rectNode) {
     var ret = new List<IntersectionInfo>();
     IntersectionsOfLineAndRectangleNodeOverPolyline(ls, rectNode, ret);
     return ret;
 }