Ejemplo n.º 1
0
        private IPlantCell ClosestTransporterCell(PlantCellType type, IPlantCell current, IEnumerable <IPlantCell> cells)
        {
            float closestDistance = float.MaxValue;

            IPlantCell closestCell = null;

            foreach (var cell in cells)
            {
                if (cell.CellType != type)
                {
                    continue;
                }

                float distance = Vector3.Distance(cell.Geometry.TopCenter, current.Geometry.TopCenter);

                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    closestCell     = cell;
                }
            }

            if (closestCell == null)
            {
                logger.LogFatal("Could not find closest cell of type {CellType} for cell at {Cell}", type, current.Geometry.TopCenter);
            }

            return(closestCell);
        }