GetNeighbors(
     Coordinate origin,
     int steps,
     string container_label = "all"
     )
 {
     return(GetContainer(container_label)
            .GetCoordinates(Cubes.GetNeighbors(origin.cube, steps)));
 }
 GetPointOnLne(
     Coordinate a,
     Coordinate b,
     int distance,
     string container_label = "all"
     )
 {
     return(GetContainer(container_label)
            .GetCoordinate(Cubes.GetPointOnLine(a.cube, b.cube, distance)));
 }
 BooleanExclude(
     List <Coordinate> a,
     List <Coordinate> b,
     string container_label = "all"
     )
 {
     return(GetContainer(container_label)
            .GetCoordinates(Cubes
                            .BooleanExclude(a.Select(x => x.cube).ToList(),
                                            b.Select(x => x.cube).ToList())));
 }
 GetDiagonalNeighbor(
     Coordinate origin,
     int direction,
     int distance,
     string container_label = "all"
     )
 {
     return(GetContainer(container_label)
            .GetCoordinate(Cubes
                           .GetDiagonalNeighbor(origin.cube, direction, distance)));
 }
        /// <summary>
        /// Creates Coordinate instances from a list of valid cube coordinates
        /// </summary>
        /// <param name="cubes">List of Vector3 cube coordinates</param>
        public void CreateCoordinates(List <Vector3> cubes)
        {
            Container         container   = GetContainer();
            List <Coordinate> coordinates = new List <Coordinate>();

            foreach (Vector3 cube in cubes)
            {
                if (container.GetCoordinate(cube) != null)
                {
                    continue;
                }
                Coordinate coordinate =
                    new Coordinate(cube,
                                   Cubes.ConvertCubeToWorldPosition(cube));
                coordinates.Add(coordinate);
            }

            container.AddCoordinates(coordinates);
        }
        GetPath(
            Coordinate origin,
            Coordinate target,
            string container_label = "all"
            )
        {
            if (origin == target)
            {
                new List <Coordinate>();
            }

            Container      container = GetContainer(container_label);
            List <Vector3> openSet   = new List <Vector3>();
            List <Vector3> closedSet = new List <Vector3>();

            openSet.Add(origin.cube);

            Dictionary <Vector3, Vector3> cameFrom =
                new Dictionary <Vector3, Vector3>();

            cameFrom.Add(origin.cube, Vector3.zero);

            Vector3    current            = Vector3.zero;
            Coordinate coordinate         = null;
            Coordinate currentCoordinate  = null;
            Coordinate neighborCoordinate = null;
            float      newCost            = 0.0f;

            while (openSet.Count > 0)
            {
                current           = openSet[0];
                currentCoordinate = container.GetCoordinate(current);

                for (int i = 1; i < openSet.Count; i++)
                {
                    coordinate = container.GetCoordinate(openSet[i]);
                    if (
                        coordinate.fCost < currentCoordinate.fCost ||
                        coordinate.fCost == currentCoordinate.fCost &&
                        coordinate.hCost < currentCoordinate.hCost
                        )
                    {
                        current           = openSet[i];
                        currentCoordinate = container.GetCoordinate(current);
                    }
                }

                openSet.Remove(current);
                closedSet.Add(current);

                if (current == target.cube)
                {
                    break;
                }

                List <Coordinate> neighbors =
                    GetNeighbors(container.GetCoordinate(current),
                                 1,
                                 container_label);

                foreach (Vector3
                         neighbor
                         in
                         neighbors.Select(x => x.cube).ToList()
                         )
                {
                    coordinate = container.GetCoordinate(neighbor);
                    if (coordinate == null || closedSet.Contains(neighbor))
                    {
                        continue;
                    }

                    newCost =
                        currentCoordinate.gCost +
                        Cubes.GetDistanceBetweenTwoCubes(current, neighbor);
                    neighborCoordinate = container.GetCoordinate(neighbor);

                    if (
                        newCost < neighborCoordinate.gCost ||
                        !openSet.Contains(neighbor)
                        )
                    {
                        neighborCoordinate.gCost = newCost;
                        neighborCoordinate.hCost =
                            Cubes.GetDistanceBetweenTwoCubes(current, neighbor);
                        cameFrom.Add(neighbor, current);

                        if (!openSet.Contains(neighbor))
                        {
                            openSet.Add(neighbor);
                        }
                    }
                }
            }

            List <Vector3> path = new List <Vector3>();

            current = target.cube;
            path.Add(target.cube);

            while (current != origin.cube)
            {
                cameFrom.TryGetValue(current, out current);
                path.Add(current);
            }

            path.Reverse();

            return(container.GetCoordinates(path));
        }
 GetRing(Coordinate origin, int distance, string container_label = "all")
 {
     return(GetContainer(container_label)
            .GetCoordinates(Cubes.GetRing(origin.cube, distance)));
 }
 GetLine(Coordinate a, Coordinate b, string container_label = "all")
 {
     return(GetContainer(container_label)
            .GetCoordinates(Cubes.GetLine(a.cube, b.cube)));
 }
        /// <summary>
        /// Gets a Coordinate matching the closest rounded cube coordinate to the world transform position (Coordinate may not exist at rounded cube coordinate)
        /// </summary>
        /// <param name="position">Vector3 transform position in world space</param>
        /// <returns>Coordinate instance if found</returns>
        public Coordinate GetCoordinateFromWorldPosition(Vector3 position)
        {
            Vector3 cube = Cubes.ConvertWorldPositionToCube(position);

            return(GetCoordinate(cube));
        }