public void IsDescendantOf_ManyParents()
        {
            Cluster grandMother = new Cluster();
            Cluster grandFather = new Cluster();
            Cluster parent = new Cluster();
            Cluster uncle = new Cluster();
            grandMother.AddChild(parent);
            grandMother.AddChild(uncle);
            grandFather.AddChild(parent);
            grandFather.AddChild(uncle);

            Node child = new Node();
            parent.AddChild(child);

            Assert.IsTrue(child.IsDescendantOf(parent), "The child node should be considered a descendant of its parent.");
            Assert.IsTrue(child.IsDescendantOf(grandMother), "The child node should be considered a descendant of its grandmother.");
            Assert.IsTrue(child.IsDescendantOf(grandFather), "The child node should be considered a descendant of its grandfather.");
            Assert.IsFalse(child.IsDescendantOf(uncle), "The child node should not be considered a descendant of its uncle.");
        }
        public void IsDescendantOf_BasicTest()
        {
            Cluster cluster = new Cluster();
            Node node = new Node();
            Node node2 = new Node();
            cluster.AddChild(node);

            Assert.IsTrue(node.IsDescendantOf(cluster), "Node is a descendant of cluster but IsDescendantOf returns false.");
            Assert.IsFalse(node2.IsDescendantOf(cluster), "Node2 is not a descendant of cluster but IsDescendantOf returns true.");
            Assert.IsFalse(cluster.IsDescendantOf(cluster), "A cluster should not be considered a descendant of itself.");
        }
        /// <summary>
        ///     Determines the index of the first obstacle map that the rectangle intersects.
        ///     Clusters that are parents/grandparents of the label's source/target nodes are not considered intersection.
        /// </summary>
        /// <returns>The index of the first obstacle map that the rectangle intersects. int.MaxValue if there is no intersection.</returns>
        int ConflictIndex(Rectangle queryRect, Label label)
        {
            var  edge   = (Edge)label.GeometryParent;
            Node source = edge.Source;
            Node target = edge.Target;

            for (int i = 0; i < obstacleMaps.Length; i++)
            {
                if (obstacleMaps[i] == null)
                {
                    continue;
                }

                foreach (IObstacle obstacle in obstacleMaps[i].GetAllIntersecting(queryRect))
                {
                    // If we're overlapping a node...
#if SHARPKIT //https://code.google.com/p/sharpkit/issues/detail?id=371
                    if (i == 1)
                    {
#else
                    if ((LabelPlacementResult)i == LabelPlacementResult.OverlapsNodes)
                    {
#endif
                        // ...and the node is a cluster...
                        var rectangleObstacle = obstacle as RectangleObstacle;
                        if (rectangleObstacle != null)
                        {
                            var cluster = rectangleObstacle.Data as Cluster;

                            // ...and the cluster is a grandparent of the source or target...
                            if (cluster != null && (source.IsDescendantOf(cluster) || target.IsDescendantOf(cluster)))
                            {
                                // ...don't consider the overlap to be a conflict.
                                continue;
                            }
                        }
                    }

                    return(i);
                }
            }

            return(int.MaxValue);
        }