Table of Contents

Method GetConnectedRays

Namespace
Gamelogic.Grids2
Assembly
Gamelogic.Grids2.dll

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

grid IImplicitShape<TPoint>

Grid in which the calculations are made.

point TPoint

Point where the calculations start.

rayMaps IEnumerable<IForwardMap<TPoint, TPoint>>

A list if forward maps used to generate rays iteratively.

isNeighborsConnected Func<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

TPoint

The 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);