Exemplo n.º 1
0
    // find peer to peer interactions
    // top to bottom, a peer prefers entering the smallest peer that is larger than itself
    // look from smallest to largest spheres, so smallest spheres enter first
    bool HorizontalIntersections(Sphere S)
    {
        bool inter = false;

        // making list of struct tuples
        List <SizeTuple> list = new List <SizeTuple>();
        SizeTuple        temp;

        for (int i = 0; i < S.numChildren; i++)
        {
            temp     = new SizeTuple();
            temp.S   = S.children[i];
            temp.rad = temp.S.radius;
            list.Add(temp);
        }
        // sorting list https://stackoverflow.com/questions/4668525/sort-listtupleint-int-in-place
        list.Sort((x, y) => x.rad.CompareTo(y.rad)); // sort by size in ascending order

        int    index = 0;
        Sphere S1; Sphere S2; Sphere tempS;

        while (index < list.Count)   // dynamic list, loop will terminate by index or by size decreasing
        // ASSUMPTION, list.Count = S.numChildren
        {
            S1 = list[index].S;
            S2 = null;
            // check if current sphere is within any sphere of larger size, break at first sphere
            for (int i = index + 1; i < list.Count; i++)
            {
                tempS = list[i].S;
                if (WithinGlobal(S1.worldPosition, tempS))  // if (WithinLocal(S1.position, tempS)) {
                {
                    S2 = tempS;
                    break;
                }
            }
            if (S2 == null)
            {
                index++;             // move to next sphere
            }
            else
            {
                // inter occured
                inter = true; //occured

                // remove current from the list so list.Count--
                list.RemoveAt(index);
                SphereEnterSphere(S1, S2);
            }
        }

        // by this point, S's parameters have been fixed
        for (int i = 0; i < S.numChildren; i++)
        {
            inter = inter || HorizontalIntersections(S.children[i]);
        }

        return(inter);
    }
Exemplo n.º 2
0
    // find diagonal interactions
    // top to bottom, a peer prefers entering the smallest peer that is larger than itself
    // look from smallest to largest spheres, so smallest spheres enter first
    bool DiagonalIntersections(Sphere S)
    {
        bool inter = false;

        // bottom to top, examine children first
        for (int i = 0; i < S.numChildren; i++)
        {
            inter = inter || DiagonalIntersections(S.children[i]);
        }

        // PEERS (with possible updates in internal structure)
        List <Sphere> list = S.children;

        Sphere T = null;

        if (S.parent == null)
        {
            return(inter);                  // no need to check further
        }
        T = S.parent;

        // PARENT PEERS + CHILDREN
        List <Sphere> baseList = new List <Sphere>();

        for (int i = 0; i < T.numChildren; i++)
        {
            if (Equals(T.children[i], S))
            {
                continue;                           // no including the self!!!
            }
            baseList.AddRange(GetAncestry(T.children[i]));
        }

        // making list of struct tuples
        List <SizeTuple> list2 = new List <SizeTuple>();
        SizeTuple        temp;

        for (int i = 0; i < baseList.Count; i++)
        {
            temp     = new SizeTuple();
            temp.S   = baseList[i];
            temp.rad = temp.S.worldRadius; // real radius, for global comp
            list2.Add(temp);
        }
        // sorting list https://stackoverflow.com/questions/4668525/sort-listtupleint-int-in-place
        list2.Sort((x, y) => x.rad.CompareTo(y.rad)); // sort by size in ascending order


        Sphere S1; Sphere S2;

        for (int j = 0; j < list.Count; j++)
        {
            S1 = list[j];
            S2 = null;
            // check if current sphere is within any diagonal sphere of SMALLEST size, break at first sphere
            for (int k = 0; k < list2.Count; k++)
            {
                S2 = list2[k].S;
                // must have S1 be smaller and clearly within S2
                if (S1.worldRadius < S2.worldRadius && WithinGlobalError(S1.worldPosition, S2)) // world position!!!
                {
                    SphereEnterSphereP(S1, S2);
                    break;
                }
            }
        }

        return(inter);
    }