Method GetConnectedRays
GetConnectedRays<TPoint>(IImplicitShape<TPoint>, TPoint, IEnumerable<IForwardMap<TPoint, TPoint>>, Func<TPoint, TPoint, bool>)
Returns a list containing lines connected to the given points. A line is a list of points. Only returns correct results for square or hex grids.
public static IEnumerable<IEnumerable<TPoint>> GetConnectedRays<TPoint>(IImplicitShape<TPoint> grid, TPoint point, IEnumerable<IForwardMap<TPoint, TPoint>> rayMaps, Func<TPoint, TPoint, bool> isNeighborsConnected)
Parameters
gridIImplicitShape<TPoint>Grid in which the calculations are made.
pointTPointPoint where the calculations start.
rayMapsIEnumerable<IForwardMap<TPoint, TPoint>>A list if forward maps used to generate rays iteratively.
isNeighborsConnectedFunc<TPoint, TPoint, bool>A functions that returns true or false, depending on whether two points can be considered connected when they are neighbors.For example, if you want rays of points that refer to cells of the same color, you can pass in a functions that compares the DefaultColors of cells.
Returns
- IEnumerable<IEnumerable<TPoint>>
Type Parameters
TPointThe type of point of the grid that this algorithm takes.
Examples
private bool IsSameColour(point1, point2)
{
return grid[point1].Color == grid[point2].Color;
}
private SomeMethod()
{
...
var rays = GetConnectedRays<ColourCell, PointyHexPoint, PointyHexNeighborIndex>(
grid, //a rect grid
point,
GridPoint2.GetForwardVectorRays(RectPoint.OrthogonalDirections),
IsSameColour);
...
}
You can of course also use a lambda expression, like this:
//The following code returns all lines that radiate from the given point
GetConnectedRays<ColourCell, PointyHexPoint, PointyHexNeighborIndex>(
grid,
point,
GridPoint2.GetForwardVectorRays(RectPoint.OrthogonalDirections),
(x, y) => grid[x].Color == grid[y].Color);