public RaycastResult Raycast(Coordinate start, Direction dir, int length) { return this.Raycast(start, start.Move(dir, length)); }
private bool adjacentToFilledCell(Coordinate coord) { return this[coord.Move(0, 0, 1)].ID != 0 || this[coord.Move(0, 1, 0)].ID != 0 || this[coord.Move(0, 1, 1)].ID != 0 || this[coord.Move(1, 0, 0)].ID != 0 || this[coord.Move(1, 0, 1)].ID != 0 || this[coord.Move(1, 1, 0)].ID != 0 || this[coord.Move(1, 1, 1)].ID != 0 || this[coord.Move(0, 0, -1)].ID != 0 || this[coord.Move(0, -1, 0)].ID != 0 || this[coord.Move(0, -1, -1)].ID != 0 || this[coord.Move(-1, 0, 0)].ID != 0 || this[coord.Move(-1, 0, 1)].ID != 0 || this[coord.Move(-1, -1, 0)].ID != 0 || this[coord.Move(-1, -1, -1)].ID != 0; }
public Coordinate? FindClosestFilledCell(Coordinate coord, int maxDistance = 20) { if (this[coord].ID != 0) return coord; Vector3 pos = this.GetRelativePosition(coord); Coordinate? closestCoord = null; for (int radius = 1; radius < maxDistance; radius++) { float closestDistance = float.MaxValue; // Left for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { Coordinate c = coord.Move(-radius, y, z); if (this[c].ID != 0) { float distance = (this.GetRelativePosition(c) - pos).LengthSquared(); if (distance < closestDistance) { closestDistance = distance; closestCoord = c; } } } } // Right for (int y = -radius; y <= radius; y++) { for (int z = -radius; z <= radius; z++) { Coordinate c = coord.Move(radius, y, z); if (this[c].ID != 0) { float distance = (this.GetRelativePosition(c) - pos).LengthSquared(); if (distance < closestDistance) { closestDistance = distance; closestCoord = c; } } } } // Bottom for (int x = -radius + 1; x < radius; x++) { for (int z = -radius + 1; z < radius; z++) { Coordinate c = coord.Move(x, -radius, z); if (this[c].ID != 0) { float distance = (this.GetRelativePosition(c) - pos).LengthSquared(); if (distance < closestDistance) { closestDistance = distance; closestCoord = c; } } } } // Top for (int x = -radius + 1; x < radius; x++) { for (int z = -radius + 1; z < radius; z++) { Coordinate c = coord.Move(x, radius, z); if (this[c].ID != 0) { float distance = (this.GetRelativePosition(c) - pos).LengthSquared(); if (distance < closestDistance) { closestDistance = distance; closestCoord = c; } } } } // Backward for (int x = -radius + 1; x < radius; x++) { for (int y = -radius; y <= radius; y++) { Coordinate c = coord.Move(x, y, -radius); if (this[c].ID != 0) { float distance = (this.GetRelativePosition(c) - pos).LengthSquared(); if (distance < closestDistance) { closestDistance = distance; closestCoord = c; } } } } // Forward for (int x = -radius + 1; x < radius; x++) { for (int y = -radius; y <= radius; y++) { Coordinate c = coord.Move(x, y, radius); if (this[c].ID != 0) { float distance = (this.GetRelativePosition(c) - pos).LengthSquared(); if (distance < closestDistance) { closestDistance = distance; closestCoord = c; } } } } if (closestCoord.HasValue) break; } return closestCoord; }