Exemplo n.º 1
0
 List<List<NeighborInfo>> PrepareNeighbors()
 {
     Random random = new Random(0);
     List<List<NeighborInfo>> allSplits = new List<List<NeighborInfo>>();
     for (int i = 0; i < NeighborListSplit; ++i)
     {
         List<NeighborInfo> neighbors = new List<NeighborInfo>();
         for (int j = 0; j < NeighborsChecked; ++j)
         {
             NeighborInfo neighbor = new NeighborInfo();
             do
             {
                 float angle = Angle.FromFraction((float)random.NextDouble() * 0.5f);
                 float distance = Calc.InterpolateExponential(MinHalfDistance, MaxHalfDistance, (float)random.NextDouble());
                 neighbor.Position = Calc.Round(Calc.Multiply(distance, Angle.ToVector(angle)));
             } while (neighbor.Position == new Point() || neighbor.Position.Y < 0);
             neighbor.Orientation = Angle.ToVector(Angle.Add(Angle.ToOrientation(Angle.Atan(neighbor.Position)), Angle.PI));
             if (!neighbors.Any(info => info.Position == neighbor.Position))
                 neighbors.Add(neighbor);
         }
         neighbors.Sort((left, right) => Calc.CompareYX(left.Position, right.Position));
         allSplits.Add(neighbors);
     }
     return allSplits;
 }
Exemplo n.º 2
0
        List <List <NeighborInfo> > PrepareNeighbors()
        {
            Random random = new Random(0);
            List <List <NeighborInfo> > allSplits = new List <List <NeighborInfo> >();

            for (int i = 0; i < NeighborListSplit; ++i)
            {
                List <NeighborInfo> neighbors = new List <NeighborInfo>();
                for (int j = 0; j < NeighborsChecked; ++j)
                {
                    NeighborInfo neighbor = new NeighborInfo();
                    do
                    {
                        float angle    = Angle.FromFraction((float)random.NextDouble() * 0.5f);
                        float distance = Calc.InterpolateExponential(MinHalfDistance, MaxHalfDistance, (float)random.NextDouble());
                        neighbor.Position = Calc.Round(Calc.Multiply(distance, Angle.ToVector(angle)));
                    } while (neighbor.Position == new Point() || neighbor.Position.Y < 0);
                    neighbor.Orientation = Angle.ToVector(Angle.Add(Angle.ToOrientation(Angle.Atan(neighbor.Position)), Angle.PI));
                    if (!neighbors.Any(info => info.Position == neighbor.Position))
                    {
                        neighbors.Add(neighbor);
                    }
                }
                neighbors.Sort((left, right) => Calc.CompareYX(left.Position, right.Position));
                allSplits.Add(neighbors);
            }
            return(allSplits);
        }
 public void updateLine()
 {
     //lineParent.childCount;
     List<zzPair<Vector3>> lLines = new List<zzPair<Vector3>>();
     var lNeighborInfo = new NeighborInfo();
     foreach (Transform lPoint in pointParent)
     {
         var lWayPoint = lPoint.GetComponent<zzWayPoint>();
         if (!lWayPoint)
             continue;
         var lWayPointPos = lWayPoint.lineCenter;
         var lNeighbors = lWayPoint.getNeighbor(neighborRange, maxHeigth
                 , pointMask, preventMask);
         foreach (var lNeighbor in lNeighbors)
         {
             if (!lNeighborInfo.isNeighbor(lWayPoint, lNeighbor))
             {
                 lLines.Add(new zzPair<Vector3>(lWayPointPos, lNeighbor.lineCenter));
                 lNeighborInfo.addNeighbor(lWayPoint, lNeighbor);
                 //NeighborInfo
             }
         }
     }
     updateLine(lLines);
 }
Exemplo n.º 4
0
    void NeighborFunc(Vector2 Star_pos, int _tri, int _to)  //////////////////////////////////////////////////////////////////
    {
        int id = touchPos_v2.FindIndex(x => x == Star_pos); //檢查是否屬於此碎片的一部分

        if (id != -1)                                       //此碎片有此點
        {
            return;                                         //跳過
        }
        NeighborInfo temp = new NeighborInfo(neighbors.Count, Star_pos, _tri, _to);

        neighbors.Add(temp);
    }
Exemplo n.º 5
0
        public bool EvaluateNeighbors(int x, int y, int ndirs, NeighborCallback cb)
        {
            // Note: this is an optimization to avoid too much memory allocations.
            // However, it introduces a limit:
            // - Don't call this function in a multithread environnment
            // - Don't call this function inside itself (in the callback)
            NeighborInfo n = __ninfo;

            for (n.dir = 0; n.dir < ndirs; ++n.dir)
            {
                n.x = x + Dir.vec2i[n.dir].X;
                n.y = y + Dir.vec2i[n.dir].Y;
                if (Contains(n.x, n.y))
                {
                    n.value = this[n.x, n.y];
                    if (cb(n))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        private NeighborInfo GetPriorityNeighborInfo(RaycastHit2D[] hits)
        {
            NeighborInfo neighborInfo = new NeighborInfo();

            foreach (RaycastHit2D hit in hits)
            {
                if (hit.collider != null)
                {
                    NeighborInfo neighborInfoTemp = new NeighborInfo();
                    neighborInfoTemp.neighborType = GetNeighborTypeFromCollider(hit.collider);
                    neighborInfoTemp.gameObject   = hit.collider.gameObject;

                    if (neighborInfo.gameObject == null)
                    {
                        neighborInfo = neighborInfoTemp;
                    }
                    else if (neighborInfoTemp.neighborType == NeighborType.Destructable)
                    {
                        neighborInfo = neighborInfoTemp;
                    }
                }
            }
            return(neighborInfo);
        }
Exemplo n.º 7
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>	No location. </summary>
 ///
 /// <remarks>	Only makes sense if !NeighborInfo.allowNegatives.  Darrell Plank, 1/22/2021. </remarks>
 ///
 /// <returns>	A GridLocation. </returns>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public static GridLocation NoLoc()
 {
     using var info = new NeighborInfo(allowNegative: true);
     return(new GridLocation(-1, -1));
 }
Exemplo n.º 8
0
 static GridLocation()
 {
     // Put an undisposed default NeighborInfo on the stack
     var ignore = new NeighborInfo();
 }