public IEnumerable <TagCompound> GetWithin(Cuboid area) { foreach (TagCompound e in _entities) { Position pos = Entity.GetPosition(e); if (area.Contains(pos.X, pos.Y, pos.Z)) { yield return(e); } } }
private static bool StraightPathBoundBoxIntersectsObstacles(Cuboid pathObstacle, Cuboid[] obstacles) { foreach (var obstacle in obstacles) { if (pathObstacle.Contains(obstacle.MinPoint)) { return(true); } } return(false); }
public IEnumerable <TagCompound> GetWithin(Cuboid area) { int fromX = area.MinX / 16; int fromZ = area.MinZ / 16; int toX = area.MaxX / 16; int toZ = area.MaxZ / 16; for (int z = fromZ; z < toZ; z++) { for (int x = fromX; x < toX; x++) { AnvilChunk c = (AnvilChunk)_chunk.GetChunk(new ChunkCoord(x, z)); foreach (TagCompound e in c.Entities) { Position pos = Entity.GetPosition(e); if (area.Contains(pos.X, pos.Y, pos.Z)) { yield return(e); } } } } }
public bool AddNode(Point3D point, T value) { if (!_bounds.Contains(point)) { return(false); } if (!_innerNode && _leafs.Count + 1 > _capacity) { DivideSelf(); } if (_innerNode) { var added = false; foreach (var child in _children) { if (child.AddNode(point, value)) { added = true; break; } } if (!added) { throw new InvalidOperationException($"Cannot add point {point} to tree in bound {_bounds}"); } } else { _leafs.Add(new OctoTreeLeaf <T>(point, value)); } return(true); }
private List <int> GetMarks(Vec center, int localityRadius) { var marks = new List <int>(); var mark = new Dictionary <Vec, int>(); var nextMark = 1; var cuboid = new Cuboid(toFill.R).Intersect(new Cuboid(center, localityRadius)); foreach (var p in cuboid.AllPoints()) { if (p == center || filled[p]) { continue; } if (!mark.ContainsKey(p)) { mark[p] = nextMark; var component = MoreEnumerable.TraverseDepthFirst(p, cur => cur.GetMNeighbours().Where(next => cuboid.Contains(next) && !filled[next] && !mark.ContainsKey(next))); foreach (var componentItem in component) { mark[componentItem] = nextMark; } nextMark++; } marks.Add(mark[p]); } return(marks); }
public static List <BotCommand> FindPathBetween( Point3D source, Point3D destination, Cuboid boundingBox, Cuboid[] obstacles = null) { obstacles = obstacles ?? new Cuboid[0]; var destinationVector = Vector3D.FromPoint(destination); var sourceVector = Vector3D.FromPoint(source); var priorityQueue = new IntervalHeap <Vector3D>( new PriorityQueueComparer(destinationVector)); var visited = new System.Collections.Generic.HashSet <Vector3D>(); var g_of_x = new Dictionary <Vector3D, int>(); var parent = new Dictionary <Vector3D, PathTempInfo>(); // var f_of_x = new Dictionary<Vector3D, int>(); priorityQueue.Add(sourceVector); g_of_x[sourceVector] = 0; parent[sourceVector] = new PathTempInfo(); // f_of_x[sourceVector] = DistanceCost(sourceVector, destinationVector); while (priorityQueue.Count != 0) { var nextPoint = priorityQueue.DeleteMin(); if (nextPoint.ToPoint() == destination) { // We have found the path! return(GeneratePathFrom(parent, sourceVector, destinationVector)); } visited.Add(nextPoint); // Console.WriteLine($"Enumerating paths from {nextPoint}"); foreach (var reachableStruct in EnumerateMoves(nextPoint)) { // Console.WriteLine($"Checking to {reachableStruct.First} with type {reachableStruct.MoveType}"); var reachable = reachableStruct.First + nextPoint; var reachablePoint = reachable.ToPoint(); var pathObstacle = Cuboid.FromPoints(nextPoint.ToPoint(), reachablePoint); if (!boundingBox.Contains(reachablePoint)) { continue; } if (PathBoundBoxIntersectsObstacles(pathObstacle, obstacles)) { continue; } var tentativeScore = g_of_x[nextPoint] + DistanceCost(nextPoint, reachable); if (visited.Contains(reachable) && tentativeScore >= g_of_x.GetValueOrDefault(reachable, 0)) { continue; } if (!visited.Contains(reachable) || tentativeScore < g_of_x.GetValueOrDefault(reachable, 0)) { parent[reachable] = new PathTempInfo { Parent = nextPoint, Move = reachableStruct }; g_of_x[reachable] = tentativeScore; //f_of_x[reachable] = tentativeScore + DistanceCost(reachable, destinationVector); if (!priorityQueue.Contains(reachable)) { priorityQueue.Add(reachable); } } } } return(null); }