public Node GetNodeForSite(Diagram.Site target)
 {
     if (site == target)
     {
         return(this);
     }
     if (site.poly == null || children == null || children.Count == 0)
     {
         return(null);
     }
     for (int i = 0; i < children.Count; i++)
     {
         if (children[i].site == target)
         {
             return(children[i]);
         }
         if (children[i].site.poly.Contains(target.position))
         {
             if (children[i].type == NodeType.Internal)
             {
                 Tree tree = children[i] as Tree;
                 return(tree.GetNodeForSite(target));
             }
             return(children[i]);
         }
     }
     return(null);
 }
Beispiel #2
0
        private static void FilterNeighbours(Diagram.Site home, HashSet <uint> neighbours, List <Diagram.Site> sites)
        {
            if (home == null)
            {
                Debug.LogError("FilterNeighbours home == null");
            }
            HashSet <KeyValuePair <uint, int> > hashSet = new HashSet <KeyValuePair <uint, int> >();

            HashSet <uint> .Enumerator niter = neighbours.GetEnumerator();
            while (niter.MoveNext())
            {
                Diagram.Site site = sites.Find((Diagram.Site s) => s.id == niter.Current);
                if (site != null)
                {
                    if (site.poly == null)
                    {
                        Debug.LogError("FilterNeighbours neighbour.poly == null");
                    }
                    int edgeIdx = -1;
                    Polygon.Commonality commonality = home.poly.SharesEdge(site.poly, ref edgeIdx);
                    if (commonality == Polygon.Commonality.Edge)
                    {
                        hashSet.Add(new KeyValuePair <uint, int>(niter.Current, edgeIdx));
                    }
                }
            }
            home.neighbours = hashSet;
        }
        public Node AddSite(Diagram.Site site, NodeType type)
        {
            Node node = null;

            node = ((type != NodeType.Internal) ? ((Node) new Leaf(site, this)) : ((Node) new Tree(site, this, myRandom.seed + ChildCount())));
            AddChild(node);
            return(node);
        }
Beispiel #4
0
 protected Node(Diagram.Site site, NodeType type, Tree parent)
 {
     tags        = new TagSet();
     this.site   = site;
     this.type   = type;
     this.parent = parent;
     log         = new LoggerSSF("VoronoiNode", 35);
 }
 public Tree(Diagram.Site site, List <Node> children, Tree parent, int seed = 0)
     : base(site, NodeType.Internal, parent)
 {
     if (children == null)
     {
         children = new List <Node>();
     }
     this.children = children;
     SetSeed(seed);
 }
 public Tree(Diagram.Site site, Tree parent, int seed = 0)
     : base(site, NodeType.Internal, parent)
 {
     children = new List <Node>();
     SetSeed(seed);
 }
 public Leaf(Diagram.Site site, Tree parent)
     : base(site, NodeType.Leaf, parent)
 {
 }